msw 2.2.11 → 2.2.13
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 +25 -19
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +25 -19
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/getResponse.js +2 -2
- package/lib/core/getResponse.js.map +1 -1
- package/lib/core/getResponse.mjs +2 -2
- package/lib/core/getResponse.mjs.map +1 -1
- package/lib/iife/index.js +26 -25
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/package.json +2 -2
- package/src/core/getResponse.ts +2 -2
- package/src/core/handlers/GraphQLHandler.test.ts +4 -5
- package/src/core/handlers/HttpHandler.test.ts +5 -5
- package/src/core/utils/handleRequest.test.ts +14 -14
- package/lib/core/utils/internal/randomId.d.mts +0 -3
- package/lib/core/utils/internal/randomId.d.ts +0 -3
- package/lib/core/utils/internal/randomId.js +0 -27
- package/lib/core/utils/internal/randomId.js.map +0 -1
- package/lib/core/utils/internal/randomId.mjs +0 -7
- package/lib/core/utils/internal/randomId.mjs.map +0 -1
- package/src/core/utils/internal/randomId.ts +0 -3
package/lib/core/getResponse.js
CHANGED
|
@@ -21,12 +21,12 @@ __export(getResponse_exports, {
|
|
|
21
21
|
getResponse: () => getResponse
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(getResponse_exports);
|
|
24
|
+
var import_interceptors = require("@mswjs/interceptors");
|
|
24
25
|
var import_executeHandlers = require("./utils/executeHandlers.js");
|
|
25
|
-
var import_randomId = require("./utils/internal/randomId.js");
|
|
26
26
|
const getResponse = async (handlers, request) => {
|
|
27
27
|
const result = await (0, import_executeHandlers.executeHandlers)({
|
|
28
28
|
request,
|
|
29
|
-
requestId: (0,
|
|
29
|
+
requestId: (0, import_interceptors.createRequestId)(),
|
|
30
30
|
handlers
|
|
31
31
|
});
|
|
32
32
|
return result?.response;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/getResponse.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../src/core/getResponse.ts"],"sourcesContent":["import { createRequestId } from '@mswjs/interceptors'\nimport type { RequestHandler } from './handlers/RequestHandler'\nimport { executeHandlers } from './utils/executeHandlers'\n\n/**\n * Finds a response for the given request instance\n * in the array of request handlers.\n * @param handlers The array of request handlers.\n * @param request The `Request` instance.\n * @returns {Response} A mocked response, if any.\n */\nexport const getResponse = async (\n handlers: Array<RequestHandler>,\n request: Request,\n): Promise<Response | undefined> => {\n const result = await executeHandlers({\n request,\n requestId: createRequestId(),\n handlers,\n })\n\n return result?.response\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAgC;AAEhC,6BAAgC;AASzB,MAAM,cAAc,OACzB,UACA,YACkC;AAClC,QAAM,SAAS,UAAM,wCAAgB;AAAA,IACnC;AAAA,IACA,eAAW,qCAAgB;AAAA,IAC3B;AAAA,EACF,CAAC;AAED,SAAO,QAAQ;AACjB;","names":[]}
|
package/lib/core/getResponse.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { createRequestId } from "@mswjs/interceptors";
|
|
1
2
|
import { executeHandlers } from './utils/executeHandlers.mjs';
|
|
2
|
-
import { randomId } from './utils/internal/randomId.mjs';
|
|
3
3
|
const getResponse = async (handlers, request) => {
|
|
4
4
|
const result = await executeHandlers({
|
|
5
5
|
request,
|
|
6
|
-
requestId:
|
|
6
|
+
requestId: createRequestId(),
|
|
7
7
|
handlers
|
|
8
8
|
});
|
|
9
9
|
return result?.response;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/getResponse.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../src/core/getResponse.ts"],"sourcesContent":["import { createRequestId } from '@mswjs/interceptors'\nimport type { RequestHandler } from './handlers/RequestHandler'\nimport { executeHandlers } from './utils/executeHandlers'\n\n/**\n * Finds a response for the given request instance\n * in the array of request handlers.\n * @param handlers The array of request handlers.\n * @param request The `Request` instance.\n * @returns {Response} A mocked response, if any.\n */\nexport const getResponse = async (\n handlers: Array<RequestHandler>,\n request: Request,\n): Promise<Response | undefined> => {\n const result = await executeHandlers({\n request,\n requestId: createRequestId(),\n handlers,\n })\n\n return result?.response\n}\n"],"mappings":"AAAA,SAAS,uBAAuB;AAEhC,SAAS,uBAAuB;AASzB,MAAM,cAAc,OACzB,UACA,YACkC;AAClC,QAAM,SAAS,MAAM,gBAAgB;AAAA,IACnC;AAAA,IACA,WAAW,gBAAgB;AAAA,IAC3B;AAAA,EACF,CAAC;AAED,SAAO,QAAQ;AACjB;","names":[]}
|
package/lib/iife/index.js
CHANGED
|
@@ -1121,7 +1121,7 @@ var MockServiceWorker = (() => {
|
|
|
1121
1121
|
return stringToRegexp(path, keys, options);
|
|
1122
1122
|
}
|
|
1123
1123
|
|
|
1124
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
1124
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.26.14/node_modules/@mswjs/interceptors/lib/browser/chunk-UJZOJSMP.mjs
|
|
1125
1125
|
var encoder = new TextEncoder();
|
|
1126
1126
|
function encodeBuffer(text) {
|
|
1127
1127
|
return encoder.encode(text);
|
|
@@ -1147,6 +1147,9 @@ var MockServiceWorker = (() => {
|
|
|
1147
1147
|
return RESPONSE_STATUS_CODES_WITHOUT_BODY.has(status);
|
|
1148
1148
|
}
|
|
1149
1149
|
|
|
1150
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.26.14/node_modules/@mswjs/interceptors/lib/browser/chunk-HAGW22AN.mjs
|
|
1151
|
+
var IS_PATCHED_MODULE = Symbol("isPatchedModule");
|
|
1152
|
+
|
|
1150
1153
|
// node_modules/.pnpm/is-node-process@1.2.0/node_modules/is-node-process/lib/index.mjs
|
|
1151
1154
|
function isNodeProcess() {
|
|
1152
1155
|
if (typeof navigator !== "undefined" && navigator.product === "ReactNative") {
|
|
@@ -1434,8 +1437,8 @@ var MockServiceWorker = (() => {
|
|
|
1434
1437
|
return message3.toString();
|
|
1435
1438
|
}
|
|
1436
1439
|
|
|
1437
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
1438
|
-
var
|
|
1440
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.26.14/node_modules/@mswjs/interceptors/lib/browser/chunk-QED3Q6Z2.mjs
|
|
1441
|
+
var INTERNAL_REQUEST_ID_HEADER_NAME = "x-interceptors-internal-request-id";
|
|
1439
1442
|
function getGlobalSymbol(symbol) {
|
|
1440
1443
|
return (
|
|
1441
1444
|
// @ts-ignore https://github.com/Microsoft/TypeScript/issues/24587
|
|
@@ -1578,8 +1581,11 @@ var MockServiceWorker = (() => {
|
|
|
1578
1581
|
this.logger.info("cleared global instance!", this.symbol.description);
|
|
1579
1582
|
}
|
|
1580
1583
|
};
|
|
1584
|
+
function createRequestId() {
|
|
1585
|
+
return Math.random().toString(16).slice(2);
|
|
1586
|
+
}
|
|
1581
1587
|
|
|
1582
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
1588
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.26.14/node_modules/@mswjs/interceptors/lib/browser/index.mjs
|
|
1583
1589
|
var BatchInterceptor = class extends Interceptor {
|
|
1584
1590
|
constructor(options) {
|
|
1585
1591
|
BatchInterceptor.symbol = Symbol(options.name);
|
|
@@ -5755,16 +5761,11 @@ Read more: https://mswjs.io/docs/getting-started/mocks`;
|
|
|
5755
5761
|
return transformedResponse;
|
|
5756
5762
|
}
|
|
5757
5763
|
|
|
5758
|
-
// src/core/utils/internal/randomId.ts
|
|
5759
|
-
function randomId() {
|
|
5760
|
-
return Math.random().toString(16).slice(2);
|
|
5761
|
-
}
|
|
5762
|
-
|
|
5763
5764
|
// src/core/getResponse.ts
|
|
5764
5765
|
var getResponse = async (handlers, request) => {
|
|
5765
5766
|
const result = await executeHandlers({
|
|
5766
5767
|
request,
|
|
5767
|
-
requestId:
|
|
5768
|
+
requestId: createRequestId(),
|
|
5768
5769
|
handlers
|
|
5769
5770
|
});
|
|
5770
5771
|
return result?.response;
|
|
@@ -6487,14 +6488,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
6487
6488
|
}
|
|
6488
6489
|
};
|
|
6489
6490
|
|
|
6490
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
6491
|
-
function uuidv4() {
|
|
6492
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
|
6493
|
-
const r = Math.random() * 16 | 0;
|
|
6494
|
-
const v = c == "x" ? r : r & 3 | 8;
|
|
6495
|
-
return v.toString(16);
|
|
6496
|
-
});
|
|
6497
|
-
}
|
|
6491
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.26.14/node_modules/@mswjs/interceptors/lib/browser/chunk-OUWBQF3Z.mjs
|
|
6498
6492
|
var RequestController = class {
|
|
6499
6493
|
constructor(request) {
|
|
6500
6494
|
this.request = request;
|
|
@@ -6532,7 +6526,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
6532
6526
|
}
|
|
6533
6527
|
}
|
|
6534
6528
|
|
|
6535
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
6529
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.26.14/node_modules/@mswjs/interceptors/lib/browser/chunk-3FNUI33J.mjs
|
|
6536
6530
|
function isPropertyAccessible2(obj, key) {
|
|
6537
6531
|
try {
|
|
6538
6532
|
obj[key];
|
|
@@ -6556,7 +6550,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
6556
6550
|
checkEnvironment() {
|
|
6557
6551
|
return typeof globalThis !== "undefined" && typeof globalThis.fetch !== "undefined";
|
|
6558
6552
|
}
|
|
6559
|
-
setup() {
|
|
6553
|
+
async setup() {
|
|
6560
6554
|
const pureFetch = globalThis.fetch;
|
|
6561
6555
|
invariant(
|
|
6562
6556
|
!pureFetch[IS_PATCHED_MODULE],
|
|
@@ -6564,7 +6558,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
6564
6558
|
);
|
|
6565
6559
|
globalThis.fetch = async (input, init) => {
|
|
6566
6560
|
var _a2;
|
|
6567
|
-
const requestId =
|
|
6561
|
+
const requestId = createRequestId();
|
|
6568
6562
|
const resolvedInput = typeof input === "string" && typeof location !== "undefined" && !canParseUrl(input) ? new URL(input, location.origin) : input;
|
|
6569
6563
|
const request = new Request(resolvedInput, init);
|
|
6570
6564
|
this.logger.info("[%s] %s", request.method, request.url);
|
|
@@ -6679,7 +6673,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
6679
6673
|
});
|
|
6680
6674
|
}
|
|
6681
6675
|
|
|
6682
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
6676
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.26.14/node_modules/@mswjs/interceptors/lib/browser/chunk-VYFS2IF2.mjs
|
|
6683
6677
|
function concatArrayBuffer(left, right) {
|
|
6684
6678
|
const result = new Uint8Array(left.byteLength + right.byteLength);
|
|
6685
6679
|
result.set(left, 0);
|
|
@@ -6873,7 +6867,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
6873
6867
|
this.method = "GET";
|
|
6874
6868
|
this.url = null;
|
|
6875
6869
|
this.events = /* @__PURE__ */ new Map();
|
|
6876
|
-
this.requestId =
|
|
6870
|
+
this.requestId = createRequestId();
|
|
6877
6871
|
this.requestHeaders = new Headers();
|
|
6878
6872
|
this.responseBuffer = new Uint8Array();
|
|
6879
6873
|
this.request = createProxy(initialRequest, {
|
|
@@ -6955,7 +6949,10 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
6955
6949
|
this.request.readyState
|
|
6956
6950
|
);
|
|
6957
6951
|
if (IS_NODE2) {
|
|
6958
|
-
this.request.setRequestHeader(
|
|
6952
|
+
this.request.setRequestHeader(
|
|
6953
|
+
INTERNAL_REQUEST_ID_HEADER_NAME,
|
|
6954
|
+
this.requestId
|
|
6955
|
+
);
|
|
6959
6956
|
}
|
|
6960
6957
|
return invoke();
|
|
6961
6958
|
}
|
|
@@ -7278,7 +7275,11 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
7278
7275
|
const XMLHttpRequestProxy = new Proxy(globalThis.XMLHttpRequest, {
|
|
7279
7276
|
construct(target, args, newTarget) {
|
|
7280
7277
|
logger.info("constructed new XMLHttpRequest");
|
|
7281
|
-
const originalRequest = Reflect.construct(
|
|
7278
|
+
const originalRequest = Reflect.construct(
|
|
7279
|
+
target,
|
|
7280
|
+
args,
|
|
7281
|
+
newTarget
|
|
7282
|
+
);
|
|
7282
7283
|
const prototypeDescriptors = Object.getOwnPropertyDescriptors(
|
|
7283
7284
|
target.prototype
|
|
7284
7285
|
);
|