msw 2.13.3 → 2.13.5
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/cli/init.js +1 -1
- package/lib/browser/index.js +200 -56
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +200 -56
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/{HttpResponse-DlRR1D-f.d.mts → HttpResponse-BMMzfpjG.d.mts} +13 -0
- package/lib/core/{HttpResponse-CksOMVAa.d.ts → HttpResponse-DPDqE4Pb.d.ts} +13 -0
- package/lib/core/HttpResponse.d.mts +1 -1
- package/lib/core/HttpResponse.d.ts +1 -1
- package/lib/core/experimental/compat.d.mts +2 -2
- package/lib/core/experimental/compat.d.ts +2 -2
- package/lib/core/experimental/compat.js +1 -0
- package/lib/core/experimental/compat.js.map +1 -1
- package/lib/core/experimental/compat.mjs +1 -0
- package/lib/core/experimental/compat.mjs.map +1 -1
- package/lib/core/experimental/define-network.d.mts +2 -2
- package/lib/core/experimental/define-network.d.ts +2 -2
- package/lib/core/experimental/define-network.js +5 -5
- package/lib/core/experimental/define-network.js.map +1 -1
- package/lib/core/experimental/define-network.mjs +7 -5
- package/lib/core/experimental/define-network.mjs.map +1 -1
- package/lib/core/experimental/frames/http-frame.d.mts +2 -2
- package/lib/core/experimental/frames/http-frame.d.ts +2 -2
- package/lib/core/experimental/frames/http-frame.js +2 -0
- package/lib/core/experimental/frames/http-frame.js.map +1 -1
- package/lib/core/experimental/frames/http-frame.mjs +5 -1
- package/lib/core/experimental/frames/http-frame.mjs.map +1 -1
- package/lib/core/experimental/frames/network-frame.d.mts +2 -2
- package/lib/core/experimental/frames/network-frame.d.ts +2 -2
- package/lib/core/experimental/frames/websocket-frame.d.mts +2 -2
- package/lib/core/experimental/frames/websocket-frame.d.ts +2 -2
- package/lib/core/experimental/frames/websocket-frame.js +2 -0
- package/lib/core/experimental/frames/websocket-frame.js.map +1 -1
- package/lib/core/experimental/frames/websocket-frame.mjs +2 -0
- package/lib/core/experimental/frames/websocket-frame.mjs.map +1 -1
- package/lib/core/experimental/handlers-controller.d.mts +2 -1
- package/lib/core/experimental/handlers-controller.d.ts +2 -1
- package/lib/core/experimental/handlers-controller.js +15 -1
- package/lib/core/experimental/handlers-controller.js.map +1 -1
- package/lib/core/experimental/handlers-controller.mjs +15 -1
- package/lib/core/experimental/handlers-controller.mjs.map +1 -1
- package/lib/core/experimental/index.d.mts +2 -2
- package/lib/core/experimental/index.d.ts +2 -2
- package/lib/core/experimental/index.js +0 -1
- package/lib/core/experimental/index.js.map +1 -1
- package/lib/core/experimental/index.mjs +1 -2
- package/lib/core/experimental/index.mjs.map +1 -1
- package/lib/core/experimental/on-unhandled-frame.d.mts +2 -2
- package/lib/core/experimental/on-unhandled-frame.d.ts +2 -2
- package/lib/core/experimental/on-unhandled-frame.js +1 -0
- package/lib/core/experimental/on-unhandled-frame.js.map +1 -1
- package/lib/core/experimental/on-unhandled-frame.mjs +1 -0
- package/lib/core/experimental/on-unhandled-frame.mjs.map +1 -1
- package/lib/core/experimental/setup-api.d.mts +1 -1
- package/lib/core/experimental/setup-api.d.ts +1 -1
- package/lib/core/experimental/setup-api.js +2 -5
- package/lib/core/experimental/setup-api.js.map +1 -1
- package/lib/core/experimental/setup-api.mjs +2 -5
- package/lib/core/experimental/setup-api.mjs.map +1 -1
- package/lib/core/experimental/sources/interceptor-source.d.mts +2 -2
- package/lib/core/experimental/sources/interceptor-source.d.ts +2 -2
- package/lib/core/experimental/sources/interceptor-source.js.map +1 -1
- package/lib/core/experimental/sources/interceptor-source.mjs +1 -3
- package/lib/core/experimental/sources/interceptor-source.mjs.map +1 -1
- package/lib/core/experimental/sources/network-source.d.mts +2 -2
- package/lib/core/experimental/sources/network-source.d.ts +2 -2
- package/lib/core/experimental/sources/network-source.js +1 -0
- package/lib/core/experimental/sources/network-source.js.map +1 -1
- package/lib/core/experimental/sources/network-source.mjs +2 -0
- package/lib/core/experimental/sources/network-source.mjs.map +1 -1
- package/lib/core/getResponse.d.mts +1 -1
- package/lib/core/getResponse.d.ts +1 -1
- package/lib/core/graphql.d.mts +1 -1
- package/lib/core/graphql.d.ts +1 -1
- package/lib/core/graphql.js +1 -0
- package/lib/core/graphql.js.map +1 -1
- package/lib/core/graphql.mjs +2 -0
- package/lib/core/graphql.mjs.map +1 -1
- package/lib/core/handlers/GraphQLHandler.d.mts +1 -1
- package/lib/core/handlers/GraphQLHandler.d.ts +1 -1
- package/lib/core/handlers/GraphQLHandler.js +1 -0
- package/lib/core/handlers/GraphQLHandler.js.map +1 -1
- package/lib/core/handlers/GraphQLHandler.mjs +4 -1
- package/lib/core/handlers/GraphQLHandler.mjs.map +1 -1
- package/lib/core/handlers/HttpHandler.d.mts +1 -1
- package/lib/core/handlers/HttpHandler.d.ts +1 -1
- package/lib/core/handlers/HttpHandler.js +1 -0
- package/lib/core/handlers/HttpHandler.js.map +1 -1
- package/lib/core/handlers/HttpHandler.mjs +1 -0
- package/lib/core/handlers/HttpHandler.mjs.map +1 -1
- package/lib/core/handlers/RequestHandler.d.mts +1 -1
- package/lib/core/handlers/RequestHandler.d.ts +1 -1
- package/lib/core/handlers/RequestHandler.js +26 -0
- package/lib/core/handlers/RequestHandler.js.map +1 -1
- package/lib/core/handlers/RequestHandler.mjs +27 -0
- package/lib/core/handlers/RequestHandler.mjs.map +1 -1
- package/lib/core/http.d.mts +1 -1
- package/lib/core/http.d.ts +1 -1
- package/lib/core/http.js +1 -0
- package/lib/core/http.js.map +1 -1
- package/lib/core/http.mjs +2 -0
- package/lib/core/http.mjs.map +1 -1
- package/lib/core/index.d.mts +1 -1
- package/lib/core/index.d.ts +1 -1
- package/lib/core/passthrough.d.mts +1 -1
- package/lib/core/passthrough.d.ts +1 -1
- package/lib/core/sse.d.mts +4 -18
- package/lib/core/sse.d.ts +4 -18
- package/lib/core/sse.js +105 -45
- package/lib/core/sse.js.map +1 -1
- package/lib/core/sse.mjs +105 -45
- package/lib/core/sse.mjs.map +1 -1
- package/lib/core/utils/HttpResponse/decorators.d.mts +1 -1
- package/lib/core/utils/HttpResponse/decorators.d.ts +1 -1
- package/lib/core/utils/cookieStore.js.map +1 -1
- package/lib/core/utils/cookieStore.mjs.map +1 -1
- package/lib/core/utils/executeHandlers.d.mts +1 -1
- package/lib/core/utils/executeHandlers.d.ts +1 -1
- package/lib/core/utils/executeHandlers.js +1 -0
- package/lib/core/utils/executeHandlers.js.map +1 -1
- package/lib/core/utils/executeHandlers.mjs +1 -0
- package/lib/core/utils/executeHandlers.mjs.map +1 -1
- package/lib/core/utils/handleRequest.d.mts +1 -1
- package/lib/core/utils/handleRequest.d.ts +1 -1
- package/lib/core/utils/handleRequest.js.map +1 -1
- package/lib/core/utils/handleRequest.mjs.map +1 -1
- package/lib/core/utils/internal/isHandlerKind.d.mts +1 -1
- package/lib/core/utils/internal/isHandlerKind.d.ts +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.d.mts +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +1 -1
- package/lib/core/utils/internal/parseMultipartData.d.mts +1 -1
- package/lib/core/utils/internal/parseMultipartData.d.ts +1 -1
- package/lib/core/utils/internal/parseMultipartData.js +1 -0
- package/lib/core/utils/internal/parseMultipartData.js.map +1 -1
- package/lib/core/utils/internal/parseMultipartData.mjs +1 -0
- package/lib/core/utils/internal/parseMultipartData.mjs.map +1 -1
- package/lib/core/utils/internal/pipeEvents.js +1 -0
- package/lib/core/utils/internal/pipeEvents.js.map +1 -1
- package/lib/core/utils/internal/pipeEvents.mjs +1 -0
- package/lib/core/utils/internal/pipeEvents.mjs.map +1 -1
- package/lib/core/ws/WebSocketClientManager.js.map +1 -1
- package/lib/core/ws/WebSocketClientManager.mjs.map +1 -1
- package/lib/core/ws/WebSocketIndexedDBClientStore.js +1 -0
- package/lib/core/ws/WebSocketIndexedDBClientStore.js.map +1 -1
- package/lib/core/ws/WebSocketIndexedDBClientStore.mjs +1 -0
- package/lib/core/ws/WebSocketIndexedDBClientStore.mjs.map +1 -1
- package/lib/core/ws/WebSocketMemoryClientStore.js +1 -0
- package/lib/core/ws/WebSocketMemoryClientStore.js.map +1 -1
- package/lib/core/ws/WebSocketMemoryClientStore.mjs +1 -0
- package/lib/core/ws/WebSocketMemoryClientStore.mjs.map +1 -1
- package/lib/core/ws/handleWebSocketEvent.d.mts +1 -1
- package/lib/core/ws/handleWebSocketEvent.d.ts +1 -1
- package/lib/core/ws/handleWebSocketEvent.js.map +1 -1
- package/lib/core/ws/handleWebSocketEvent.mjs.map +1 -1
- package/lib/core/ws.js.map +1 -1
- package/lib/core/ws.mjs.map +1 -1
- package/lib/iife/index.js +6316 -6063
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/lib/native/index.js.map +1 -1
- package/lib/native/index.mjs.map +1 -1
- package/lib/node/index.js.map +1 -1
- package/lib/node/index.mjs.map +1 -1
- package/lib/shims/cookie.js +152 -62
- package/lib/shims/cookie.mjs +152 -62
- package/package.json +33 -40
- package/src/browser/glossary.ts +1 -1
- package/src/browser/setup-worker.ts +2 -2
- package/src/browser/sources/service-worker-source.ts +125 -28
- package/src/browser/utils/deserializeRequest.ts +2 -2
- package/src/browser/utils/pruneGetRequestBody.ts +3 -3
- package/src/browser/utils/should-invalidate-worker.test.ts +122 -0
- package/src/browser/utils/should-invalidate-worker.ts +13 -0
- package/src/browser/utils/workerChannel.ts +43 -21
- package/src/core/experimental/define-network.ts +14 -9
- package/src/core/experimental/frames/http-frame.test.ts +2 -1
- package/src/core/experimental/frames/http-frame.ts +6 -2
- package/src/core/experimental/frames/websocket-frame.test.ts +2 -4
- package/src/core/experimental/frames/websocket-frame.ts +3 -2
- package/src/core/experimental/handlers-controller.ts +15 -1
- package/src/core/experimental/index.ts +1 -1
- package/src/core/experimental/on-unhandled-frame.test.ts +2 -4
- package/src/core/experimental/setup-api.ts +4 -8
- package/src/core/experimental/sources/interceptor-source.ts +2 -6
- package/src/core/graphql.ts +8 -8
- package/src/core/handlers/GraphQLHandler.test.ts +3 -4
- package/src/core/handlers/GraphQLHandler.ts +15 -11
- package/src/core/handlers/HttpHandler.test.ts +3 -2
- package/src/core/handlers/HttpHandler.ts +7 -7
- package/src/core/handlers/RequestHandler.ts +33 -5
- package/src/core/http.ts +5 -5
- package/src/core/sse.ts +157 -56
- package/src/core/utils/cookieStore.ts +1 -1
- package/src/core/utils/executeHandlers.ts +2 -4
- package/src/core/utils/handleRequest.test.ts +5 -4
- package/src/core/utils/handleRequest.ts +3 -3
- package/src/core/utils/internal/parseGraphQLRequest.test.ts +2 -4
- package/src/core/utils/internal/parseMultipartData.ts +1 -1
- package/src/core/utils/internal/pipeEvents.ts +2 -1
- package/src/core/utils/request/onUnhandledRequest.test.ts +2 -4
- package/src/core/ws/WebSocketClientManager.test.ts +2 -4
- package/src/core/ws/WebSocketClientManager.ts +1 -1
- package/src/core/ws/WebSocketIndexedDBClientStore.ts +3 -5
- package/src/core/ws/WebSocketMemoryClientStore.ts +3 -5
- package/src/core/ws/handleWebSocketEvent.ts +3 -3
- package/src/core/ws.ts +1 -1
- package/src/native/index.ts +2 -2
- package/src/node/async-handlers-controller.ts +2 -2
- package/src/node/setup-server-common.ts +4 -4
- package/src/node/setup-server.ts +2 -2
- package/lib/core/utils/internal/requestHandlerUtils.d.mts +0 -12
- package/lib/core/utils/internal/requestHandlerUtils.d.ts +0 -12
- package/lib/core/utils/internal/requestHandlerUtils.js +0 -37
- package/lib/core/utils/internal/requestHandlerUtils.js.map +0 -1
- package/lib/core/utils/internal/requestHandlerUtils.mjs +0 -17
- package/lib/core/utils/internal/requestHandlerUtils.mjs.map +0 -1
- package/src/core/utils/internal/requestHandlerUtils.ts +0 -21
- package/lib/core/{network-frame-usYiHS0K.d.ts → on-unhandled-frame-BBR-P3kV.d.ts} +12 -12
- package/lib/core/{network-frame-B7A0ggXE.d.mts → on-unhandled-frame-Cr1KOZ0I.d.mts} +12 -12
package/lib/browser/index.mjs
CHANGED
|
@@ -534,7 +534,7 @@ var _Emitter = class {
|
|
|
534
534
|
var Emitter = _Emitter;
|
|
535
535
|
Emitter.defaultMaxListeners = 10;
|
|
536
536
|
|
|
537
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.
|
|
537
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.3/node_modules/@mswjs/interceptors/lib/browser/createRequestId-DQcIlohW.mjs
|
|
538
538
|
var INTERNAL_REQUEST_ID_HEADER_NAME = "x-interceptors-internal-request-id";
|
|
539
539
|
function getGlobalSymbol(symbol) {
|
|
540
540
|
return globalThis[symbol] || void 0;
|
|
@@ -683,7 +683,7 @@ function createRequestId() {
|
|
|
683
683
|
return Math.random().toString(16).slice(2);
|
|
684
684
|
}
|
|
685
685
|
|
|
686
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.
|
|
686
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.3/node_modules/@mswjs/interceptors/lib/browser/resolveWebSocketUrl-C83-x9iE.mjs
|
|
687
687
|
function resolveWebSocketUrl(url) {
|
|
688
688
|
if (typeof url === "string") return resolveWebSocketUrl(new URL(url, typeof location !== "undefined" ? location.href : void 0));
|
|
689
689
|
if (url.protocol === "http:") url.protocol = "ws:";
|
|
@@ -694,7 +694,7 @@ function resolveWebSocketUrl(url) {
|
|
|
694
694
|
return url.href;
|
|
695
695
|
}
|
|
696
696
|
|
|
697
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.
|
|
697
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.3/node_modules/@mswjs/interceptors/lib/browser/hasConfigurableGlobal-npXitu1-.mjs
|
|
698
698
|
async function emitAsync(emitter, eventName, ...data) {
|
|
699
699
|
const listeners = emitter.listeners(eventName);
|
|
700
700
|
if (listeners.length === 0) return;
|
|
@@ -778,7 +778,7 @@ var DeferredPromise = class extends Promise {
|
|
|
778
778
|
}
|
|
779
779
|
};
|
|
780
780
|
|
|
781
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.
|
|
781
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.3/node_modules/@mswjs/interceptors/lib/browser/interceptors/WebSocket/index.mjs
|
|
782
782
|
function bindEvent(target, event) {
|
|
783
783
|
Object.defineProperties(event, {
|
|
784
784
|
target: {
|
|
@@ -1311,7 +1311,73 @@ function supportsReadableStreamTransfer() {
|
|
|
1311
1311
|
}
|
|
1312
1312
|
}
|
|
1313
1313
|
|
|
1314
|
-
// node_modules/.pnpm/@
|
|
1314
|
+
// node_modules/.pnpm/@open-draft+deferred-promise@3.0.0/node_modules/@open-draft/deferred-promise/build/index.mjs
|
|
1315
|
+
function createDeferredExecutor2() {
|
|
1316
|
+
const executor = ((resolve, reject) => {
|
|
1317
|
+
executor.state = "pending";
|
|
1318
|
+
executor.resolve = (data) => {
|
|
1319
|
+
if (executor.state !== "pending") return;
|
|
1320
|
+
executor.result = data;
|
|
1321
|
+
const onFulfilled = (value) => {
|
|
1322
|
+
executor.state = "fulfilled";
|
|
1323
|
+
return value;
|
|
1324
|
+
};
|
|
1325
|
+
return resolve(data instanceof Promise ? data : Promise.resolve(data).then(onFulfilled));
|
|
1326
|
+
};
|
|
1327
|
+
executor.reject = (reason) => {
|
|
1328
|
+
if (executor.state !== "pending") return;
|
|
1329
|
+
queueMicrotask(() => {
|
|
1330
|
+
executor.state = "rejected";
|
|
1331
|
+
});
|
|
1332
|
+
return reject(executor.rejectionReason = reason);
|
|
1333
|
+
};
|
|
1334
|
+
});
|
|
1335
|
+
return executor;
|
|
1336
|
+
}
|
|
1337
|
+
var DeferredPromise2 = class extends Promise {
|
|
1338
|
+
#executor;
|
|
1339
|
+
resolve;
|
|
1340
|
+
reject;
|
|
1341
|
+
constructor(executor = null) {
|
|
1342
|
+
const deferredExecutor = createDeferredExecutor2();
|
|
1343
|
+
super((originalResolve, originalReject) => {
|
|
1344
|
+
deferredExecutor(originalResolve, originalReject);
|
|
1345
|
+
executor?.(deferredExecutor.resolve, deferredExecutor.reject);
|
|
1346
|
+
});
|
|
1347
|
+
this.#executor = deferredExecutor;
|
|
1348
|
+
this.resolve = this.#executor.resolve;
|
|
1349
|
+
this.reject = this.#executor.reject;
|
|
1350
|
+
}
|
|
1351
|
+
get state() {
|
|
1352
|
+
return this.#executor.state;
|
|
1353
|
+
}
|
|
1354
|
+
get rejectionReason() {
|
|
1355
|
+
return this.#executor.rejectionReason;
|
|
1356
|
+
}
|
|
1357
|
+
then(onFulfilled, onRejected) {
|
|
1358
|
+
return this.#decorate(super.then(onFulfilled, onRejected));
|
|
1359
|
+
}
|
|
1360
|
+
catch(onRejected) {
|
|
1361
|
+
return this.#decorate(super.catch(onRejected));
|
|
1362
|
+
}
|
|
1363
|
+
finally(onfinally) {
|
|
1364
|
+
return this.#decorate(super.finally(onfinally));
|
|
1365
|
+
}
|
|
1366
|
+
#decorate(promise) {
|
|
1367
|
+
return Object.defineProperties(promise, {
|
|
1368
|
+
resolve: {
|
|
1369
|
+
configurable: true,
|
|
1370
|
+
value: this.resolve
|
|
1371
|
+
},
|
|
1372
|
+
reject: {
|
|
1373
|
+
configurable: true,
|
|
1374
|
+
value: this.reject
|
|
1375
|
+
}
|
|
1376
|
+
});
|
|
1377
|
+
}
|
|
1378
|
+
};
|
|
1379
|
+
|
|
1380
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.3/node_modules/@mswjs/interceptors/lib/browser/getRawRequest-BTaNLFr0.mjs
|
|
1315
1381
|
var IS_PATCHED_MODULE = Symbol("isPatchedModule");
|
|
1316
1382
|
var InterceptorError = class InterceptorError2 extends Error {
|
|
1317
1383
|
constructor(message) {
|
|
@@ -1472,7 +1538,7 @@ function setRawRequest(request, rawRequest) {
|
|
|
1472
1538
|
Reflect.set(request, kRawRequest, rawRequest);
|
|
1473
1539
|
}
|
|
1474
1540
|
|
|
1475
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.
|
|
1541
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.3/node_modules/@mswjs/interceptors/lib/browser/bufferUtils-BiiO6HZv.mjs
|
|
1476
1542
|
var encoder = new TextEncoder();
|
|
1477
1543
|
function encodeBuffer(text) {
|
|
1478
1544
|
return encoder.encode(text);
|
|
@@ -1930,21 +1996,31 @@ var WorkerEvent = class extends TypedEvent {
|
|
|
1930
1996
|
}
|
|
1931
1997
|
};
|
|
1932
1998
|
var WorkerChannel = class extends Emitter2 {
|
|
1999
|
+
#getWorker;
|
|
2000
|
+
#controller;
|
|
1933
2001
|
constructor(options) {
|
|
1934
2002
|
super();
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
2003
|
+
invariant(
|
|
2004
|
+
SUPPORTS_SERVICE_WORKER,
|
|
2005
|
+
"Failed to open a WorkerChannel: Service Worker is not supported in this environment."
|
|
2006
|
+
);
|
|
2007
|
+
this.#getWorker = options.getWorker;
|
|
2008
|
+
this.#controller = new AbortController();
|
|
2009
|
+
navigator.serviceWorker.addEventListener(
|
|
2010
|
+
"message",
|
|
2011
|
+
async (event) => {
|
|
2012
|
+
const worker = await this.#getWorker();
|
|
2013
|
+
if (event.source != null && event.source !== worker) {
|
|
2014
|
+
return;
|
|
2015
|
+
}
|
|
2016
|
+
if (event.data && isObject(event.data) && "type" in event.data) {
|
|
2017
|
+
this.emit(new WorkerEvent(event));
|
|
2018
|
+
}
|
|
2019
|
+
},
|
|
2020
|
+
{
|
|
2021
|
+
signal: this.#controller.signal
|
|
1946
2022
|
}
|
|
1947
|
-
|
|
2023
|
+
);
|
|
1948
2024
|
}
|
|
1949
2025
|
/**
|
|
1950
2026
|
* Send data to the Service Worker controlling this client.
|
|
@@ -1953,12 +2029,20 @@ var WorkerChannel = class extends Emitter2 {
|
|
|
1953
2029
|
postMessage(type) {
|
|
1954
2030
|
invariant(
|
|
1955
2031
|
SUPPORTS_SERVICE_WORKER,
|
|
1956
|
-
"Failed to post message on a WorkerChannel: the Service Worker API is unavailable in this
|
|
2032
|
+
"Failed to post message on a WorkerChannel: the Service Worker API is unavailable in this environment. This is likely an issue with MSW. Please report it on GitHub: https://github.com/mswjs/msw/issues"
|
|
1957
2033
|
);
|
|
1958
|
-
this.
|
|
2034
|
+
this.#getWorker().then((worker) => {
|
|
1959
2035
|
worker.postMessage(type);
|
|
1960
2036
|
});
|
|
1961
2037
|
}
|
|
2038
|
+
/**
|
|
2039
|
+
* Terminal teardown. Removes the `navigator.serviceWorker` message listener
|
|
2040
|
+
* and all emitter subscriptions. The channel is not usable afterwards.
|
|
2041
|
+
*/
|
|
2042
|
+
terminate() {
|
|
2043
|
+
this.#controller.abort();
|
|
2044
|
+
this.removeAllListeners();
|
|
2045
|
+
}
|
|
1962
2046
|
};
|
|
1963
2047
|
|
|
1964
2048
|
// src/browser/utils/pruneGetRequestBody.ts
|
|
@@ -1990,40 +2074,63 @@ function validateWorkerScope(registration) {
|
|
|
1990
2074
|
}
|
|
1991
2075
|
}
|
|
1992
2076
|
|
|
2077
|
+
// src/browser/utils/should-invalidate-worker.ts
|
|
2078
|
+
function shouldInvalidateWorker(prevOptions, nextOptions) {
|
|
2079
|
+
return prevOptions.findWorker !== nextOptions.findWorker || prevOptions.serviceWorker.url !== nextOptions.serviceWorker.url || JSON.stringify(prevOptions.serviceWorker.options) !== JSON.stringify(nextOptions.serviceWorker.options);
|
|
2080
|
+
}
|
|
2081
|
+
|
|
1993
2082
|
// src/browser/sources/service-worker-source.ts
|
|
1994
|
-
var ServiceWorkerSource = class extends NetworkSource {
|
|
2083
|
+
var ServiceWorkerSource = class _ServiceWorkerSource extends NetworkSource {
|
|
2084
|
+
static #current;
|
|
2085
|
+
/**
|
|
2086
|
+
* Create a new Service Worker source or reuse an existing one.
|
|
2087
|
+
* These sources act as a singleton and only get recreated if the options change.
|
|
2088
|
+
*/
|
|
2089
|
+
static async from(options) {
|
|
2090
|
+
if (_ServiceWorkerSource.#current == null) {
|
|
2091
|
+
_ServiceWorkerSource.#current = new _ServiceWorkerSource(options);
|
|
2092
|
+
} else if (shouldInvalidateWorker(_ServiceWorkerSource.#current.#options, options)) {
|
|
2093
|
+
await _ServiceWorkerSource.#current.terminate();
|
|
2094
|
+
_ServiceWorkerSource.#current = new _ServiceWorkerSource(options);
|
|
2095
|
+
}
|
|
2096
|
+
return _ServiceWorkerSource.#current;
|
|
2097
|
+
}
|
|
2098
|
+
#options;
|
|
2099
|
+
#frames;
|
|
2100
|
+
#channel;
|
|
2101
|
+
#listenerController;
|
|
2102
|
+
#clientPromise;
|
|
2103
|
+
#keepAliveInterval;
|
|
2104
|
+
#stoppedAt;
|
|
2105
|
+
workerPromise;
|
|
1995
2106
|
constructor(options) {
|
|
1996
2107
|
super();
|
|
1997
|
-
this.options = options;
|
|
1998
2108
|
invariant(
|
|
1999
2109
|
supportsServiceWorker(),
|
|
2000
2110
|
"Failed to use Service Worker as the network source: the Service Worker API is not supported in this environment"
|
|
2001
2111
|
);
|
|
2112
|
+
this.#options = options;
|
|
2002
2113
|
this.#frames = /* @__PURE__ */ new Map();
|
|
2003
|
-
this.workerPromise = new
|
|
2114
|
+
this.workerPromise = new DeferredPromise2();
|
|
2004
2115
|
this.#channel = new WorkerChannel({
|
|
2005
|
-
|
|
2116
|
+
getWorker: () => this.workerPromise.then(([worker]) => worker)
|
|
2006
2117
|
});
|
|
2007
2118
|
}
|
|
2008
|
-
#frames;
|
|
2009
|
-
#channel;
|
|
2010
|
-
#clientPromise;
|
|
2011
|
-
#keepAliveInterval;
|
|
2012
|
-
#stoppedAt;
|
|
2013
|
-
workerPromise;
|
|
2014
2119
|
async enable() {
|
|
2015
|
-
this.#stoppedAt
|
|
2016
|
-
if (this.workerPromise.state !== "pending") {
|
|
2120
|
+
if (this.workerPromise.state === "fulfilled" && typeof this.#stoppedAt == "undefined") {
|
|
2017
2121
|
devUtils3.warn(
|
|
2018
2122
|
'Found a redundant "worker.start()" call. Note that starting the worker while mocking is already enabled will have no effect. Consider removing this "worker.start()" call.'
|
|
2019
2123
|
);
|
|
2020
2124
|
return this.workerPromise.then(([, registration2]) => registration2);
|
|
2021
2125
|
}
|
|
2126
|
+
this.#stoppedAt = void 0;
|
|
2022
2127
|
this.#channel.removeAllListeners();
|
|
2128
|
+
this.#frames.clear();
|
|
2129
|
+
this.#listenerController = new AbortController();
|
|
2023
2130
|
const [worker, registration] = await this.#startWorker();
|
|
2024
2131
|
if (worker.state !== "activated") {
|
|
2025
2132
|
const controller = new AbortController();
|
|
2026
|
-
const activationPromise = new
|
|
2133
|
+
const activationPromise = new DeferredPromise2();
|
|
2027
2134
|
activationPromise.then(() => controller.abort());
|
|
2028
2135
|
worker.addEventListener(
|
|
2029
2136
|
"statechange",
|
|
@@ -2032,18 +2139,20 @@ var ServiceWorkerSource = class extends NetworkSource {
|
|
|
2032
2139
|
activationPromise.resolve();
|
|
2033
2140
|
}
|
|
2034
2141
|
},
|
|
2035
|
-
{
|
|
2142
|
+
{
|
|
2143
|
+
signal: controller.signal
|
|
2144
|
+
}
|
|
2036
2145
|
);
|
|
2037
2146
|
await activationPromise;
|
|
2038
2147
|
}
|
|
2039
2148
|
this.#channel.postMessage("MOCK_ACTIVATE");
|
|
2040
|
-
const clientConfirmationPromise = new
|
|
2149
|
+
const clientConfirmationPromise = new DeferredPromise2();
|
|
2041
2150
|
this.#clientPromise = clientConfirmationPromise;
|
|
2042
2151
|
this.#channel.once("MOCKING_ENABLED", (event) => {
|
|
2043
2152
|
clientConfirmationPromise.resolve(event.data.client);
|
|
2044
2153
|
});
|
|
2045
2154
|
await clientConfirmationPromise;
|
|
2046
|
-
if (!this
|
|
2155
|
+
if (!this.#options.quiet) {
|
|
2047
2156
|
this.#printStartMessage();
|
|
2048
2157
|
}
|
|
2049
2158
|
return registration;
|
|
@@ -2056,24 +2165,47 @@ var ServiceWorkerSource = class extends NetworkSource {
|
|
|
2056
2165
|
return;
|
|
2057
2166
|
}
|
|
2058
2167
|
this.#stoppedAt = Date.now();
|
|
2059
|
-
this.#
|
|
2060
|
-
this
|
|
2061
|
-
|
|
2168
|
+
this.#listenerController?.abort();
|
|
2169
|
+
this.#listenerController = void 0;
|
|
2170
|
+
this.#channel.postMessage("CLIENT_CLOSED");
|
|
2171
|
+
if (!this.#options.quiet) {
|
|
2062
2172
|
this.#printStopMessage();
|
|
2063
2173
|
}
|
|
2064
2174
|
}
|
|
2175
|
+
/**
|
|
2176
|
+
* Terminal teardown. Unregisters the Service Worker, tears down the channel,
|
|
2177
|
+
* and clears timers. Called when the singleton is being replaced with one
|
|
2178
|
+
* that has different options. The instance is not usable afterwards.
|
|
2179
|
+
*/
|
|
2180
|
+
async terminate() {
|
|
2181
|
+
if (this.#keepAliveInterval != null) {
|
|
2182
|
+
clearInterval(this.#keepAliveInterval);
|
|
2183
|
+
this.#keepAliveInterval = void 0;
|
|
2184
|
+
}
|
|
2185
|
+
this.#frames.clear();
|
|
2186
|
+
this.#channel.terminate();
|
|
2187
|
+
this.#listenerController?.abort();
|
|
2188
|
+
this.#listenerController = void 0;
|
|
2189
|
+
if (this.workerPromise.state === "fulfilled") {
|
|
2190
|
+
const [, registration] = await this.workerPromise;
|
|
2191
|
+
await registration.unregister();
|
|
2192
|
+
}
|
|
2193
|
+
if (_ServiceWorkerSource.#current === this) {
|
|
2194
|
+
_ServiceWorkerSource.#current = void 0;
|
|
2195
|
+
}
|
|
2196
|
+
}
|
|
2065
2197
|
async #startWorker() {
|
|
2066
2198
|
if (this.#keepAliveInterval) {
|
|
2067
2199
|
clearInterval(this.#keepAliveInterval);
|
|
2068
2200
|
}
|
|
2069
|
-
const workerUrl = this
|
|
2201
|
+
const workerUrl = this.#options.serviceWorker.url;
|
|
2070
2202
|
const [worker, registration] = await getWorkerInstance(
|
|
2071
2203
|
workerUrl,
|
|
2072
|
-
this
|
|
2073
|
-
this
|
|
2204
|
+
this.#options.serviceWorker.options,
|
|
2205
|
+
this.#options.findWorker || this.#defaultFindWorker
|
|
2074
2206
|
);
|
|
2075
2207
|
if (worker == null) {
|
|
2076
|
-
const missingWorkerMessage = this
|
|
2208
|
+
const missingWorkerMessage = this.#options?.findWorker ? devUtils3.formatMessage(
|
|
2077
2209
|
`Failed to locate the Service Worker registration using a custom "findWorker" predicate.
|
|
2078
2210
|
|
|
2079
2211
|
Please ensure that the custom predicate properly locates the Service Worker registration at "%s".
|
|
@@ -2091,16 +2223,28 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
2091
2223
|
);
|
|
2092
2224
|
throw new Error(missingWorkerMessage);
|
|
2093
2225
|
}
|
|
2094
|
-
this.workerPromise.
|
|
2226
|
+
if (this.workerPromise.state === "pending") {
|
|
2227
|
+
this.workerPromise.resolve([worker, registration]);
|
|
2228
|
+
} else {
|
|
2229
|
+
this.workerPromise = new DeferredPromise2((resolve) => {
|
|
2230
|
+
resolve([worker, registration]);
|
|
2231
|
+
});
|
|
2232
|
+
}
|
|
2095
2233
|
this.#channel.on("REQUEST", this.#handleRequest.bind(this));
|
|
2096
2234
|
this.#channel.on("RESPONSE", this.#handleResponse.bind(this));
|
|
2097
|
-
window.addEventListener(
|
|
2098
|
-
|
|
2099
|
-
|
|
2235
|
+
window.addEventListener(
|
|
2236
|
+
"beforeunload",
|
|
2237
|
+
() => {
|
|
2238
|
+
if (worker.state !== "redundant") {
|
|
2239
|
+
this.#channel.postMessage("CLIENT_CLOSED");
|
|
2240
|
+
}
|
|
2241
|
+
clearInterval(this.#keepAliveInterval);
|
|
2242
|
+
window.postMessage({ type: "msw/worker:stop" });
|
|
2243
|
+
},
|
|
2244
|
+
{
|
|
2245
|
+
signal: this.#listenerController?.signal
|
|
2100
2246
|
}
|
|
2101
|
-
|
|
2102
|
-
window.postMessage({ type: "msw/worker:stop" });
|
|
2103
|
-
});
|
|
2247
|
+
);
|
|
2104
2248
|
await this.#checkWorkerIntegrity().catch((error2) => {
|
|
2105
2249
|
devUtils3.error(
|
|
2106
2250
|
"Error while checking the worker script integrity. Please report this on GitHub (https://github.com/mswjs/msw/issues) and include the original error below."
|
|
@@ -2110,7 +2254,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
2110
2254
|
this.#keepAliveInterval = window.setInterval(() => {
|
|
2111
2255
|
this.#channel.postMessage("KEEPALIVE_REQUEST");
|
|
2112
2256
|
}, 5e3);
|
|
2113
|
-
if (!this
|
|
2257
|
+
if (!this.#options.quiet) {
|
|
2114
2258
|
validateWorkerScope(registration);
|
|
2115
2259
|
}
|
|
2116
2260
|
return [worker, registration];
|
|
@@ -2174,7 +2318,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
2174
2318
|
return workerUrl === mockServiceWorkerUrl;
|
|
2175
2319
|
};
|
|
2176
2320
|
async #checkWorkerIntegrity() {
|
|
2177
|
-
const integrityCheckPromise = new
|
|
2321
|
+
const integrityCheckPromise = new DeferredPromise2();
|
|
2178
2322
|
this.#channel.postMessage("INTEGRITY_CHECK_REQUEST");
|
|
2179
2323
|
this.#channel.once("INTEGRITY_CHECK_RESPONSE", (event) => {
|
|
2180
2324
|
const { checksum, packageVersion } = event.data;
|
|
@@ -2298,7 +2442,7 @@ var until2 = async (promise) => {
|
|
|
2298
2442
|
}
|
|
2299
2443
|
};
|
|
2300
2444
|
|
|
2301
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.
|
|
2445
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.3/node_modules/@mswjs/interceptors/lib/browser/handleRequest-D7kpTI5U.mjs
|
|
2302
2446
|
function isObject2(value, loose = false) {
|
|
2303
2447
|
return loose ? Object.prototype.toString.call(value).startsWith("[object ") : Object.prototype.toString.call(value) === "[object Object]";
|
|
2304
2448
|
}
|
|
@@ -2415,7 +2559,7 @@ async function handleRequest(options) {
|
|
|
2415
2559
|
return options.controller.handled;
|
|
2416
2560
|
}
|
|
2417
2561
|
|
|
2418
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.
|
|
2562
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.3/node_modules/@mswjs/interceptors/lib/browser/fetch-DdKEdDOR.mjs
|
|
2419
2563
|
function createNetworkError(cause) {
|
|
2420
2564
|
return Object.assign(/* @__PURE__ */ new TypeError("Failed to fetch"), { cause });
|
|
2421
2565
|
}
|
|
@@ -2608,7 +2752,7 @@ var FetchInterceptor = class FetchInterceptor2 extends Interceptor {
|
|
|
2608
2752
|
}
|
|
2609
2753
|
};
|
|
2610
2754
|
|
|
2611
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.
|
|
2755
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.3/node_modules/@mswjs/interceptors/lib/browser/XMLHttpRequest-BvxZV0WU.mjs
|
|
2612
2756
|
function concatArrayBuffer(left, right) {
|
|
2613
2757
|
const result = new Uint8Array(left.byteLength + right.byteLength);
|
|
2614
2758
|
result.set(left, 0);
|
|
@@ -3299,7 +3443,7 @@ function setupWorker(...handlers) {
|
|
|
3299
3443
|
);
|
|
3300
3444
|
return;
|
|
3301
3445
|
}
|
|
3302
|
-
const httpSource = supportsServiceWorker() ?
|
|
3446
|
+
const httpSource = supportsServiceWorker() ? await ServiceWorkerSource.from({
|
|
3303
3447
|
serviceWorker: {
|
|
3304
3448
|
url: options?.serviceWorker?.url?.toString() || DEFAULT_WORKER_URL,
|
|
3305
3449
|
options: options?.serviceWorker?.options
|