msw 2.14.2 → 2.14.3
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.
- package/lib/browser/index.js +88 -38
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +88 -38
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/experimental/sources/interceptor-source.js +14 -10
- package/lib/core/experimental/sources/interceptor-source.js.map +1 -1
- package/lib/core/experimental/sources/interceptor-source.mjs +14 -10
- package/lib/core/experimental/sources/interceptor-source.mjs.map +1 -1
- package/lib/iife/index.js +102 -48
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/package.json +5 -4
- package/src/browser/sources/service-worker-source.ts +17 -12
- package/src/core/experimental/sources/interceptor-source.ts +20 -10
package/lib/mockServiceWorker.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* - Please do NOT modify this file.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
const PACKAGE_VERSION = '2.14.
|
|
10
|
+
const PACKAGE_VERSION = '2.14.3'
|
|
11
11
|
const INTEGRITY_CHECKSUM = '4db4a41e972cec1b64cc569c66952d82'
|
|
12
12
|
const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
|
|
13
13
|
const activeClientIds = new Set()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "msw",
|
|
3
|
-
"version": "2.14.
|
|
3
|
+
"version": "2.14.3",
|
|
4
4
|
"description": "Seamless REST/GraphQL API mocking library for browser and Node.js.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./lib/core/index.js",
|
|
@@ -233,7 +233,7 @@
|
|
|
233
233
|
"outvariant": "^1.4.3",
|
|
234
234
|
"path-to-regexp": "^6.3.0",
|
|
235
235
|
"picocolors": "^1.1.1",
|
|
236
|
-
"rettime": "^0.11.
|
|
236
|
+
"rettime": "^0.11.11",
|
|
237
237
|
"statuses": "^2.0.2",
|
|
238
238
|
"strict-event-emitter": "^0.5.1",
|
|
239
239
|
"tough-cookie": "^6.0.1",
|
|
@@ -286,7 +286,7 @@
|
|
|
286
286
|
"vitest-environment-miniflare": "^2.14.4",
|
|
287
287
|
"webpack": "^5.106.2",
|
|
288
288
|
"webpack-http-server": "^0.5.0",
|
|
289
|
-
"msw": "^2.14.
|
|
289
|
+
"msw": "^2.14.3"
|
|
290
290
|
},
|
|
291
291
|
"peerDependencies": {
|
|
292
292
|
"typescript": ">= 4.8.x"
|
|
@@ -313,7 +313,7 @@
|
|
|
313
313
|
"build": "pnpm clean && cross-env NODE_ENV=production tsup && pnpm patch:dts",
|
|
314
314
|
"patch:dts": "node \"./config/scripts/patch-ts.js\"",
|
|
315
315
|
"publint": "publint",
|
|
316
|
-
"test": "pnpm test:unit && pnpm test:node && pnpm test:browser && pnpm test:native",
|
|
316
|
+
"test": "pnpm test:unit && pnpm test:node && pnpm test:browser && pnpm test:native && pnpm test:memory",
|
|
317
317
|
"test:unit": "vitest",
|
|
318
318
|
"test:node": "vitest --config=./test/node/vitest.config.ts",
|
|
319
319
|
"test:native": "vitest --config=./test/native/vitest.config.ts",
|
|
@@ -322,6 +322,7 @@
|
|
|
322
322
|
"test:modules:browser": "playwright test -c ./test/modules/browser/playwright.config.ts",
|
|
323
323
|
"test:e2e": "vitest run --config=./test/e2e/vitest.config.ts",
|
|
324
324
|
"test:ts": "vitest --config=./test/typings/vitest.config.ts",
|
|
325
|
+
"test:memory": "vitest --config=./test/memory/vitest.config.ts",
|
|
325
326
|
"release": "release publish",
|
|
326
327
|
"postinstall": "node -e \"import('./config/scripts/postinstall.js').catch(() => void 0)\"",
|
|
327
328
|
"knip": "knip"
|
|
@@ -330,6 +330,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
330
330
|
|
|
331
331
|
async #handleResponse(event: WorkerChannelResponseEvent): Promise<void> {
|
|
332
332
|
const { request, response, isMockedResponse } = event.data
|
|
333
|
+
const frame = this.#frames.get(request.id)
|
|
333
334
|
|
|
334
335
|
/**
|
|
335
336
|
* CORS requests with `mode: "no-cors"` result in "opaque" responses.
|
|
@@ -340,10 +341,10 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
340
341
|
*/
|
|
341
342
|
if (response.type?.includes('opaque')) {
|
|
342
343
|
this.#frames.delete(request.id)
|
|
344
|
+
frame?.events.removeAllListeners()
|
|
343
345
|
return
|
|
344
346
|
}
|
|
345
347
|
|
|
346
|
-
const frame = this.#frames.get(request.id)
|
|
347
348
|
this.#frames.delete(request.id)
|
|
348
349
|
|
|
349
350
|
/**
|
|
@@ -379,17 +380,21 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
379
380
|
},
|
|
380
381
|
)
|
|
381
382
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
383
|
+
try {
|
|
384
|
+
frame.events.emit(
|
|
385
|
+
new ResponseEvent(
|
|
386
|
+
isMockedResponse ? 'response:mocked' : 'response:bypass',
|
|
387
|
+
{
|
|
388
|
+
requestId: frame.data.id,
|
|
389
|
+
request: fetchRequest,
|
|
390
|
+
response: fetchResponse,
|
|
391
|
+
isMockedResponse,
|
|
392
|
+
},
|
|
393
|
+
),
|
|
394
|
+
)
|
|
395
|
+
} finally {
|
|
396
|
+
frame.events.removeAllListeners()
|
|
397
|
+
}
|
|
393
398
|
}
|
|
394
399
|
|
|
395
400
|
#defaultFindWorker: FindWorker = (workerUrl, mockServiceWorkerUrl) => {
|
|
@@ -87,16 +87,26 @@ export class InterceptorSource extends NetworkSource {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
queueMicrotask(() => {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
90
|
+
try {
|
|
91
|
+
httpFrame.events.emit(
|
|
92
|
+
new ResponseEvent(
|
|
93
|
+
isMockedResponse ? 'response:mocked' : 'response:bypass',
|
|
94
|
+
{
|
|
95
|
+
requestId,
|
|
96
|
+
request,
|
|
97
|
+
response,
|
|
98
|
+
},
|
|
99
|
+
),
|
|
100
|
+
)
|
|
101
|
+
} finally {
|
|
102
|
+
/**
|
|
103
|
+
* @note Remove any listeners from this frame.
|
|
104
|
+
* Past this point, it won't emit anything. The removal is crucial
|
|
105
|
+
* to prevent "rettime" from keeping the abort cleanup listeners internally.
|
|
106
|
+
* @see https://github.com/mswjs/msw/issues/2735
|
|
107
|
+
*/
|
|
108
|
+
httpFrame.events.removeAllListeners()
|
|
109
|
+
}
|
|
100
110
|
})
|
|
101
111
|
}
|
|
102
112
|
|