msw 2.4.12 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,8 +8,8 @@
8
8
  * - Please do NOT serve this file on production.
9
9
  */
10
10
 
11
- const PACKAGE_VERSION = '2.4.12'
12
- const INTEGRITY_CHECKSUM = '26357c79639bfa20d64c0efca2a87423'
11
+ const PACKAGE_VERSION = '2.5.0'
12
+ const INTEGRITY_CHECKSUM = '07a8241b182f8a246a7cd39894799a9e'
13
13
  const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
14
14
  const activeClientIds = new Set()
15
15
 
@@ -62,7 +62,12 @@ self.addEventListener('message', async function (event) {
62
62
 
63
63
  sendToClient(client, {
64
64
  type: 'MOCKING_ENABLED',
65
- payload: true,
65
+ payload: {
66
+ client: {
67
+ id: client.id,
68
+ frameType: client.frameType,
69
+ },
70
+ },
66
71
  })
67
72
  break
68
73
  }
@@ -155,6 +160,10 @@ async function handleRequest(event, requestId) {
155
160
  async function resolveMainClient(event) {
156
161
  const client = await self.clients.get(event.clientId)
157
162
 
163
+ if (activeClientIds.has(event.clientId)) {
164
+ return client
165
+ }
166
+
158
167
  if (client?.frameType === 'top-level') {
159
168
  return client
160
169
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "msw",
3
- "version": "2.4.12",
3
+ "version": "2.5.0",
4
4
  "description": "Seamless REST/GraphQL API mocking library for browser and Node.js.",
5
5
  "main": "./lib/core/index.js",
6
6
  "module": "./lib/core/index.mjs",
@@ -116,7 +116,7 @@
116
116
  "@bundled-es-modules/cookie": "^2.0.0",
117
117
  "@bundled-es-modules/statuses": "^1.0.1",
118
118
  "@bundled-es-modules/tough-cookie": "^0.1.6",
119
- "@inquirer/confirm": "^3.0.0",
119
+ "@inquirer/confirm": "^4.0.0",
120
120
  "@mswjs/interceptors": "^0.36.5",
121
121
  "@open-draft/until": "^2.1.0",
122
122
  "@types/cookie": "^0.6.0",
@@ -53,7 +53,12 @@ export type ServiceWorkerIncomingResponse = Pick<
53
53
  * Map of the events that can be received from the Service Worker.
54
54
  */
55
55
  export interface ServiceWorkerIncomingEventsMap {
56
- MOCKING_ENABLED: boolean
56
+ MOCKING_ENABLED: {
57
+ client: {
58
+ id: string
59
+ frameType: string
60
+ }
61
+ }
57
62
  INTEGRITY_CHECK_RESPONSE: {
58
63
  packageVersion: string
59
64
  checksum: string
@@ -10,7 +10,7 @@ export async function enableMocking(
10
10
  options: StartOptions,
11
11
  ) {
12
12
  context.workerChannel.send('MOCK_ACTIVATE')
13
- await context.events.once('MOCKING_ENABLED')
13
+ const { payload } = await context.events.once('MOCKING_ENABLED')
14
14
 
15
15
  // Warn the developer on multiple "worker.start()" calls.
16
16
  // While this will not affect the worker in any way,
@@ -28,5 +28,6 @@ export async function enableMocking(
28
28
  quiet: options.quiet,
29
29
  workerScope: context.registration?.scope,
30
30
  workerUrl: context.worker?.scriptURL,
31
+ client: payload.client,
31
32
  })
32
33
  }
@@ -1,3 +1,4 @@
1
+ import type { ServiceWorkerIncomingEventsMap } from 'browser/setupWorker/glossary'
1
2
  import { devUtils } from '~/core/utils/internal/devUtils'
2
3
 
3
4
  export interface PrintStartMessageArgs {
@@ -5,6 +6,7 @@ export interface PrintStartMessageArgs {
5
6
  message?: string
6
7
  workerUrl?: string
7
8
  workerScope?: string
9
+ client?: ServiceWorkerIncomingEventsMap['MOCKING_ENABLED']['client']
8
10
  }
9
11
 
10
12
  /**
@@ -41,6 +43,11 @@ export function printStartMessage(args: PrintStartMessageArgs = {}) {
41
43
  console.log('Worker scope:', args.workerScope)
42
44
  }
43
45
 
46
+ if (args.client) {
47
+ // eslint-disable-next-line no-console
48
+ console.log('Client ID: %s (%s)', args.client.id, args.client.frameType)
49
+ }
50
+
44
51
  // eslint-disable-next-line no-console
45
52
  console.groupEnd()
46
53
  }
@@ -62,7 +62,12 @@ self.addEventListener('message', async function (event) {
62
62
 
63
63
  sendToClient(client, {
64
64
  type: 'MOCKING_ENABLED',
65
- payload: true,
65
+ payload: {
66
+ client: {
67
+ id: client.id,
68
+ frameType: client.frameType,
69
+ },
70
+ },
66
71
  })
67
72
  break
68
73
  }
@@ -155,6 +160,10 @@ async function handleRequest(event, requestId) {
155
160
  async function resolveMainClient(event) {
156
161
  const client = await self.clients.get(event.clientId)
157
162
 
163
+ if (activeClientIds.has(event.clientId)) {
164
+ return client
165
+ }
166
+
158
167
  if (client?.frameType === 'top-level') {
159
168
  return client
160
169
  }