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/cli/init.js
CHANGED
package/lib/browser/index.js
CHANGED
|
@@ -561,7 +561,7 @@ var _Emitter = class {
|
|
|
561
561
|
var Emitter = _Emitter;
|
|
562
562
|
Emitter.defaultMaxListeners = 10;
|
|
563
563
|
|
|
564
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.
|
|
564
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.3/node_modules/@mswjs/interceptors/lib/browser/createRequestId-DQcIlohW.mjs
|
|
565
565
|
var INTERNAL_REQUEST_ID_HEADER_NAME = "x-interceptors-internal-request-id";
|
|
566
566
|
function getGlobalSymbol(symbol) {
|
|
567
567
|
return globalThis[symbol] || void 0;
|
|
@@ -710,7 +710,7 @@ function createRequestId() {
|
|
|
710
710
|
return Math.random().toString(16).slice(2);
|
|
711
711
|
}
|
|
712
712
|
|
|
713
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.
|
|
713
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.3/node_modules/@mswjs/interceptors/lib/browser/resolveWebSocketUrl-C83-x9iE.mjs
|
|
714
714
|
function resolveWebSocketUrl(url) {
|
|
715
715
|
if (typeof url === "string") return resolveWebSocketUrl(new URL(url, typeof location !== "undefined" ? location.href : void 0));
|
|
716
716
|
if (url.protocol === "http:") url.protocol = "ws:";
|
|
@@ -721,7 +721,7 @@ function resolveWebSocketUrl(url) {
|
|
|
721
721
|
return url.href;
|
|
722
722
|
}
|
|
723
723
|
|
|
724
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.
|
|
724
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.3/node_modules/@mswjs/interceptors/lib/browser/hasConfigurableGlobal-npXitu1-.mjs
|
|
725
725
|
async function emitAsync(emitter, eventName, ...data) {
|
|
726
726
|
const listeners = emitter.listeners(eventName);
|
|
727
727
|
if (listeners.length === 0) return;
|
|
@@ -805,7 +805,7 @@ var DeferredPromise = class extends Promise {
|
|
|
805
805
|
}
|
|
806
806
|
};
|
|
807
807
|
|
|
808
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.
|
|
808
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.3/node_modules/@mswjs/interceptors/lib/browser/interceptors/WebSocket/index.mjs
|
|
809
809
|
function bindEvent(target, event) {
|
|
810
810
|
Object.defineProperties(event, {
|
|
811
811
|
target: {
|
|
@@ -1335,7 +1335,73 @@ function supportsReadableStreamTransfer() {
|
|
|
1335
1335
|
}
|
|
1336
1336
|
}
|
|
1337
1337
|
|
|
1338
|
-
// node_modules/.pnpm/@
|
|
1338
|
+
// node_modules/.pnpm/@open-draft+deferred-promise@3.0.0/node_modules/@open-draft/deferred-promise/build/index.mjs
|
|
1339
|
+
function createDeferredExecutor2() {
|
|
1340
|
+
const executor = ((resolve, reject) => {
|
|
1341
|
+
executor.state = "pending";
|
|
1342
|
+
executor.resolve = (data) => {
|
|
1343
|
+
if (executor.state !== "pending") return;
|
|
1344
|
+
executor.result = data;
|
|
1345
|
+
const onFulfilled = (value) => {
|
|
1346
|
+
executor.state = "fulfilled";
|
|
1347
|
+
return value;
|
|
1348
|
+
};
|
|
1349
|
+
return resolve(data instanceof Promise ? data : Promise.resolve(data).then(onFulfilled));
|
|
1350
|
+
};
|
|
1351
|
+
executor.reject = (reason) => {
|
|
1352
|
+
if (executor.state !== "pending") return;
|
|
1353
|
+
queueMicrotask(() => {
|
|
1354
|
+
executor.state = "rejected";
|
|
1355
|
+
});
|
|
1356
|
+
return reject(executor.rejectionReason = reason);
|
|
1357
|
+
};
|
|
1358
|
+
});
|
|
1359
|
+
return executor;
|
|
1360
|
+
}
|
|
1361
|
+
var DeferredPromise2 = class extends Promise {
|
|
1362
|
+
#executor;
|
|
1363
|
+
resolve;
|
|
1364
|
+
reject;
|
|
1365
|
+
constructor(executor = null) {
|
|
1366
|
+
const deferredExecutor = createDeferredExecutor2();
|
|
1367
|
+
super((originalResolve, originalReject) => {
|
|
1368
|
+
deferredExecutor(originalResolve, originalReject);
|
|
1369
|
+
executor?.(deferredExecutor.resolve, deferredExecutor.reject);
|
|
1370
|
+
});
|
|
1371
|
+
this.#executor = deferredExecutor;
|
|
1372
|
+
this.resolve = this.#executor.resolve;
|
|
1373
|
+
this.reject = this.#executor.reject;
|
|
1374
|
+
}
|
|
1375
|
+
get state() {
|
|
1376
|
+
return this.#executor.state;
|
|
1377
|
+
}
|
|
1378
|
+
get rejectionReason() {
|
|
1379
|
+
return this.#executor.rejectionReason;
|
|
1380
|
+
}
|
|
1381
|
+
then(onFulfilled, onRejected) {
|
|
1382
|
+
return this.#decorate(super.then(onFulfilled, onRejected));
|
|
1383
|
+
}
|
|
1384
|
+
catch(onRejected) {
|
|
1385
|
+
return this.#decorate(super.catch(onRejected));
|
|
1386
|
+
}
|
|
1387
|
+
finally(onfinally) {
|
|
1388
|
+
return this.#decorate(super.finally(onfinally));
|
|
1389
|
+
}
|
|
1390
|
+
#decorate(promise) {
|
|
1391
|
+
return Object.defineProperties(promise, {
|
|
1392
|
+
resolve: {
|
|
1393
|
+
configurable: true,
|
|
1394
|
+
value: this.resolve
|
|
1395
|
+
},
|
|
1396
|
+
reject: {
|
|
1397
|
+
configurable: true,
|
|
1398
|
+
value: this.reject
|
|
1399
|
+
}
|
|
1400
|
+
});
|
|
1401
|
+
}
|
|
1402
|
+
};
|
|
1403
|
+
|
|
1404
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.3/node_modules/@mswjs/interceptors/lib/browser/getRawRequest-BTaNLFr0.mjs
|
|
1339
1405
|
var IS_PATCHED_MODULE = Symbol("isPatchedModule");
|
|
1340
1406
|
var InterceptorError = class InterceptorError2 extends Error {
|
|
1341
1407
|
constructor(message) {
|
|
@@ -1496,7 +1562,7 @@ function setRawRequest(request, rawRequest) {
|
|
|
1496
1562
|
Reflect.set(request, kRawRequest, rawRequest);
|
|
1497
1563
|
}
|
|
1498
1564
|
|
|
1499
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.
|
|
1565
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.3/node_modules/@mswjs/interceptors/lib/browser/bufferUtils-BiiO6HZv.mjs
|
|
1500
1566
|
var encoder = new TextEncoder();
|
|
1501
1567
|
function encodeBuffer(text) {
|
|
1502
1568
|
return encoder.encode(text);
|
|
@@ -1951,21 +2017,31 @@ var WorkerEvent = class extends TypedEvent {
|
|
|
1951
2017
|
}
|
|
1952
2018
|
};
|
|
1953
2019
|
var WorkerChannel = class extends Emitter2 {
|
|
2020
|
+
#getWorker;
|
|
2021
|
+
#controller;
|
|
1954
2022
|
constructor(options) {
|
|
1955
2023
|
super();
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
2024
|
+
invariant(
|
|
2025
|
+
SUPPORTS_SERVICE_WORKER,
|
|
2026
|
+
"Failed to open a WorkerChannel: Service Worker is not supported in this environment."
|
|
2027
|
+
);
|
|
2028
|
+
this.#getWorker = options.getWorker;
|
|
2029
|
+
this.#controller = new AbortController();
|
|
2030
|
+
navigator.serviceWorker.addEventListener(
|
|
2031
|
+
"message",
|
|
2032
|
+
async (event) => {
|
|
2033
|
+
const worker = await this.#getWorker();
|
|
2034
|
+
if (event.source != null && event.source !== worker) {
|
|
2035
|
+
return;
|
|
2036
|
+
}
|
|
2037
|
+
if (event.data && (0, import_isObject.isObject)(event.data) && "type" in event.data) {
|
|
2038
|
+
this.emit(new WorkerEvent(event));
|
|
2039
|
+
}
|
|
2040
|
+
},
|
|
2041
|
+
{
|
|
2042
|
+
signal: this.#controller.signal
|
|
1967
2043
|
}
|
|
1968
|
-
|
|
2044
|
+
);
|
|
1969
2045
|
}
|
|
1970
2046
|
/**
|
|
1971
2047
|
* Send data to the Service Worker controlling this client.
|
|
@@ -1974,12 +2050,20 @@ var WorkerChannel = class extends Emitter2 {
|
|
|
1974
2050
|
postMessage(type) {
|
|
1975
2051
|
invariant(
|
|
1976
2052
|
SUPPORTS_SERVICE_WORKER,
|
|
1977
|
-
"Failed to post message on a WorkerChannel: the Service Worker API is unavailable in this
|
|
2053
|
+
"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"
|
|
1978
2054
|
);
|
|
1979
|
-
this.
|
|
2055
|
+
this.#getWorker().then((worker) => {
|
|
1980
2056
|
worker.postMessage(type);
|
|
1981
2057
|
});
|
|
1982
2058
|
}
|
|
2059
|
+
/**
|
|
2060
|
+
* Terminal teardown. Removes the `navigator.serviceWorker` message listener
|
|
2061
|
+
* and all emitter subscriptions. The channel is not usable afterwards.
|
|
2062
|
+
*/
|
|
2063
|
+
terminate() {
|
|
2064
|
+
this.#controller.abort();
|
|
2065
|
+
this.removeAllListeners();
|
|
2066
|
+
}
|
|
1983
2067
|
};
|
|
1984
2068
|
|
|
1985
2069
|
// src/browser/utils/pruneGetRequestBody.ts
|
|
@@ -2011,40 +2095,63 @@ function validateWorkerScope(registration) {
|
|
|
2011
2095
|
}
|
|
2012
2096
|
}
|
|
2013
2097
|
|
|
2098
|
+
// src/browser/utils/should-invalidate-worker.ts
|
|
2099
|
+
function shouldInvalidateWorker(prevOptions, nextOptions) {
|
|
2100
|
+
return prevOptions.findWorker !== nextOptions.findWorker || prevOptions.serviceWorker.url !== nextOptions.serviceWorker.url || JSON.stringify(prevOptions.serviceWorker.options) !== JSON.stringify(nextOptions.serviceWorker.options);
|
|
2101
|
+
}
|
|
2102
|
+
|
|
2014
2103
|
// src/browser/sources/service-worker-source.ts
|
|
2015
|
-
var ServiceWorkerSource = class extends import_network_source.NetworkSource {
|
|
2104
|
+
var ServiceWorkerSource = class _ServiceWorkerSource extends import_network_source.NetworkSource {
|
|
2105
|
+
static #current;
|
|
2106
|
+
/**
|
|
2107
|
+
* Create a new Service Worker source or reuse an existing one.
|
|
2108
|
+
* These sources act as a singleton and only get recreated if the options change.
|
|
2109
|
+
*/
|
|
2110
|
+
static async from(options) {
|
|
2111
|
+
if (_ServiceWorkerSource.#current == null) {
|
|
2112
|
+
_ServiceWorkerSource.#current = new _ServiceWorkerSource(options);
|
|
2113
|
+
} else if (shouldInvalidateWorker(_ServiceWorkerSource.#current.#options, options)) {
|
|
2114
|
+
await _ServiceWorkerSource.#current.terminate();
|
|
2115
|
+
_ServiceWorkerSource.#current = new _ServiceWorkerSource(options);
|
|
2116
|
+
}
|
|
2117
|
+
return _ServiceWorkerSource.#current;
|
|
2118
|
+
}
|
|
2119
|
+
#options;
|
|
2120
|
+
#frames;
|
|
2121
|
+
#channel;
|
|
2122
|
+
#listenerController;
|
|
2123
|
+
#clientPromise;
|
|
2124
|
+
#keepAliveInterval;
|
|
2125
|
+
#stoppedAt;
|
|
2126
|
+
workerPromise;
|
|
2016
2127
|
constructor(options) {
|
|
2017
2128
|
super();
|
|
2018
|
-
this.options = options;
|
|
2019
2129
|
invariant(
|
|
2020
2130
|
supportsServiceWorker(),
|
|
2021
2131
|
"Failed to use Service Worker as the network source: the Service Worker API is not supported in this environment"
|
|
2022
2132
|
);
|
|
2133
|
+
this.#options = options;
|
|
2023
2134
|
this.#frames = /* @__PURE__ */ new Map();
|
|
2024
|
-
this.workerPromise = new
|
|
2135
|
+
this.workerPromise = new DeferredPromise2();
|
|
2025
2136
|
this.#channel = new WorkerChannel({
|
|
2026
|
-
|
|
2137
|
+
getWorker: () => this.workerPromise.then(([worker]) => worker)
|
|
2027
2138
|
});
|
|
2028
2139
|
}
|
|
2029
|
-
#frames;
|
|
2030
|
-
#channel;
|
|
2031
|
-
#clientPromise;
|
|
2032
|
-
#keepAliveInterval;
|
|
2033
|
-
#stoppedAt;
|
|
2034
|
-
workerPromise;
|
|
2035
2140
|
async enable() {
|
|
2036
|
-
this.#stoppedAt
|
|
2037
|
-
if (this.workerPromise.state !== "pending") {
|
|
2141
|
+
if (this.workerPromise.state === "fulfilled" && typeof this.#stoppedAt == "undefined") {
|
|
2038
2142
|
import_devUtils3.devUtils.warn(
|
|
2039
2143
|
'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.'
|
|
2040
2144
|
);
|
|
2041
2145
|
return this.workerPromise.then(([, registration2]) => registration2);
|
|
2042
2146
|
}
|
|
2147
|
+
this.#stoppedAt = void 0;
|
|
2043
2148
|
this.#channel.removeAllListeners();
|
|
2149
|
+
this.#frames.clear();
|
|
2150
|
+
this.#listenerController = new AbortController();
|
|
2044
2151
|
const [worker, registration] = await this.#startWorker();
|
|
2045
2152
|
if (worker.state !== "activated") {
|
|
2046
2153
|
const controller = new AbortController();
|
|
2047
|
-
const activationPromise = new
|
|
2154
|
+
const activationPromise = new DeferredPromise2();
|
|
2048
2155
|
activationPromise.then(() => controller.abort());
|
|
2049
2156
|
worker.addEventListener(
|
|
2050
2157
|
"statechange",
|
|
@@ -2053,18 +2160,20 @@ var ServiceWorkerSource = class extends import_network_source.NetworkSource {
|
|
|
2053
2160
|
activationPromise.resolve();
|
|
2054
2161
|
}
|
|
2055
2162
|
},
|
|
2056
|
-
{
|
|
2163
|
+
{
|
|
2164
|
+
signal: controller.signal
|
|
2165
|
+
}
|
|
2057
2166
|
);
|
|
2058
2167
|
await activationPromise;
|
|
2059
2168
|
}
|
|
2060
2169
|
this.#channel.postMessage("MOCK_ACTIVATE");
|
|
2061
|
-
const clientConfirmationPromise = new
|
|
2170
|
+
const clientConfirmationPromise = new DeferredPromise2();
|
|
2062
2171
|
this.#clientPromise = clientConfirmationPromise;
|
|
2063
2172
|
this.#channel.once("MOCKING_ENABLED", (event) => {
|
|
2064
2173
|
clientConfirmationPromise.resolve(event.data.client);
|
|
2065
2174
|
});
|
|
2066
2175
|
await clientConfirmationPromise;
|
|
2067
|
-
if (!this
|
|
2176
|
+
if (!this.#options.quiet) {
|
|
2068
2177
|
this.#printStartMessage();
|
|
2069
2178
|
}
|
|
2070
2179
|
return registration;
|
|
@@ -2077,24 +2186,47 @@ var ServiceWorkerSource = class extends import_network_source.NetworkSource {
|
|
|
2077
2186
|
return;
|
|
2078
2187
|
}
|
|
2079
2188
|
this.#stoppedAt = Date.now();
|
|
2080
|
-
this.#
|
|
2081
|
-
this
|
|
2082
|
-
|
|
2189
|
+
this.#listenerController?.abort();
|
|
2190
|
+
this.#listenerController = void 0;
|
|
2191
|
+
this.#channel.postMessage("CLIENT_CLOSED");
|
|
2192
|
+
if (!this.#options.quiet) {
|
|
2083
2193
|
this.#printStopMessage();
|
|
2084
2194
|
}
|
|
2085
2195
|
}
|
|
2196
|
+
/**
|
|
2197
|
+
* Terminal teardown. Unregisters the Service Worker, tears down the channel,
|
|
2198
|
+
* and clears timers. Called when the singleton is being replaced with one
|
|
2199
|
+
* that has different options. The instance is not usable afterwards.
|
|
2200
|
+
*/
|
|
2201
|
+
async terminate() {
|
|
2202
|
+
if (this.#keepAliveInterval != null) {
|
|
2203
|
+
clearInterval(this.#keepAliveInterval);
|
|
2204
|
+
this.#keepAliveInterval = void 0;
|
|
2205
|
+
}
|
|
2206
|
+
this.#frames.clear();
|
|
2207
|
+
this.#channel.terminate();
|
|
2208
|
+
this.#listenerController?.abort();
|
|
2209
|
+
this.#listenerController = void 0;
|
|
2210
|
+
if (this.workerPromise.state === "fulfilled") {
|
|
2211
|
+
const [, registration] = await this.workerPromise;
|
|
2212
|
+
await registration.unregister();
|
|
2213
|
+
}
|
|
2214
|
+
if (_ServiceWorkerSource.#current === this) {
|
|
2215
|
+
_ServiceWorkerSource.#current = void 0;
|
|
2216
|
+
}
|
|
2217
|
+
}
|
|
2086
2218
|
async #startWorker() {
|
|
2087
2219
|
if (this.#keepAliveInterval) {
|
|
2088
2220
|
clearInterval(this.#keepAliveInterval);
|
|
2089
2221
|
}
|
|
2090
|
-
const workerUrl = this
|
|
2222
|
+
const workerUrl = this.#options.serviceWorker.url;
|
|
2091
2223
|
const [worker, registration] = await getWorkerInstance(
|
|
2092
2224
|
workerUrl,
|
|
2093
|
-
this
|
|
2094
|
-
this
|
|
2225
|
+
this.#options.serviceWorker.options,
|
|
2226
|
+
this.#options.findWorker || this.#defaultFindWorker
|
|
2095
2227
|
);
|
|
2096
2228
|
if (worker == null) {
|
|
2097
|
-
const missingWorkerMessage = this
|
|
2229
|
+
const missingWorkerMessage = this.#options?.findWorker ? import_devUtils3.devUtils.formatMessage(
|
|
2098
2230
|
`Failed to locate the Service Worker registration using a custom "findWorker" predicate.
|
|
2099
2231
|
|
|
2100
2232
|
Please ensure that the custom predicate properly locates the Service Worker registration at "%s".
|
|
@@ -2112,16 +2244,28 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
2112
2244
|
);
|
|
2113
2245
|
throw new Error(missingWorkerMessage);
|
|
2114
2246
|
}
|
|
2115
|
-
this.workerPromise.
|
|
2247
|
+
if (this.workerPromise.state === "pending") {
|
|
2248
|
+
this.workerPromise.resolve([worker, registration]);
|
|
2249
|
+
} else {
|
|
2250
|
+
this.workerPromise = new DeferredPromise2((resolve) => {
|
|
2251
|
+
resolve([worker, registration]);
|
|
2252
|
+
});
|
|
2253
|
+
}
|
|
2116
2254
|
this.#channel.on("REQUEST", this.#handleRequest.bind(this));
|
|
2117
2255
|
this.#channel.on("RESPONSE", this.#handleResponse.bind(this));
|
|
2118
|
-
window.addEventListener(
|
|
2119
|
-
|
|
2120
|
-
|
|
2256
|
+
window.addEventListener(
|
|
2257
|
+
"beforeunload",
|
|
2258
|
+
() => {
|
|
2259
|
+
if (worker.state !== "redundant") {
|
|
2260
|
+
this.#channel.postMessage("CLIENT_CLOSED");
|
|
2261
|
+
}
|
|
2262
|
+
clearInterval(this.#keepAliveInterval);
|
|
2263
|
+
window.postMessage({ type: "msw/worker:stop" });
|
|
2264
|
+
},
|
|
2265
|
+
{
|
|
2266
|
+
signal: this.#listenerController?.signal
|
|
2121
2267
|
}
|
|
2122
|
-
|
|
2123
|
-
window.postMessage({ type: "msw/worker:stop" });
|
|
2124
|
-
});
|
|
2268
|
+
);
|
|
2125
2269
|
await this.#checkWorkerIntegrity().catch((error2) => {
|
|
2126
2270
|
import_devUtils3.devUtils.error(
|
|
2127
2271
|
"Error while checking the worker script integrity. Please report this on GitHub (https://github.com/mswjs/msw/issues) and include the original error below."
|
|
@@ -2131,7 +2275,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
2131
2275
|
this.#keepAliveInterval = window.setInterval(() => {
|
|
2132
2276
|
this.#channel.postMessage("KEEPALIVE_REQUEST");
|
|
2133
2277
|
}, 5e3);
|
|
2134
|
-
if (!this
|
|
2278
|
+
if (!this.#options.quiet) {
|
|
2135
2279
|
validateWorkerScope(registration);
|
|
2136
2280
|
}
|
|
2137
2281
|
return [worker, registration];
|
|
@@ -2195,7 +2339,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
2195
2339
|
return workerUrl === mockServiceWorkerUrl;
|
|
2196
2340
|
};
|
|
2197
2341
|
async #checkWorkerIntegrity() {
|
|
2198
|
-
const integrityCheckPromise = new
|
|
2342
|
+
const integrityCheckPromise = new DeferredPromise2();
|
|
2199
2343
|
this.#channel.postMessage("INTEGRITY_CHECK_REQUEST");
|
|
2200
2344
|
this.#channel.once("INTEGRITY_CHECK_RESPONSE", (event) => {
|
|
2201
2345
|
const { checksum, packageVersion } = event.data;
|
|
@@ -2319,7 +2463,7 @@ var until2 = async (promise) => {
|
|
|
2319
2463
|
}
|
|
2320
2464
|
};
|
|
2321
2465
|
|
|
2322
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.
|
|
2466
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.3/node_modules/@mswjs/interceptors/lib/browser/handleRequest-D7kpTI5U.mjs
|
|
2323
2467
|
function isObject2(value, loose = false) {
|
|
2324
2468
|
return loose ? Object.prototype.toString.call(value).startsWith("[object ") : Object.prototype.toString.call(value) === "[object Object]";
|
|
2325
2469
|
}
|
|
@@ -2436,7 +2580,7 @@ async function handleRequest(options) {
|
|
|
2436
2580
|
return options.controller.handled;
|
|
2437
2581
|
}
|
|
2438
2582
|
|
|
2439
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.
|
|
2583
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.3/node_modules/@mswjs/interceptors/lib/browser/fetch-DdKEdDOR.mjs
|
|
2440
2584
|
function createNetworkError(cause) {
|
|
2441
2585
|
return Object.assign(/* @__PURE__ */ new TypeError("Failed to fetch"), { cause });
|
|
2442
2586
|
}
|
|
@@ -2629,7 +2773,7 @@ var FetchInterceptor = class FetchInterceptor2 extends Interceptor {
|
|
|
2629
2773
|
}
|
|
2630
2774
|
};
|
|
2631
2775
|
|
|
2632
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.
|
|
2776
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.3/node_modules/@mswjs/interceptors/lib/browser/XMLHttpRequest-BvxZV0WU.mjs
|
|
2633
2777
|
function concatArrayBuffer(left, right) {
|
|
2634
2778
|
const result = new Uint8Array(left.byteLength + right.byteLength);
|
|
2635
2779
|
result.set(left, 0);
|
|
@@ -3320,7 +3464,7 @@ function setupWorker(...handlers) {
|
|
|
3320
3464
|
);
|
|
3321
3465
|
return;
|
|
3322
3466
|
}
|
|
3323
|
-
const httpSource = supportsServiceWorker() ?
|
|
3467
|
+
const httpSource = supportsServiceWorker() ? await ServiceWorkerSource.from({
|
|
3324
3468
|
serviceWorker: {
|
|
3325
3469
|
url: options?.serviceWorker?.url?.toString() || DEFAULT_WORKER_URL,
|
|
3326
3470
|
options: options?.serviceWorker?.options
|