msw 0.27.0 → 0.28.1

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.
@@ -1,6 +1,6 @@
1
- import { j as jsonParse, a as set, s as status, d as delay, f as fetch } from './fetch-deps.js';
1
+ import { j as jsonParse, b as set, s as status, d as delay, f as fetch } from './fetch-deps.js';
2
2
  import { d as data, e as errors } from './errors-deps.js';
3
- import { g as getPublicUrlFromRequest, n as __rest, R as RequestHandler, m as matchRequestUrl, i as prepareRequest, j as prepareResponse, k as getTimestamp, l as getStatusCodeColor } from './RequestHandler-deps.js';
3
+ import { g as getPublicUrlFromRequest, k as __rest, R as RequestHandler, m as matchRequestUrl, f as prepareRequest, h as prepareResponse, i as getTimestamp, j as getStatusCodeColor } from './RequestHandler-deps.js';
4
4
 
5
5
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
6
6
 
@@ -750,11 +750,7 @@ function devAssert(condition, message) {
750
750
  */
751
751
  // See: https://expressjs.com/en/advanced/best-practice-performance.html#set-node_env-to-production
752
752
  // See: https://webpack.js.org/guides/production/
753
- var instanceOf = process.env.NODE_ENV === 'production' ? // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')
754
- // eslint-disable-next-line no-shadow
755
- function instanceOf(value, constructor) {
756
- return value instanceof constructor;
757
- } : // eslint-disable-next-line no-shadow
753
+ var instanceOf = // eslint-disable-next-line no-shadow
758
754
  function instanceOf(value, constructor) {
759
755
  if (value instanceof constructor) {
760
756
  return true;
@@ -1,4 +1,4 @@
1
- import { s as status, a as set, d as delay, f as fetch, b as json } from './fetch-deps.js';
1
+ import { s as status, b as set, d as delay, f as fetch, e as json } from './fetch-deps.js';
2
2
  import { c as cookie, b as body, t as text, x as xml } from './xml-deps.js';
3
3
  import { d as data, e as errors } from './errors-deps.js';
4
4
 
package/lib/esm/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  export { i as context } from './index-deps.js';
2
- import { c as createCommonjsModule, a as commonjsGlobal, _ as __awaiter, g as getPublicUrlFromRequest, p as parseBody, N as NetworkError } from './RequestHandler-deps.js';
3
- export { R as RequestHandler, f as compose, b as createResponseComposition, e as defaultContext, d as defaultResponse, m as matchRequestUrl, r as response } from './RequestHandler-deps.js';
4
- import { H as Headers, h as headersToList, j as jsonParse, i as isNodeProcess } from './fetch-deps.js';
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';
8
- export { a as RESTMethods, r as rest, b as restContext } from './rest-deps.js';
8
+ export { a as RESTMethods, R as RestHandler, r as rest, b as restContext } from './rest-deps.js';
9
9
  import { p as parse_1$1 } from './xml-deps.js';
10
10
  import { m as mergeRight } from './errors-deps.js';
11
11
 
@@ -690,9 +690,17 @@ const getResponse = (request, handlers) => __awaiter(void 0, void 0, void 0, fun
690
690
  return acc;
691
691
  }
692
692
  const result = yield handler.run(request);
693
- if (result === null || !result.response || result.handler.shouldSkip) {
693
+ if (result === null || result.handler.shouldSkip) {
694
694
  return null;
695
695
  }
696
+ if (!result.response) {
697
+ return {
698
+ request: result.request,
699
+ handler: result.handler,
700
+ response: undefined,
701
+ parsedResult: result.parsedResult,
702
+ };
703
+ }
696
704
  if (result.response.once) {
697
705
  handler.markAsSkipped(true);
698
706
  }
@@ -956,7 +964,9 @@ function parseString(setCookieValue, options) {
956
964
  value = options.decodeValues ? decodeURIComponent(value) : value; // decode cookie value
957
965
  } catch (e) {
958
966
  console.error(
959
- `set-cookie-parser encountered an error while decoding a cookie with value '${value}'. Set options.decodeValues to false to disable this feature.`,
967
+ "set-cookie-parser encountered an error while decoding a cookie with value '" +
968
+ value +
969
+ "'. Set options.decodeValues to false to disable this feature.",
960
970
  e
961
971
  );
962
972
  }
@@ -1234,8 +1244,14 @@ class CookieStore {
1234
1244
  if (persistedCookies) {
1235
1245
  try {
1236
1246
  const parsedCookies = JSON.parse(persistedCookies);
1237
- parsedCookies.forEach(([origin, cookie]) => {
1238
- this.store.set(origin, new Map(cookie));
1247
+ parsedCookies.forEach(([origin, cookies]) => {
1248
+ this.store.set(origin, new Map(cookies.map((_a) => {
1249
+ var [token, _b] = _a, { expires } = _b, cookie = __rest(_b, ["expires"]);
1250
+ return [
1251
+ token,
1252
+ expires === undefined ? cookie : Object.assign(Object.assign({}, cookie), { expires: new Date(expires) })
1253
+ ];
1254
+ })));
1239
1255
  });
1240
1256
  }
1241
1257
  catch (error) {
@@ -1302,7 +1318,7 @@ function getAllCookies() {
1302
1318
  */
1303
1319
  function getRequestCookies(request) {
1304
1320
  /**
1305
- * @note No cookies persist on the document in NodeJS: no document.
1321
+ * @note No cookies persist on the document in Node.js: no document.
1306
1322
  */
1307
1323
  if (typeof location === 'undefined') {
1308
1324
  return {};
@@ -1326,7 +1342,7 @@ function getRequestCookies(request) {
1326
1342
  function setRequestCookies(request) {
1327
1343
  var _a;
1328
1344
  lib$1.store.hydrate();
1329
- request.cookies = Object.assign(Object.assign({}, getRequestCookies(request)), Object.fromEntries(Array.from((_a = lib$1.store.get(Object.assign(Object.assign({}, request), { url: request.url.toString() }))) === null || _a === void 0 ? void 0 : _a.entries()).map(([name, { value }]) => [name, value])));
1345
+ request.cookies = Object.assign(Object.assign({}, getRequestCookies(request)), Array.from((_a = lib$1.store.get(Object.assign(Object.assign({}, request), { url: request.url.toString() }))) === null || _a === void 0 ? void 0 : _a.entries()).reduce((cookies, [name, { value }]) => Object.assign(cookies, { [name]: value }), {}));
1330
1346
  request.headers.set('cookie', Object.entries(request.cookies)
1331
1347
  .map(([name, value]) => `${name}=${value}`)
1332
1348
  .join('; '));
@@ -1362,7 +1378,7 @@ function parseWorkerRequest(rawRequest) {
1362
1378
  destination: rawRequest.destination,
1363
1379
  body: pruneGetRequestBody(rawRequest),
1364
1380
  bodyUsed: rawRequest.bodyUsed,
1365
- headers: new Headers(rawRequest.headers),
1381
+ headers: new lib$2.Headers(rawRequest.headers),
1366
1382
  };
1367
1383
  // Set document cookies on the request.
1368
1384
  setRequestCookies(request);
@@ -1402,7 +1418,7 @@ const createRequestListener = (context, options) => {
1402
1418
  return channel.send({ type: 'MOCK_NOT_FOUND' });
1403
1419
  }
1404
1420
  readResponseCookies(request, response);
1405
- const responseWithSerializedHeaders = Object.assign(Object.assign({}, response), { headers: headersToList(response.headers) });
1421
+ const responseWithSerializedHeaders = Object.assign(Object.assign({}, response), { headers: lib$2.headersToList(response.headers) });
1406
1422
  if (!options.quiet) {
1407
1423
  setTimeout(() => {
1408
1424
  handler.log(publicRequest, responseWithSerializedHeaders, handler, parsedRequest);
@@ -1450,8 +1466,8 @@ function requestIntegrityCheck(context, serviceWorker) {
1450
1466
  const { payload: actualChecksum } = yield context.events.once('INTEGRITY_CHECK_RESPONSE');
1451
1467
  // Compare the response from the Service Worker and the
1452
1468
  // global variable set by webpack upon build.
1453
- if (actualChecksum !== "f7d0ed371e596d181f62c6f68c4b7baf") {
1454
- throw new Error(`Currently active Service Worker (${actualChecksum}) is behind the latest published one (${"f7d0ed371e596d181f62c6f68c4b7baf"}).`);
1469
+ if (actualChecksum !== "82ef9b96d8393b6da34527d1d6e19187") {
1470
+ throw new Error(`Currently active Service Worker (${actualChecksum}) is behind the latest published one (${"82ef9b96d8393b6da34527d1d6e19187"}).`);
1455
1471
  }
1456
1472
  return serviceWorker;
1457
1473
  });
@@ -1540,7 +1556,8 @@ const createStart = (context) => {
1540
1556
  const instance = yield getWorkerInstance(resolvedOptions.serviceWorker.url, resolvedOptions.serviceWorker.options, resolvedOptions.findWorker);
1541
1557
  const [worker, registration] = instance;
1542
1558
  if (!worker) {
1543
- const missingWorkerMessage = (options === null || options === void 0 ? void 0 : options.findWorker) ? `[MSW] Failed to locate the Service Worker registration using a custom "findWorker" predicate.
1559
+ const missingWorkerMessage = (options === null || options === void 0 ? void 0 : options.findWorker)
1560
+ ? `[MSW] Failed to locate the Service Worker registration using a custom "findWorker" predicate.
1544
1561
 
1545
1562
  Please ensure that the custom predicate properly locates the Service Worker registration at "${resolvedOptions.serviceWorker.url}".
1546
1563
  More details: https://mswjs.io/docs/api/setup-worker/start#findworker
@@ -1704,9 +1721,9 @@ function setupWorker(...requestHandlers) {
1704
1721
  },
1705
1722
  },
1706
1723
  };
1707
- // Error when attempting to run this function in a NodeJS environment.
1724
+ // Error when attempting to run this function in a Node.js environment.
1708
1725
  if (isNodeProcess()) {
1709
- throw new Error('[MSW] Failed to execute `setupWorker` in a non-browser environment. Consider using `setupServer` for NodeJS environment instead.');
1726
+ throw new Error('[MSW] Failed to execute `setupWorker` in a non-browser environment. Consider using `setupServer` for Node.js environment instead.');
1710
1727
  }
1711
1728
  return {
1712
1729
  start: createStart(context),
package/lib/esm/index2.js CHANGED
@@ -1,3 +1,3 @@
1
- export { d as delay, f as fetch, b as json, a as set, s as status } from './fetch-deps.js';
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 = 'f7d0ed371e596d181f62c6f68c4b7baf'
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
- const clonedResponse = response.clone()
119
-
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: clonedResponse.body === null ? null : await clonedResponse.text(),
129
- headers: serializeHeaders(clonedResponse.headers),
130
- redirected: clonedResponse.redirected,
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
@@ -1,5 +1,5 @@
1
- import { R as RequestHandler, h as getUrlByMask, m as matchRequestUrl, g as getPublicUrlFromRequest, i as prepareRequest, j as prepareResponse, k as getTimestamp, l as getStatusCodeColor } from './RequestHandler-deps.js';
2
- import { a as set, s as status, b as json, d as delay, f as fetch } from './fetch-deps.js';
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
  /**