msw 2.14.3 → 2.14.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/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 +9 -0
- package/lib/core/experimental/sources/interceptor-source.js.map +1 -1
- package/lib/core/experimental/sources/interceptor-source.mjs +9 -0
- 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 +90 -1
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/package.json +2 -2
- package/src/core/experimental/sources/interceptor-source.ts +14 -0
- 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
|
@@ -16166,7 +16166,9 @@ ${operationTypes.join("\n")}
|
|
|
16166
16166
|
resolver;
|
|
16167
16167
|
resolverIterator;
|
|
16168
16168
|
resolverIteratorResult;
|
|
16169
|
+
resolverIteratorCleanups;
|
|
16169
16170
|
options;
|
|
16171
|
+
scheduledCleanups;
|
|
16170
16172
|
info;
|
|
16171
16173
|
/**
|
|
16172
16174
|
* Indicates whether this request handler has been used
|
|
@@ -16176,6 +16178,7 @@ ${operationTypes.join("\n")}
|
|
|
16176
16178
|
constructor(args) {
|
|
16177
16179
|
this.resolver = args.resolver;
|
|
16178
16180
|
this.options = args.options;
|
|
16181
|
+
this.scheduledCleanups = /* @__PURE__ */ new Map();
|
|
16179
16182
|
const callFrame = getCallFrame(new Error());
|
|
16180
16183
|
this.info = {
|
|
16181
16184
|
...args.info,
|
|
@@ -16190,9 +16193,11 @@ ${operationTypes.join("\n")}
|
|
|
16190
16193
|
* from a clean state.
|
|
16191
16194
|
*/
|
|
16192
16195
|
reset() {
|
|
16196
|
+
this.scheduledCleanups.clear();
|
|
16193
16197
|
const iterator = this.resolverIterator;
|
|
16194
16198
|
this.resolverIterator = void 0;
|
|
16195
16199
|
this.resolverIteratorResult = void 0;
|
|
16200
|
+
this.resolverIteratorCleanups = void 0;
|
|
16196
16201
|
if (typeof iterator?.return === "function") {
|
|
16197
16202
|
void Promise.resolve(iterator.return());
|
|
16198
16203
|
}
|
|
@@ -16278,8 +16283,20 @@ ${operationTypes.join("\n")}
|
|
|
16278
16283
|
request: args.request,
|
|
16279
16284
|
parsedResult
|
|
16280
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
|
+
);
|
|
16281
16295
|
const mockedResponsePromise = executeResolver({
|
|
16282
16296
|
...resolverExtras,
|
|
16297
|
+
finalize: (callback) => {
|
|
16298
|
+
this.scheduleCleanup(args.requestId, callback);
|
|
16299
|
+
},
|
|
16283
16300
|
requestId: args.requestId,
|
|
16284
16301
|
request: args.request
|
|
16285
16302
|
}).catch((errorOrResponse) => {
|
|
@@ -16287,6 +16304,8 @@ ${operationTypes.join("\n")}
|
|
|
16287
16304
|
return errorOrResponse;
|
|
16288
16305
|
}
|
|
16289
16306
|
throw errorOrResponse;
|
|
16307
|
+
}).finally(() => {
|
|
16308
|
+
listenerController.abort();
|
|
16290
16309
|
});
|
|
16291
16310
|
const mockedResponse = await mockedResponsePromise;
|
|
16292
16311
|
if (mockedResponse) {
|
|
@@ -16305,10 +16324,22 @@ ${operationTypes.join("\n")}
|
|
|
16305
16324
|
wrapResolver(resolver) {
|
|
16306
16325
|
return async (info) => {
|
|
16307
16326
|
if (!this.resolverIterator) {
|
|
16308
|
-
|
|
16327
|
+
let result;
|
|
16328
|
+
try {
|
|
16329
|
+
result = await resolver(info);
|
|
16330
|
+
} catch (error3) {
|
|
16331
|
+
await this.runScheduledCleanups(info.requestId);
|
|
16332
|
+
throw error3;
|
|
16333
|
+
}
|
|
16309
16334
|
if (!isIterable(result)) {
|
|
16335
|
+
await this.runScheduledCleanups(info.requestId);
|
|
16310
16336
|
return result;
|
|
16311
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
|
+
}
|
|
16312
16343
|
this.resolverIterator = Symbol.iterator in result ? result[Symbol.iterator]() : result[Symbol.asyncIterator]();
|
|
16313
16344
|
}
|
|
16314
16345
|
this.isUsed = false;
|
|
@@ -16319,6 +16350,7 @@ ${operationTypes.join("\n")}
|
|
|
16319
16350
|
}
|
|
16320
16351
|
if (done) {
|
|
16321
16352
|
this.isUsed = true;
|
|
16353
|
+
await this.runScheduledCleanups(info.requestId);
|
|
16322
16354
|
return this.resolverIteratorResult?.clone();
|
|
16323
16355
|
}
|
|
16324
16356
|
return nextResponse;
|
|
@@ -16333,6 +16365,54 @@ ${operationTypes.join("\n")}
|
|
|
16333
16365
|
parsedResult: args.parsedResult
|
|
16334
16366
|
};
|
|
16335
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
|
+
}
|
|
16336
16416
|
};
|
|
16337
16417
|
function forwardResponseCookies(response) {
|
|
16338
16418
|
if (typeof document === "undefined") {
|
|
@@ -23036,6 +23116,15 @@ Read more: https://mswjs.io/docs/websocket`;
|
|
|
23036
23116
|
var InterceptorWebSocketNetworkFrame = class extends WebSocketNetworkFrame {
|
|
23037
23117
|
constructor(args) {
|
|
23038
23118
|
super({ connection: args.connection });
|
|
23119
|
+
args.connection.client.addEventListener(
|
|
23120
|
+
"close",
|
|
23121
|
+
() => {
|
|
23122
|
+
this.events.removeAllListeners();
|
|
23123
|
+
},
|
|
23124
|
+
{
|
|
23125
|
+
once: true
|
|
23126
|
+
}
|
|
23127
|
+
);
|
|
23039
23128
|
}
|
|
23040
23129
|
errorWith(reason) {
|
|
23041
23130
|
if (reason instanceof Error) {
|