msw 0.27.1 → 0.28.2
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/esm/RequestHandler-deps.js +10 -15
- package/lib/esm/errors-deps.js +1 -1
- package/lib/esm/fetch-deps.js +402 -110
- package/lib/esm/graphql-deps.js +2 -2
- package/lib/esm/index-deps.js +1 -1
- package/lib/esm/index.js +66 -29
- package/lib/esm/index2.js +1 -1
- package/lib/esm/mockServiceWorker.js +19 -17
- package/lib/esm/rest-deps.js +3 -3
- package/lib/iife/index.js +4 -4
- package/lib/iife/mockServiceWorker.js +19 -17
- package/lib/types/node/createSetupServer.d.ts +1 -1
- package/lib/types/node/glossary.d.ts +3 -3
- package/lib/types/utils/internal/compose.d.ts +2 -5
- package/lib/umd/index.js +478 -154
- package/lib/umd/mockServiceWorker.js +19 -17
- package/native/lib/index.js +588 -278
- package/node/lib/index.js +593 -280
- package/package.json +8 -11
package/lib/esm/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { i as context } from './index-deps.js';
|
|
2
|
-
import { c as createCommonjsModule, a as commonjsGlobal,
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import { c as createCommonjsModule, a as commonjsGlobal, l as lib$2, j as jsonParse, i as isNodeProcess } from './fetch-deps.js';
|
|
3
|
+
import { _ as __awaiter, g as getPublicUrlFromRequest, p as parseBody, N as NetworkError } from './RequestHandler-deps.js';
|
|
4
|
+
export { R as RequestHandler, b as compose, c as createResponseComposition, a as defaultContext, d as defaultResponse, m as matchRequestUrl, r as response } from './RequestHandler-deps.js';
|
|
5
5
|
import { p as parseGraphQLRequest, G as GraphQLHandler } from './graphql-deps.js';
|
|
6
6
|
export { G as GraphQLHandler, g as graphql, a as graphqlContext } from './graphql-deps.js';
|
|
7
7
|
import { R as RestHandler, i as isStringEqual } from './rest-deps.js';
|
|
@@ -438,31 +438,52 @@ function unwrapListeners(arr) {
|
|
|
438
438
|
|
|
439
439
|
function once(emitter, name) {
|
|
440
440
|
return new Promise(function (resolve, reject) {
|
|
441
|
-
function
|
|
442
|
-
|
|
441
|
+
function errorListener(err) {
|
|
442
|
+
emitter.removeListener(name, resolver);
|
|
443
|
+
reject(err);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
function resolver() {
|
|
447
|
+
if (typeof emitter.removeListener === 'function') {
|
|
443
448
|
emitter.removeListener('error', errorListener);
|
|
444
449
|
}
|
|
445
450
|
resolve([].slice.call(arguments));
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
// Adding an error listener is not optional because
|
|
449
|
-
// if an error is thrown on an event emitter we cannot
|
|
450
|
-
// guarantee that the actual event we are waiting will
|
|
451
|
-
// be fired. The result could be a silent way to create
|
|
452
|
-
// memory or file descriptor leaks, which is something
|
|
453
|
-
// we should avoid.
|
|
451
|
+
}
|
|
452
|
+
eventTargetAgnosticAddListener(emitter, name, resolver, { once: true });
|
|
454
453
|
if (name !== 'error') {
|
|
455
|
-
errorListener
|
|
456
|
-
emitter.removeListener(name, eventListener);
|
|
457
|
-
reject(err);
|
|
458
|
-
};
|
|
459
|
-
|
|
460
|
-
emitter.once('error', errorListener);
|
|
454
|
+
addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true });
|
|
461
455
|
}
|
|
462
|
-
|
|
463
|
-
emitter.once(name, eventListener);
|
|
464
456
|
});
|
|
465
457
|
}
|
|
458
|
+
|
|
459
|
+
function addErrorHandlerIfEventEmitter(emitter, handler, flags) {
|
|
460
|
+
if (typeof emitter.on === 'function') {
|
|
461
|
+
eventTargetAgnosticAddListener(emitter, 'error', handler, flags);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
|
|
466
|
+
if (typeof emitter.on === 'function') {
|
|
467
|
+
if (flags.once) {
|
|
468
|
+
emitter.once(name, listener);
|
|
469
|
+
} else {
|
|
470
|
+
emitter.on(name, listener);
|
|
471
|
+
}
|
|
472
|
+
} else if (typeof emitter.addEventListener === 'function') {
|
|
473
|
+
// EventTarget does not have `error` event semantics like Node
|
|
474
|
+
// EventEmitters, we do not listen for `error` events here.
|
|
475
|
+
emitter.addEventListener(name, function wrapListener(arg) {
|
|
476
|
+
// IE does not have builtin `{ once: true }` support so we
|
|
477
|
+
// have to do it manually.
|
|
478
|
+
if (flags.once) {
|
|
479
|
+
emitter.removeEventListener(name, wrapListener);
|
|
480
|
+
}
|
|
481
|
+
listener(arg);
|
|
482
|
+
});
|
|
483
|
+
} else {
|
|
484
|
+
throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof emitter);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
466
487
|
events.once = once_1;
|
|
467
488
|
|
|
468
489
|
var StrictEventEmitter_1 = createCommonjsModule(function (module, exports) {
|
|
@@ -690,9 +711,17 @@ const getResponse = (request, handlers) => __awaiter(void 0, void 0, void 0, fun
|
|
|
690
711
|
return acc;
|
|
691
712
|
}
|
|
692
713
|
const result = yield handler.run(request);
|
|
693
|
-
if (result === null ||
|
|
714
|
+
if (result === null || result.handler.shouldSkip) {
|
|
694
715
|
return null;
|
|
695
716
|
}
|
|
717
|
+
if (!result.response) {
|
|
718
|
+
return {
|
|
719
|
+
request: result.request,
|
|
720
|
+
handler: result.handler,
|
|
721
|
+
response: undefined,
|
|
722
|
+
parsedResult: result.parsedResult,
|
|
723
|
+
};
|
|
724
|
+
}
|
|
696
725
|
if (result.response.once) {
|
|
697
726
|
handler.markAsSkipped(true);
|
|
698
727
|
}
|
|
@@ -956,7 +985,9 @@ function parseString(setCookieValue, options) {
|
|
|
956
985
|
value = options.decodeValues ? decodeURIComponent(value) : value; // decode cookie value
|
|
957
986
|
} catch (e) {
|
|
958
987
|
console.error(
|
|
959
|
-
|
|
988
|
+
"set-cookie-parser encountered an error while decoding a cookie with value '" +
|
|
989
|
+
value +
|
|
990
|
+
"'. Set options.decodeValues to false to disable this feature.",
|
|
960
991
|
e
|
|
961
992
|
);
|
|
962
993
|
}
|
|
@@ -1234,8 +1265,14 @@ class CookieStore {
|
|
|
1234
1265
|
if (persistedCookies) {
|
|
1235
1266
|
try {
|
|
1236
1267
|
const parsedCookies = JSON.parse(persistedCookies);
|
|
1237
|
-
parsedCookies.forEach(([origin,
|
|
1238
|
-
this.store.set(origin, new Map(
|
|
1268
|
+
parsedCookies.forEach(([origin, cookies]) => {
|
|
1269
|
+
this.store.set(origin, new Map(cookies.map((_a) => {
|
|
1270
|
+
var [token, _b] = _a, { expires } = _b, cookie = __rest(_b, ["expires"]);
|
|
1271
|
+
return [
|
|
1272
|
+
token,
|
|
1273
|
+
expires === undefined ? cookie : Object.assign(Object.assign({}, cookie), { expires: new Date(expires) })
|
|
1274
|
+
];
|
|
1275
|
+
})));
|
|
1239
1276
|
});
|
|
1240
1277
|
}
|
|
1241
1278
|
catch (error) {
|
|
@@ -1362,7 +1399,7 @@ function parseWorkerRequest(rawRequest) {
|
|
|
1362
1399
|
destination: rawRequest.destination,
|
|
1363
1400
|
body: pruneGetRequestBody(rawRequest),
|
|
1364
1401
|
bodyUsed: rawRequest.bodyUsed,
|
|
1365
|
-
headers: new Headers(rawRequest.headers),
|
|
1402
|
+
headers: new lib$2.Headers(rawRequest.headers),
|
|
1366
1403
|
};
|
|
1367
1404
|
// Set document cookies on the request.
|
|
1368
1405
|
setRequestCookies(request);
|
|
@@ -1402,7 +1439,7 @@ const createRequestListener = (context, options) => {
|
|
|
1402
1439
|
return channel.send({ type: 'MOCK_NOT_FOUND' });
|
|
1403
1440
|
}
|
|
1404
1441
|
readResponseCookies(request, response);
|
|
1405
|
-
const responseWithSerializedHeaders = Object.assign(Object.assign({}, response), { headers: headersToList(response.headers) });
|
|
1442
|
+
const responseWithSerializedHeaders = Object.assign(Object.assign({}, response), { headers: lib$2.headersToList(response.headers) });
|
|
1406
1443
|
if (!options.quiet) {
|
|
1407
1444
|
setTimeout(() => {
|
|
1408
1445
|
handler.log(publicRequest, responseWithSerializedHeaders, handler, parsedRequest);
|
|
@@ -1450,8 +1487,8 @@ function requestIntegrityCheck(context, serviceWorker) {
|
|
|
1450
1487
|
const { payload: actualChecksum } = yield context.events.once('INTEGRITY_CHECK_RESPONSE');
|
|
1451
1488
|
// Compare the response from the Service Worker and the
|
|
1452
1489
|
// global variable set by webpack upon build.
|
|
1453
|
-
if (actualChecksum !== "
|
|
1454
|
-
throw new Error(`Currently active Service Worker (${actualChecksum}) is behind the latest published one (${"
|
|
1490
|
+
if (actualChecksum !== "82ef9b96d8393b6da34527d1d6e19187") {
|
|
1491
|
+
throw new Error(`Currently active Service Worker (${actualChecksum}) is behind the latest published one (${"82ef9b96d8393b6da34527d1d6e19187"}).`);
|
|
1455
1492
|
}
|
|
1456
1493
|
return serviceWorker;
|
|
1457
1494
|
});
|
package/lib/esm/index2.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { d as delay, f as fetch,
|
|
1
|
+
export { d as delay, f as fetch, e as json, b as set, s as status } from './fetch-deps.js';
|
|
2
2
|
export { b as body, c as cookie, t as text, x as xml } from './xml-deps.js';
|
|
3
3
|
export { d as data, e as errors } from './errors-deps.js';
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
/* eslint-disable */
|
|
8
8
|
/* tslint:disable */
|
|
9
9
|
|
|
10
|
-
const INTEGRITY_CHECKSUM = '
|
|
10
|
+
const INTEGRITY_CHECKSUM = '82ef9b96d8393b6da34527d1d6e19187'
|
|
11
11
|
const bypassHeaderName = 'x-msw-bypass'
|
|
12
12
|
const activeClientIds = new Set()
|
|
13
13
|
|
|
@@ -114,22 +114,24 @@ async function handleRequest(event, requestId) {
|
|
|
114
114
|
// Send back the response clone for the "response:*" life-cycle events.
|
|
115
115
|
// Ensure MSW is active and ready to handle the message, otherwise
|
|
116
116
|
// this message will pend indefinitely.
|
|
117
|
-
if (activeClientIds.has(client.id)) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
117
|
+
if (client && activeClientIds.has(client.id)) {
|
|
118
|
+
;(async function () {
|
|
119
|
+
const clonedResponse = response.clone()
|
|
120
|
+
sendToClient(client, {
|
|
121
|
+
type: 'RESPONSE',
|
|
122
|
+
payload: {
|
|
123
|
+
requestId,
|
|
124
|
+
type: clonedResponse.type,
|
|
125
|
+
ok: clonedResponse.ok,
|
|
126
|
+
status: clonedResponse.status,
|
|
127
|
+
statusText: clonedResponse.statusText,
|
|
128
|
+
body:
|
|
129
|
+
clonedResponse.body === null ? null : await clonedResponse.text(),
|
|
130
|
+
headers: serializeHeaders(clonedResponse.headers),
|
|
131
|
+
redirected: clonedResponse.redirected,
|
|
132
|
+
},
|
|
133
|
+
})
|
|
134
|
+
})()
|
|
133
135
|
}
|
|
134
136
|
|
|
135
137
|
return response
|
package/lib/esm/rest-deps.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { R as RequestHandler,
|
|
2
|
-
import {
|
|
1
|
+
import { R as RequestHandler, e as getUrlByMask, m as matchRequestUrl, g as getPublicUrlFromRequest, f as prepareRequest, h as prepareResponse, i as getTimestamp, j as getStatusCodeColor } from './RequestHandler-deps.js';
|
|
2
|
+
import { b as set, s as status, e as json, d as delay, f as fetch } from './fetch-deps.js';
|
|
3
3
|
import { c as cookie, b as body, t as text, x as xml } from './xml-deps.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -72,7 +72,7 @@ ${queryParams
|
|
|
72
72
|
return matchRequestUrl(request.url, this.info.mask);
|
|
73
73
|
}
|
|
74
74
|
getPublicRequest(request, parsedResult) {
|
|
75
|
-
return Object.assign(Object.assign({}, request), { params: parsedResult.params });
|
|
75
|
+
return Object.assign(Object.assign({}, request), { params: parsedResult.params || {} });
|
|
76
76
|
}
|
|
77
77
|
predicate(request, parsedResult) {
|
|
78
78
|
return (isStringEqual(this.info.method, request.method) && parsedResult.matches);
|