msw 2.14.2 → 2.14.4
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/{HttpResponse-aGiIzO91.d.ts → HttpResponse-BFS34nkx.d.ts} +16 -0
- package/lib/core/{HttpResponse-CxHR1nNN.d.mts → HttpResponse-CQwYpuKo.d.mts} +16 -0
- package/lib/core/HttpResponse.d.mts +1 -1
- package/lib/core/HttpResponse.d.ts +1 -1
- package/lib/core/experimental/compat.d.mts +1 -1
- package/lib/core/experimental/compat.d.ts +1 -1
- package/lib/core/experimental/define-network.d.mts +1 -1
- package/lib/core/experimental/define-network.d.ts +1 -1
- package/lib/core/experimental/frames/http-frame.d.mts +1 -1
- package/lib/core/experimental/frames/http-frame.d.ts +1 -1
- package/lib/core/experimental/frames/network-frame.d.mts +1 -1
- package/lib/core/experimental/frames/network-frame.d.ts +1 -1
- package/lib/core/experimental/frames/websocket-frame.d.mts +1 -1
- package/lib/core/experimental/frames/websocket-frame.d.ts +1 -1
- package/lib/core/experimental/handlers-controller.d.mts +1 -1
- package/lib/core/experimental/handlers-controller.d.ts +1 -1
- package/lib/core/experimental/index.d.mts +1 -1
- package/lib/core/experimental/index.d.ts +1 -1
- package/lib/core/experimental/on-unhandled-frame.d.mts +1 -1
- package/lib/core/experimental/on-unhandled-frame.d.ts +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/sources/interceptor-source.d.mts +1 -1
- package/lib/core/experimental/sources/interceptor-source.d.ts +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/core/experimental/sources/network-source.d.mts +1 -1
- package/lib/core/experimental/sources/network-source.d.ts +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/handlers/GraphQLHandler.d.mts +1 -1
- package/lib/core/handlers/GraphQLHandler.d.ts +1 -1
- package/lib/core/handlers/HttpHandler.d.mts +1 -1
- package/lib/core/handlers/HttpHandler.d.ts +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 +82 -1
- package/lib/core/handlers/RequestHandler.js.map +1 -1
- package/lib/core/handlers/RequestHandler.mjs +82 -1
- 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/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 +1 -1
- package/lib/core/sse.d.ts +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/executeHandlers.d.mts +1 -1
- package/lib/core/utils/executeHandlers.d.ts +1 -1
- package/lib/core/utils/handleRequest.d.mts +1 -1
- package/lib/core/utils/handleRequest.d.ts +1 -1
- package/lib/core/utils/internal/attachSiblingHandlers.d.mts +1 -1
- package/lib/core/utils/internal/attachSiblingHandlers.d.ts +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/ws/handleWebSocketEvent.d.mts +1 -1
- package/lib/core/ws/handleWebSocketEvent.d.ts +1 -1
- package/lib/iife/index.js +183 -49
- 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/src/core/handlers/RequestHandler.ts +144 -10
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AnyHandler } from '../../experimental/handlers-controller.mjs';
|
|
2
|
-
import { R as RequestHandler } from '../../HttpResponse-
|
|
2
|
+
import { R as RequestHandler } from '../../HttpResponse-CQwYpuKo.mjs';
|
|
3
3
|
import { WebSocketHandler } from '../../handlers/WebSocketHandler.mjs';
|
|
4
4
|
import '@mswjs/interceptors';
|
|
5
5
|
import './isIterable.mjs';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AnyHandler } from '../../experimental/handlers-controller.js';
|
|
2
|
-
import { R as RequestHandler } from '../../HttpResponse-
|
|
2
|
+
import { R as RequestHandler } from '../../HttpResponse-BFS34nkx.js';
|
|
3
3
|
import { WebSocketHandler } from '../../handlers/WebSocketHandler.js';
|
|
4
4
|
import '@mswjs/interceptors';
|
|
5
5
|
import './isIterable.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'graphql';
|
|
2
|
-
export { x as GraphQLMultipartRequestBody, w as GraphQLParsedOperationsMap, u as ParsedGraphQLQuery, P as ParsedGraphQLRequest, v as parseDocumentNode, y as parseGraphQLRequest } from '../../HttpResponse-
|
|
2
|
+
export { x as GraphQLMultipartRequestBody, w as GraphQLParsedOperationsMap, u as ParsedGraphQLQuery, P as ParsedGraphQLRequest, v as parseDocumentNode, y as parseGraphQLRequest } from '../../HttpResponse-CQwYpuKo.mjs';
|
|
3
3
|
import '@mswjs/interceptors';
|
|
4
4
|
import './isIterable.mjs';
|
|
5
5
|
import '../../typeUtils.mjs';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'graphql';
|
|
2
|
-
export { x as GraphQLMultipartRequestBody, w as GraphQLParsedOperationsMap, u as ParsedGraphQLQuery, P as ParsedGraphQLRequest, v as parseDocumentNode, y as parseGraphQLRequest } from '../../HttpResponse-
|
|
2
|
+
export { x as GraphQLMultipartRequestBody, w as GraphQLParsedOperationsMap, u as ParsedGraphQLQuery, P as ParsedGraphQLRequest, v as parseDocumentNode, y as parseGraphQLRequest } from '../../HttpResponse-BFS34nkx.js';
|
|
3
3
|
import '@mswjs/interceptors';
|
|
4
4
|
import './isIterable.js';
|
|
5
5
|
import '../../typeUtils.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WebSocketConnectionData } from '@mswjs/interceptors/WebSocket';
|
|
2
|
-
import { R as RequestHandler } from '../HttpResponse-
|
|
2
|
+
import { R as RequestHandler } from '../HttpResponse-CQwYpuKo.mjs';
|
|
3
3
|
import { WebSocketHandler } from '../handlers/WebSocketHandler.mjs';
|
|
4
4
|
import { UnhandledRequestStrategy } from '../utils/request/onUnhandledRequest.mjs';
|
|
5
5
|
import '@mswjs/interceptors';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WebSocketConnectionData } from '@mswjs/interceptors/WebSocket';
|
|
2
|
-
import { R as RequestHandler } from '../HttpResponse-
|
|
2
|
+
import { R as RequestHandler } from '../HttpResponse-BFS34nkx.js';
|
|
3
3
|
import { WebSocketHandler } from '../handlers/WebSocketHandler.js';
|
|
4
4
|
import { UnhandledRequestStrategy } from '../utils/request/onUnhandledRequest.js';
|
|
5
5
|
import '@mswjs/interceptors';
|
package/lib/iife/index.js
CHANGED
|
@@ -14335,7 +14335,7 @@ ${operationTypes.join("\n")}
|
|
|
14335
14335
|
);
|
|
14336
14336
|
}
|
|
14337
14337
|
|
|
14338
|
-
// node_modules/.pnpm/rettime@0.11.
|
|
14338
|
+
// node_modules/.pnpm/rettime@0.11.11/node_modules/rettime/build/lens-list.mjs
|
|
14339
14339
|
var LensList = class {
|
|
14340
14340
|
#list;
|
|
14341
14341
|
#lens;
|
|
@@ -14377,15 +14377,17 @@ ${operationTypes.join("\n")}
|
|
|
14377
14377
|
}
|
|
14378
14378
|
/**
|
|
14379
14379
|
* Delete the value belonging to the given key.
|
|
14380
|
+
* Returns `true` if the value was present and removed, `false` otherwise.
|
|
14380
14381
|
*/
|
|
14381
14382
|
delete(key, value) {
|
|
14382
|
-
if (this.size === 0) return;
|
|
14383
|
-
this.#list = this.#list.filter((item) => item[1] !== value);
|
|
14383
|
+
if (this.size === 0) return false;
|
|
14384
14384
|
const values = this.#lens.get(key);
|
|
14385
|
-
if (values)
|
|
14386
|
-
|
|
14387
|
-
|
|
14388
|
-
|
|
14385
|
+
if (!values) return false;
|
|
14386
|
+
const index = values.indexOf(value);
|
|
14387
|
+
if (index === -1) return false;
|
|
14388
|
+
values.splice(index, 1);
|
|
14389
|
+
this.#list.splice(this.#list.findIndex((item) => item[0] === key && item[1] === value), 1);
|
|
14390
|
+
return true;
|
|
14389
14391
|
}
|
|
14390
14392
|
/**
|
|
14391
14393
|
* Delete all values belogning to the given key.
|
|
@@ -14408,7 +14410,7 @@ ${operationTypes.join("\n")}
|
|
|
14408
14410
|
}
|
|
14409
14411
|
};
|
|
14410
14412
|
|
|
14411
|
-
// node_modules/.pnpm/rettime@0.11.
|
|
14413
|
+
// node_modules/.pnpm/rettime@0.11.11/node_modules/rettime/build/index.mjs
|
|
14412
14414
|
var kDefaultPrevented = Symbol("kDefaultPrevented");
|
|
14413
14415
|
var kPropagationStopped = Symbol("kPropagationStopped");
|
|
14414
14416
|
var kImmediatePropagationStopped = Symbol("kImmediatePropagationStopped");
|
|
@@ -14441,37 +14443,66 @@ ${operationTypes.join("\n")}
|
|
|
14441
14443
|
var Emitter = class {
|
|
14442
14444
|
#listeners;
|
|
14443
14445
|
#listenerOptions;
|
|
14446
|
+
#listenerAbortCleanups;
|
|
14444
14447
|
#typelessListeners;
|
|
14445
14448
|
#hookListeners;
|
|
14446
14449
|
#hookListenerOptions;
|
|
14450
|
+
#hookListenerAbortCleanups;
|
|
14447
14451
|
hooks;
|
|
14448
14452
|
constructor() {
|
|
14449
14453
|
this.#listeners = new LensList();
|
|
14450
14454
|
this.#listenerOptions = /* @__PURE__ */ new WeakMap();
|
|
14455
|
+
this.#listenerAbortCleanups = /* @__PURE__ */ new WeakMap();
|
|
14451
14456
|
this.#typelessListeners = /* @__PURE__ */ new WeakSet();
|
|
14452
14457
|
this.#hookListeners = new LensList();
|
|
14453
14458
|
this.#hookListenerOptions = /* @__PURE__ */ new WeakMap();
|
|
14459
|
+
this.#hookListenerAbortCleanups = /* @__PURE__ */ new WeakMap();
|
|
14454
14460
|
this.hooks = {
|
|
14455
14461
|
on: (hook, callback, options) => {
|
|
14462
|
+
if (options?.signal?.aborted) return;
|
|
14456
14463
|
if (options?.once) {
|
|
14457
14464
|
const original = callback;
|
|
14458
14465
|
const wrapper = ((...args) => {
|
|
14459
|
-
this.#
|
|
14466
|
+
this.#deleteHookListener(hook, wrapper);
|
|
14460
14467
|
return original(...args);
|
|
14461
14468
|
});
|
|
14462
14469
|
callback = wrapper;
|
|
14463
14470
|
}
|
|
14464
14471
|
this.#hookListeners.append(hook, callback);
|
|
14465
14472
|
if (options) this.#hookListenerOptions.set(callback, options);
|
|
14466
|
-
if (options?.signal)
|
|
14467
|
-
|
|
14468
|
-
|
|
14473
|
+
if (options?.signal) {
|
|
14474
|
+
const { signal } = options;
|
|
14475
|
+
const onAbort = () => {
|
|
14476
|
+
this.#deleteHookListener(hook, callback);
|
|
14477
|
+
};
|
|
14478
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
14479
|
+
this.#hookListenerAbortCleanups.set(callback, () => {
|
|
14480
|
+
signal.removeEventListener("abort", onAbort);
|
|
14481
|
+
});
|
|
14482
|
+
}
|
|
14469
14483
|
},
|
|
14470
14484
|
removeListener: (hook, callback) => {
|
|
14471
|
-
this.#
|
|
14485
|
+
this.#deleteHookListener(hook, callback);
|
|
14472
14486
|
}
|
|
14473
14487
|
};
|
|
14474
14488
|
}
|
|
14489
|
+
#deleteHookListener(hook, callback) {
|
|
14490
|
+
this.#hookListeners.delete(hook, callback);
|
|
14491
|
+
const cleanup = this.#hookListenerAbortCleanups.get(callback);
|
|
14492
|
+
if (cleanup) {
|
|
14493
|
+
cleanup();
|
|
14494
|
+
this.#hookListenerAbortCleanups.delete(callback);
|
|
14495
|
+
}
|
|
14496
|
+
}
|
|
14497
|
+
#deleteListener(type, listener) {
|
|
14498
|
+
const removed = this.#listeners.delete(type, listener);
|
|
14499
|
+
const cleanup = this.#listenerAbortCleanups.get(listener);
|
|
14500
|
+
if (cleanup) {
|
|
14501
|
+
cleanup();
|
|
14502
|
+
this.#listenerAbortCleanups.delete(listener);
|
|
14503
|
+
}
|
|
14504
|
+
return removed;
|
|
14505
|
+
}
|
|
14475
14506
|
/**
|
|
14476
14507
|
* Adds a listener for the given event type.
|
|
14477
14508
|
*/
|
|
@@ -14573,8 +14604,8 @@ ${operationTypes.join("\n")}
|
|
|
14573
14604
|
*/
|
|
14574
14605
|
removeListener(type, listener) {
|
|
14575
14606
|
const options = this.#listenerOptions.get(listener);
|
|
14576
|
-
this.#
|
|
14577
|
-
for (const hook of this.#hookListeners.get("removeListener")) hook(type, listener, options);
|
|
14607
|
+
if (!this.#deleteListener(type, listener)) return;
|
|
14608
|
+
for (const hook of this.#hookListeners.get("removeListener").slice()) hook(type, listener, options);
|
|
14578
14609
|
}
|
|
14579
14610
|
/**
|
|
14580
14611
|
* Removes all listeners for the given event type.
|
|
@@ -14582,11 +14613,12 @@ ${operationTypes.join("\n")}
|
|
|
14582
14613
|
*/
|
|
14583
14614
|
removeAllListeners(type) {
|
|
14584
14615
|
if (type == null) {
|
|
14585
|
-
this.#listeners.
|
|
14586
|
-
for (const [hookType, hookListener] of this.#hookListeners) if (!this.#hookListenerOptions.get(hookListener)?.persist) this.#
|
|
14616
|
+
for (const [listenerType, listeners$1] of this.#listeners.entries()) while (listeners$1.length > 0) this.removeListener(listenerType, listeners$1[0]);
|
|
14617
|
+
for (const [hookType, hookListener] of [...this.#hookListeners]) if (!this.#hookListenerOptions.get(hookListener)?.persist) this.#deleteHookListener(hookType, hookListener);
|
|
14587
14618
|
return;
|
|
14588
14619
|
}
|
|
14589
|
-
this
|
|
14620
|
+
const listeners = this.listeners(type);
|
|
14621
|
+
while (listeners.length > 0) this.removeListener(type, listeners[0]);
|
|
14590
14622
|
}
|
|
14591
14623
|
/**
|
|
14592
14624
|
* Returns the list of listeners for the given event type.
|
|
@@ -14605,15 +14637,23 @@ ${operationTypes.join("\n")}
|
|
|
14605
14637
|
return this.listeners(type).length;
|
|
14606
14638
|
}
|
|
14607
14639
|
#addListener(type, listener, options, insertMode = "append") {
|
|
14608
|
-
|
|
14640
|
+
if (options?.signal?.aborted) return;
|
|
14641
|
+
for (const hook of this.#hookListeners.get("newListener").slice()) hook(type, listener, options);
|
|
14609
14642
|
if (type === "*") this.#typelessListeners.add(listener);
|
|
14610
14643
|
if (insertMode === "prepend") this.#listeners.prepend(type, listener);
|
|
14611
14644
|
else this.#listeners.append(type, listener);
|
|
14612
14645
|
if (options) {
|
|
14613
14646
|
this.#listenerOptions.set(listener, options);
|
|
14614
|
-
if (options.signal)
|
|
14615
|
-
|
|
14616
|
-
|
|
14647
|
+
if (options.signal) {
|
|
14648
|
+
const { signal } = options;
|
|
14649
|
+
const onAbort = () => {
|
|
14650
|
+
this.removeListener(type, listener);
|
|
14651
|
+
};
|
|
14652
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
14653
|
+
this.#listenerAbortCleanups.set(listener, () => {
|
|
14654
|
+
signal.removeEventListener("abort", onAbort);
|
|
14655
|
+
});
|
|
14656
|
+
}
|
|
14617
14657
|
}
|
|
14618
14658
|
}
|
|
14619
14659
|
#proxyEvent(event) {
|
|
@@ -14630,22 +14670,27 @@ ${operationTypes.join("\n")}
|
|
|
14630
14670
|
};
|
|
14631
14671
|
}
|
|
14632
14672
|
#callListener(event, listener) {
|
|
14633
|
-
for (const hook of this.#hookListeners.get("beforeEmit")) if (hook(event) === false) return;
|
|
14673
|
+
for (const hook of this.#hookListeners.get("beforeEmit").slice()) if (hook(event) === false) return;
|
|
14634
14674
|
const returnValue = listener.call(this, event);
|
|
14635
14675
|
const options = this.#listenerOptions.get(listener);
|
|
14636
14676
|
if (options?.once) {
|
|
14637
14677
|
const type = this.#isTypelessListener(listener) ? "*" : event.type;
|
|
14638
|
-
this.#
|
|
14639
|
-
for (const hook of this.#hookListeners.get("removeListener")) hook(type, listener, options);
|
|
14678
|
+
if (this.#deleteListener(type, listener)) for (const hook of this.#hookListeners.get("removeListener").slice()) hook(type, listener, options);
|
|
14640
14679
|
}
|
|
14641
14680
|
return returnValue;
|
|
14642
14681
|
}
|
|
14643
14682
|
/**
|
|
14644
14683
|
* Return a list of all event listeners relevant for the given event type.
|
|
14645
14684
|
* This includes the explicit event listeners and also typeless event listeners.
|
|
14685
|
+
*
|
|
14686
|
+
* @note Snapshot the matching listeners before yielding. Listeners can add or
|
|
14687
|
+
* remove other listeners during emission (e.g. `earlyOn` unshifts `#list`),
|
|
14688
|
+
* which would otherwise shift the live iterator and re-yield prior entries.
|
|
14646
14689
|
*/
|
|
14647
14690
|
*#matchListeners(type) {
|
|
14648
|
-
|
|
14691
|
+
const snapshot = [];
|
|
14692
|
+
for (const [key, listener] of this.#listeners) if (key === "*" || key === type) snapshot.push(listener);
|
|
14693
|
+
yield* snapshot;
|
|
14649
14694
|
}
|
|
14650
14695
|
#isTypelessListener(listener) {
|
|
14651
14696
|
return this.#typelessListeners.has(listener);
|
|
@@ -16121,7 +16166,9 @@ ${operationTypes.join("\n")}
|
|
|
16121
16166
|
resolver;
|
|
16122
16167
|
resolverIterator;
|
|
16123
16168
|
resolverIteratorResult;
|
|
16169
|
+
resolverIteratorCleanups;
|
|
16124
16170
|
options;
|
|
16171
|
+
scheduledCleanups;
|
|
16125
16172
|
info;
|
|
16126
16173
|
/**
|
|
16127
16174
|
* Indicates whether this request handler has been used
|
|
@@ -16131,6 +16178,7 @@ ${operationTypes.join("\n")}
|
|
|
16131
16178
|
constructor(args) {
|
|
16132
16179
|
this.resolver = args.resolver;
|
|
16133
16180
|
this.options = args.options;
|
|
16181
|
+
this.scheduledCleanups = /* @__PURE__ */ new Map();
|
|
16134
16182
|
const callFrame = getCallFrame(new Error());
|
|
16135
16183
|
this.info = {
|
|
16136
16184
|
...args.info,
|
|
@@ -16145,9 +16193,11 @@ ${operationTypes.join("\n")}
|
|
|
16145
16193
|
* from a clean state.
|
|
16146
16194
|
*/
|
|
16147
16195
|
reset() {
|
|
16196
|
+
this.scheduledCleanups.clear();
|
|
16148
16197
|
const iterator = this.resolverIterator;
|
|
16149
16198
|
this.resolverIterator = void 0;
|
|
16150
16199
|
this.resolverIteratorResult = void 0;
|
|
16200
|
+
this.resolverIteratorCleanups = void 0;
|
|
16151
16201
|
if (typeof iterator?.return === "function") {
|
|
16152
16202
|
void Promise.resolve(iterator.return());
|
|
16153
16203
|
}
|
|
@@ -16233,8 +16283,20 @@ ${operationTypes.join("\n")}
|
|
|
16233
16283
|
request: args.request,
|
|
16234
16284
|
parsedResult
|
|
16235
16285
|
});
|
|
16286
|
+
const listenerController = new AbortController();
|
|
16287
|
+
args.request.signal.addEventListener(
|
|
16288
|
+
"abort",
|
|
16289
|
+
() => this.runScheduledCleanups(args.requestId),
|
|
16290
|
+
{
|
|
16291
|
+
once: true,
|
|
16292
|
+
signal: listenerController.signal
|
|
16293
|
+
}
|
|
16294
|
+
);
|
|
16236
16295
|
const mockedResponsePromise = executeResolver({
|
|
16237
16296
|
...resolverExtras,
|
|
16297
|
+
finalize: (callback) => {
|
|
16298
|
+
this.scheduleCleanup(args.requestId, callback);
|
|
16299
|
+
},
|
|
16238
16300
|
requestId: args.requestId,
|
|
16239
16301
|
request: args.request
|
|
16240
16302
|
}).catch((errorOrResponse) => {
|
|
@@ -16242,6 +16304,8 @@ ${operationTypes.join("\n")}
|
|
|
16242
16304
|
return errorOrResponse;
|
|
16243
16305
|
}
|
|
16244
16306
|
throw errorOrResponse;
|
|
16307
|
+
}).finally(() => {
|
|
16308
|
+
listenerController.abort();
|
|
16245
16309
|
});
|
|
16246
16310
|
const mockedResponse = await mockedResponsePromise;
|
|
16247
16311
|
if (mockedResponse) {
|
|
@@ -16260,10 +16324,22 @@ ${operationTypes.join("\n")}
|
|
|
16260
16324
|
wrapResolver(resolver) {
|
|
16261
16325
|
return async (info) => {
|
|
16262
16326
|
if (!this.resolverIterator) {
|
|
16263
|
-
|
|
16327
|
+
let result;
|
|
16328
|
+
try {
|
|
16329
|
+
result = await resolver(info);
|
|
16330
|
+
} catch (error3) {
|
|
16331
|
+
await this.runScheduledCleanups(info.requestId);
|
|
16332
|
+
throw error3;
|
|
16333
|
+
}
|
|
16264
16334
|
if (!isIterable(result)) {
|
|
16335
|
+
await this.runScheduledCleanups(info.requestId);
|
|
16265
16336
|
return result;
|
|
16266
16337
|
}
|
|
16338
|
+
const existingCleanups = this.scheduledCleanups.get(info.requestId);
|
|
16339
|
+
if (existingCleanups != null && existingCleanups.length > 0) {
|
|
16340
|
+
this.resolverIteratorCleanups = existingCleanups;
|
|
16341
|
+
this.scheduledCleanups.delete(info.requestId);
|
|
16342
|
+
}
|
|
16267
16343
|
this.resolverIterator = Symbol.iterator in result ? result[Symbol.iterator]() : result[Symbol.asyncIterator]();
|
|
16268
16344
|
}
|
|
16269
16345
|
this.isUsed = false;
|
|
@@ -16274,6 +16350,7 @@ ${operationTypes.join("\n")}
|
|
|
16274
16350
|
}
|
|
16275
16351
|
if (done) {
|
|
16276
16352
|
this.isUsed = true;
|
|
16353
|
+
await this.runScheduledCleanups(info.requestId);
|
|
16277
16354
|
return this.resolverIteratorResult?.clone();
|
|
16278
16355
|
}
|
|
16279
16356
|
return nextResponse;
|
|
@@ -16288,6 +16365,54 @@ ${operationTypes.join("\n")}
|
|
|
16288
16365
|
parsedResult: args.parsedResult
|
|
16289
16366
|
};
|
|
16290
16367
|
}
|
|
16368
|
+
scheduleCleanup(requestId, callback) {
|
|
16369
|
+
if (this.resolverIterator) {
|
|
16370
|
+
;
|
|
16371
|
+
(this.resolverIteratorCleanups ||= []).unshift(callback);
|
|
16372
|
+
return;
|
|
16373
|
+
}
|
|
16374
|
+
const cleanups = this.scheduledCleanups.get(requestId) || [];
|
|
16375
|
+
cleanups.unshift(callback);
|
|
16376
|
+
this.scheduledCleanups.set(requestId, cleanups);
|
|
16377
|
+
}
|
|
16378
|
+
async exhaustCleanups(cleanups) {
|
|
16379
|
+
const errors = [];
|
|
16380
|
+
for (const cleanup of cleanups) {
|
|
16381
|
+
try {
|
|
16382
|
+
await cleanup();
|
|
16383
|
+
} catch (error3) {
|
|
16384
|
+
if (error3 instanceof Error) {
|
|
16385
|
+
errors.push(error3);
|
|
16386
|
+
}
|
|
16387
|
+
}
|
|
16388
|
+
}
|
|
16389
|
+
if (errors.length > 0) {
|
|
16390
|
+
devUtils.error(
|
|
16391
|
+
'Failed to execute cleanup for request handler "%s"',
|
|
16392
|
+
this.info.header,
|
|
16393
|
+
new AggregateError(
|
|
16394
|
+
errors,
|
|
16395
|
+
`Failed to execute cleanup for request handler "${this.info.header}"`
|
|
16396
|
+
)
|
|
16397
|
+
);
|
|
16398
|
+
}
|
|
16399
|
+
}
|
|
16400
|
+
async runScheduledCleanups(requestId) {
|
|
16401
|
+
if (this.resolverIterator && this.resolverIteratorCleanups != null && this.resolverIteratorCleanups.length > 0) {
|
|
16402
|
+
try {
|
|
16403
|
+
await this.exhaustCleanups(this.resolverIteratorCleanups);
|
|
16404
|
+
} finally {
|
|
16405
|
+
this.resolverIteratorCleanups = void 0;
|
|
16406
|
+
}
|
|
16407
|
+
return;
|
|
16408
|
+
}
|
|
16409
|
+
const cleanups = this.scheduledCleanups.get(requestId);
|
|
16410
|
+
if (!cleanups || cleanups.length == 0) {
|
|
16411
|
+
return;
|
|
16412
|
+
}
|
|
16413
|
+
await this.exhaustCleanups(cleanups);
|
|
16414
|
+
this.scheduledCleanups.delete(requestId);
|
|
16415
|
+
}
|
|
16291
16416
|
};
|
|
16292
16417
|
function forwardResponseCookies(response) {
|
|
16293
16418
|
if (typeof document === "undefined") {
|
|
@@ -22937,16 +23062,20 @@ Read more: https://mswjs.io/docs/websocket`;
|
|
|
22937
23062
|
return;
|
|
22938
23063
|
}
|
|
22939
23064
|
queueMicrotask(() => {
|
|
22940
|
-
|
|
22941
|
-
|
|
22942
|
-
|
|
22943
|
-
|
|
22944
|
-
|
|
22945
|
-
|
|
22946
|
-
|
|
22947
|
-
|
|
22948
|
-
|
|
22949
|
-
|
|
23065
|
+
try {
|
|
23066
|
+
httpFrame.events.emit(
|
|
23067
|
+
new ResponseEvent(
|
|
23068
|
+
isMockedResponse ? "response:mocked" : "response:bypass",
|
|
23069
|
+
{
|
|
23070
|
+
requestId,
|
|
23071
|
+
request,
|
|
23072
|
+
response
|
|
23073
|
+
}
|
|
23074
|
+
)
|
|
23075
|
+
);
|
|
23076
|
+
} finally {
|
|
23077
|
+
httpFrame.events.removeAllListeners();
|
|
23078
|
+
}
|
|
22950
23079
|
});
|
|
22951
23080
|
}
|
|
22952
23081
|
async #handleWebSocketConnection(connection) {
|
|
@@ -23439,11 +23568,12 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
23439
23568
|
}
|
|
23440
23569
|
async #handleResponse(event) {
|
|
23441
23570
|
const { request, response, isMockedResponse } = event.data;
|
|
23571
|
+
const frame = this.#frames.get(request.id);
|
|
23442
23572
|
if (response.type?.includes("opaque")) {
|
|
23443
23573
|
this.#frames.delete(request.id);
|
|
23574
|
+
frame?.events.removeAllListeners();
|
|
23444
23575
|
return;
|
|
23445
23576
|
}
|
|
23446
|
-
const frame = this.#frames.get(request.id);
|
|
23447
23577
|
this.#frames.delete(request.id);
|
|
23448
23578
|
if (frame == null) {
|
|
23449
23579
|
return;
|
|
@@ -23467,17 +23597,21 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
23467
23597
|
url: request.url
|
|
23468
23598
|
}
|
|
23469
23599
|
);
|
|
23470
|
-
|
|
23471
|
-
|
|
23472
|
-
|
|
23473
|
-
|
|
23474
|
-
|
|
23475
|
-
|
|
23476
|
-
|
|
23477
|
-
|
|
23478
|
-
|
|
23479
|
-
|
|
23480
|
-
|
|
23600
|
+
try {
|
|
23601
|
+
frame.events.emit(
|
|
23602
|
+
new ResponseEvent(
|
|
23603
|
+
isMockedResponse ? "response:mocked" : "response:bypass",
|
|
23604
|
+
{
|
|
23605
|
+
requestId: frame.data.id,
|
|
23606
|
+
request: fetchRequest,
|
|
23607
|
+
response: fetchResponse,
|
|
23608
|
+
isMockedResponse
|
|
23609
|
+
}
|
|
23610
|
+
)
|
|
23611
|
+
);
|
|
23612
|
+
} finally {
|
|
23613
|
+
frame.events.removeAllListeners();
|
|
23614
|
+
}
|
|
23481
23615
|
}
|
|
23482
23616
|
#defaultFindWorker = (workerUrl, mockServiceWorkerUrl) => {
|
|
23483
23617
|
return workerUrl === mockServiceWorkerUrl;
|