msw 1.3.2 → 2.0.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.
- package/README.md +45 -29
- package/browser/package.json +5 -0
- package/cli/init.js +3 -3
- package/config/constants.js +1 -2
- package/lib/browser/index.d.ts +104 -0
- package/lib/browser/index.js +752 -0
- package/lib/browser/index.mjs +734 -0
- package/lib/core/GraphQLHandler-b42ca96f.d.ts +74 -0
- package/lib/core/HttpResponse.d.ts +2 -0
- package/lib/core/HttpResponse.js +94 -0
- package/lib/core/HttpResponse.mjs +77 -0
- package/lib/core/RequestHandler-1a5dbdc7.d.ts +172 -0
- package/lib/core/SetupApi.d.ts +26 -0
- package/lib/core/SetupApi.js +83 -0
- package/lib/core/SetupApi.mjs +63 -0
- package/lib/core/bypass.d.ts +16 -0
- package/lib/core/bypass.js +36 -0
- package/lib/core/bypass.mjs +16 -0
- package/lib/core/delay.d.ts +18 -0
- package/lib/core/delay.js +92 -0
- package/lib/core/delay.mjs +72 -0
- package/lib/core/graphql.d.ts +109 -0
- package/lib/core/graphql.js +112 -0
- package/lib/core/graphql.mjs +96 -0
- package/lib/core/handlers/GraphQLHandler.d.ts +5 -0
- package/lib/core/handlers/GraphQLHandler.js +145 -0
- package/lib/core/handlers/GraphQLHandler.mjs +130 -0
- package/lib/core/handlers/HttpHandler.d.ts +62 -0
- package/lib/core/handlers/HttpHandler.js +149 -0
- package/lib/core/handlers/HttpHandler.mjs +133 -0
- package/lib/core/handlers/RequestHandler.d.ts +2 -0
- package/lib/core/handlers/RequestHandler.js +180 -0
- package/lib/core/handlers/RequestHandler.mjs +162 -0
- package/lib/core/http.d.ts +26 -0
- package/lib/core/http.js +39 -0
- package/lib/core/http.mjs +22 -0
- package/lib/core/http.spec.d.ts +2 -0
- package/lib/core/http.spec.js +15 -0
- package/lib/core/http.spec.mjs +14 -0
- package/lib/core/index.d.ts +18 -0
- package/lib/core/index.js +49 -0
- package/lib/core/index.mjs +28 -0
- package/lib/core/passthrough.d.ts +17 -0
- package/lib/core/passthrough.js +32 -0
- package/lib/core/passthrough.mjs +12 -0
- package/lib/core/sharedOptions.d.ts +66 -0
- package/lib/core/sharedOptions.js +16 -0
- package/lib/core/sharedOptions.mjs +0 -0
- package/lib/core/typeUtils.d.ts +7 -0
- package/lib/core/typeUtils.js +16 -0
- package/lib/core/typeUtils.mjs +0 -0
- package/lib/core/utils/HttpResponse/decorators.d.ts +12 -0
- package/lib/core/utils/HttpResponse/decorators.js +80 -0
- package/lib/core/utils/HttpResponse/decorators.mjs +52 -0
- package/lib/core/utils/getResponse.d.ts +2 -0
- package/lib/core/utils/getResponse.js +64 -0
- package/lib/core/utils/getResponse.mjs +44 -0
- package/lib/core/utils/handleRequest.d.ts +30 -0
- package/lib/core/utils/handleRequest.js +102 -0
- package/lib/core/utils/handleRequest.mjs +82 -0
- package/lib/core/utils/internal/Disposable.d.ts +7 -0
- package/lib/core/utils/internal/Disposable.js +53 -0
- package/lib/core/utils/internal/Disposable.mjs +33 -0
- package/lib/core/utils/internal/checkGlobals.d.ts +3 -0
- package/lib/core/utils/internal/checkGlobals.js +33 -0
- package/lib/core/utils/internal/checkGlobals.mjs +13 -0
- package/lib/core/utils/internal/devUtils.d.ts +19 -0
- package/lib/core/utils/internal/devUtils.js +40 -0
- package/lib/core/utils/internal/devUtils.mjs +20 -0
- package/lib/core/utils/internal/getCallFrame.d.ts +6 -0
- package/lib/core/utils/internal/getCallFrame.js +40 -0
- package/lib/core/utils/internal/getCallFrame.mjs +20 -0
- package/lib/core/utils/internal/isIterable.d.ts +6 -0
- package/lib/core/utils/internal/isIterable.js +29 -0
- package/lib/core/utils/internal/isIterable.mjs +9 -0
- package/lib/core/utils/internal/isObject.d.ts +6 -0
- package/lib/core/utils/internal/isObject.js +26 -0
- package/lib/core/utils/internal/isObject.mjs +6 -0
- package/lib/core/utils/internal/isStringEqual.d.ts +6 -0
- package/lib/core/utils/internal/isStringEqual.js +26 -0
- package/lib/core/utils/internal/isStringEqual.mjs +6 -0
- package/lib/core/utils/internal/jsonParse.d.ts +7 -0
- package/lib/core/utils/internal/jsonParse.js +30 -0
- package/lib/core/utils/internal/jsonParse.mjs +10 -0
- package/lib/core/utils/internal/mergeRight.d.ts +7 -0
- package/lib/core/utils/internal/mergeRight.js +39 -0
- package/lib/core/utils/internal/mergeRight.mjs +19 -0
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +5 -0
- package/lib/core/utils/internal/parseGraphQLRequest.js +184 -0
- package/lib/core/utils/internal/parseGraphQLRequest.mjs +165 -0
- package/lib/core/utils/internal/parseMultipartData.d.ts +10 -0
- package/lib/core/utils/internal/parseMultipartData.js +81 -0
- package/lib/core/utils/internal/parseMultipartData.mjs +61 -0
- package/lib/core/utils/internal/pipeEvents.d.ts +8 -0
- package/lib/core/utils/internal/pipeEvents.js +34 -0
- package/lib/core/utils/internal/pipeEvents.mjs +14 -0
- package/lib/core/utils/internal/requestHandlerUtils.d.ts +8 -0
- package/lib/core/utils/internal/requestHandlerUtils.js +36 -0
- package/lib/core/utils/internal/requestHandlerUtils.mjs +16 -0
- package/lib/core/utils/internal/toReadonlyArray.d.ts +6 -0
- package/lib/core/utils/internal/toReadonlyArray.js +28 -0
- package/lib/core/utils/internal/toReadonlyArray.mjs +8 -0
- package/lib/core/utils/internal/tryCatch.d.ts +3 -0
- package/lib/core/utils/internal/tryCatch.js +31 -0
- package/lib/core/utils/internal/tryCatch.mjs +11 -0
- package/lib/core/utils/internal/uuidv4.d.ts +3 -0
- package/lib/core/utils/internal/uuidv4.js +26 -0
- package/lib/core/utils/internal/uuidv4.mjs +6 -0
- package/lib/core/utils/logging/getStatusCodeColor.d.ts +11 -0
- package/lib/core/utils/logging/getStatusCodeColor.js +39 -0
- package/lib/core/utils/logging/getStatusCodeColor.mjs +19 -0
- package/lib/core/utils/logging/getTimestamp.d.ts +6 -0
- package/lib/core/utils/logging/getTimestamp.js +27 -0
- package/lib/core/utils/logging/getTimestamp.mjs +7 -0
- package/lib/core/utils/logging/serializeRequest.d.ts +12 -0
- package/lib/core/utils/logging/serializeRequest.js +55 -0
- package/lib/core/utils/logging/serializeRequest.mjs +35 -0
- package/lib/core/utils/logging/serializeResponse.d.ts +9 -0
- package/lib/core/utils/logging/serializeResponse.js +69 -0
- package/lib/core/utils/logging/serializeResponse.mjs +39 -0
- package/lib/core/utils/matching/matchRequestUrl.d.ts +19 -0
- package/lib/core/utils/matching/matchRequestUrl.js +50 -0
- package/lib/core/utils/matching/matchRequestUrl.mjs +30 -0
- package/lib/core/utils/matching/normalizePath.d.ts +12 -0
- package/lib/core/utils/matching/normalizePath.js +32 -0
- package/lib/core/utils/matching/normalizePath.mjs +12 -0
- package/lib/core/utils/request/getPublicUrlFromRequest.d.ts +7 -0
- package/lib/core/utils/request/getPublicUrlFromRequest.js +30 -0
- package/lib/core/utils/request/getPublicUrlFromRequest.mjs +10 -0
- package/lib/core/utils/request/getRequestCookies.d.ts +8 -0
- package/lib/core/utils/request/getRequestCookies.js +88 -0
- package/lib/core/utils/request/getRequestCookies.mjs +60 -0
- package/lib/core/utils/request/onUnhandledRequest.d.ts +12 -0
- package/lib/core/utils/request/onUnhandledRequest.js +193 -0
- package/lib/core/utils/request/onUnhandledRequest.mjs +165 -0
- package/lib/core/utils/request/readResponseCookies.d.ts +3 -0
- package/lib/core/utils/request/readResponseCookies.js +45 -0
- package/lib/core/utils/request/readResponseCookies.mjs +27 -0
- package/lib/core/utils/toResponseInit.d.ts +3 -0
- package/lib/core/utils/toResponseInit.js +30 -0
- package/lib/core/utils/toResponseInit.mjs +10 -0
- package/lib/core/utils/url/cleanUrl.d.ts +7 -0
- package/lib/core/utils/url/cleanUrl.js +31 -0
- package/lib/core/utils/url/cleanUrl.mjs +11 -0
- package/lib/core/utils/url/getAbsoluteUrl.d.ts +6 -0
- package/lib/core/utils/url/getAbsoluteUrl.js +37 -0
- package/lib/core/utils/url/getAbsoluteUrl.mjs +17 -0
- package/lib/core/utils/url/isAbsoluteUrl.d.ts +6 -0
- package/lib/core/utils/url/isAbsoluteUrl.js +26 -0
- package/lib/core/utils/url/isAbsoluteUrl.mjs +6 -0
- package/lib/iife/index.js +6204 -12360
- package/lib/mockServiceWorker.js +82 -93
- package/lib/native/index.d.ts +67 -7
- package/lib/native/index.js +74 -1500
- package/lib/native/index.mjs +69 -1514
- package/lib/node/index.d.ts +68 -9
- package/lib/node/index.js +77 -1508
- package/lib/node/index.mjs +71 -1521
- package/native/package.json +2 -1
- package/node/package.json +2 -1
- package/package.json +53 -23
- package/lib/SetupServerApi-1855d9c6.d.ts +0 -20
- package/lib/glossary-de6278a9.d.ts +0 -385
- package/lib/iife/index.js.map +0 -1
- package/lib/index.d.ts +0 -365
- package/lib/index.js +0 -2295
- package/lib/index.js.map +0 -1
- package/lib/node/index.js.map +0 -1
- package/lib/node/index.mjs.map +0 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import statuses from "@bundled-es-modules/statuses";
|
|
21
|
+
const { message } = statuses;
|
|
22
|
+
function normalizeResponseInit(init = {}) {
|
|
23
|
+
const status = (init == null ? void 0 : init.status) || 200;
|
|
24
|
+
const statusText = (init == null ? void 0 : init.statusText) || message[status] || "";
|
|
25
|
+
const headers = new Headers(init == null ? void 0 : init.headers);
|
|
26
|
+
return __spreadProps(__spreadValues({}, init), {
|
|
27
|
+
headers,
|
|
28
|
+
status,
|
|
29
|
+
statusText
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function decorateResponse(response, init) {
|
|
33
|
+
var _a;
|
|
34
|
+
if (init.type) {
|
|
35
|
+
Object.defineProperty(response, "type", {
|
|
36
|
+
value: init.type,
|
|
37
|
+
enumerable: true,
|
|
38
|
+
writable: false
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
if (typeof document !== "undefined") {
|
|
42
|
+
const responseCookies = ((_a = init.headers.get("Set-Cookie")) == null ? void 0 : _a.split(",")) || [];
|
|
43
|
+
for (const cookieString of responseCookies) {
|
|
44
|
+
document.cookie = cookieString;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return response;
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
decorateResponse,
|
|
51
|
+
normalizeResponseInit
|
|
52
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var __async = (__this, __arguments, generator) => {
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
var fulfilled = (value) => {
|
|
22
|
+
try {
|
|
23
|
+
step(generator.next(value));
|
|
24
|
+
} catch (e) {
|
|
25
|
+
reject(e);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var rejected = (value) => {
|
|
29
|
+
try {
|
|
30
|
+
step(generator.throw(value));
|
|
31
|
+
} catch (e) {
|
|
32
|
+
reject(e);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
36
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
var getResponse_exports = {};
|
|
40
|
+
__export(getResponse_exports, {
|
|
41
|
+
getResponse: () => getResponse
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(getResponse_exports);
|
|
44
|
+
const getResponse = (request, handlers, resolutionContext) => __async(void 0, null, function* () {
|
|
45
|
+
let matchingHandler = null;
|
|
46
|
+
let result = null;
|
|
47
|
+
for (const handler of handlers) {
|
|
48
|
+
result = yield handler.run({ request, resolutionContext });
|
|
49
|
+
if (result !== null) {
|
|
50
|
+
matchingHandler = handler;
|
|
51
|
+
}
|
|
52
|
+
if (result == null ? void 0 : result.response) {
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (matchingHandler) {
|
|
57
|
+
return {
|
|
58
|
+
handler: matchingHandler,
|
|
59
|
+
parsedResult: result == null ? void 0 : result.parsedResult,
|
|
60
|
+
response: result == null ? void 0 : result.response
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
const getResponse = (request, handlers, resolutionContext) => __async(void 0, null, function* () {
|
|
22
|
+
let matchingHandler = null;
|
|
23
|
+
let result = null;
|
|
24
|
+
for (const handler of handlers) {
|
|
25
|
+
result = yield handler.run({ request, resolutionContext });
|
|
26
|
+
if (result !== null) {
|
|
27
|
+
matchingHandler = handler;
|
|
28
|
+
}
|
|
29
|
+
if (result == null ? void 0 : result.response) {
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (matchingHandler) {
|
|
34
|
+
return {
|
|
35
|
+
handler: matchingHandler,
|
|
36
|
+
parsedResult: result == null ? void 0 : result.parsedResult,
|
|
37
|
+
response: result == null ? void 0 : result.response
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
});
|
|
42
|
+
export {
|
|
43
|
+
getResponse
|
|
44
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Emitter } from 'strict-event-emitter';
|
|
2
|
+
import { h as ResponseLookupResult, R as RequestHandler } from '../RequestHandler-1a5dbdc7.js';
|
|
3
|
+
import { SharedOptions, LifeCycleEventsMap } from '../sharedOptions.js';
|
|
4
|
+
import { RequiredDeep } from '../typeUtils.js';
|
|
5
|
+
import './request/onUnhandledRequest.js';
|
|
6
|
+
|
|
7
|
+
interface HandleRequestOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Options for the response resolution process.
|
|
10
|
+
*/
|
|
11
|
+
resolutionContext?: {
|
|
12
|
+
baseUrl?: string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Transforms a `MockedResponse` instance returned from a handler
|
|
16
|
+
* to a response instance supported by the lower tooling (i.e. interceptors).
|
|
17
|
+
*/
|
|
18
|
+
transformResponse?(response: Response): Response;
|
|
19
|
+
/**
|
|
20
|
+
* Invoked whenever a request is performed as-is.
|
|
21
|
+
*/
|
|
22
|
+
onPassthroughResponse?(request: Request): void;
|
|
23
|
+
/**
|
|
24
|
+
* Invoked when the mocked response is ready to be sent.
|
|
25
|
+
*/
|
|
26
|
+
onMockedResponse?(response: Response, handler: RequiredDeep<ResponseLookupResult>): void;
|
|
27
|
+
}
|
|
28
|
+
declare function handleRequest(request: Request, requestId: string, handlers: Array<RequestHandler>, options: RequiredDeep<SharedOptions>, emitter: Emitter<LifeCycleEventsMap>, handleRequestOptions?: HandleRequestOptions): Promise<Response | undefined>;
|
|
29
|
+
|
|
30
|
+
export { HandleRequestOptions, handleRequest };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var __async = (__this, __arguments, generator) => {
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
var fulfilled = (value) => {
|
|
22
|
+
try {
|
|
23
|
+
step(generator.next(value));
|
|
24
|
+
} catch (e) {
|
|
25
|
+
reject(e);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var rejected = (value) => {
|
|
29
|
+
try {
|
|
30
|
+
step(generator.throw(value));
|
|
31
|
+
} catch (e) {
|
|
32
|
+
reject(e);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
36
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
var handleRequest_exports = {};
|
|
40
|
+
__export(handleRequest_exports, {
|
|
41
|
+
handleRequest: () => handleRequest
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(handleRequest_exports);
|
|
44
|
+
var import_until = require("@open-draft/until");
|
|
45
|
+
var import_getResponse = require("./getResponse.js");
|
|
46
|
+
var import_onUnhandledRequest = require("./request/onUnhandledRequest.js");
|
|
47
|
+
var import_readResponseCookies = require("./request/readResponseCookies.js");
|
|
48
|
+
function handleRequest(request, requestId, handlers, options, emitter, handleRequestOptions) {
|
|
49
|
+
return __async(this, null, function* () {
|
|
50
|
+
var _a, _b, _c, _d, _e, _f;
|
|
51
|
+
emitter.emit("request:start", { request, requestId });
|
|
52
|
+
if (request.headers.get("x-msw-intention") === "bypass") {
|
|
53
|
+
emitter.emit("request:end", { request, requestId });
|
|
54
|
+
(_a = handleRequestOptions == null ? void 0 : handleRequestOptions.onPassthroughResponse) == null ? void 0 : _a.call(handleRequestOptions, request);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const lookupResult = yield (0, import_until.until)(() => {
|
|
58
|
+
return (0, import_getResponse.getResponse)(
|
|
59
|
+
request,
|
|
60
|
+
handlers,
|
|
61
|
+
handleRequestOptions == null ? void 0 : handleRequestOptions.resolutionContext
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
if (lookupResult.error) {
|
|
65
|
+
emitter.emit("unhandledException", {
|
|
66
|
+
error: lookupResult.error,
|
|
67
|
+
request,
|
|
68
|
+
requestId
|
|
69
|
+
});
|
|
70
|
+
throw lookupResult.error;
|
|
71
|
+
}
|
|
72
|
+
if (!lookupResult.data) {
|
|
73
|
+
yield (0, import_onUnhandledRequest.onUnhandledRequest)(request, handlers, options.onUnhandledRequest);
|
|
74
|
+
emitter.emit("request:unhandled", { request, requestId });
|
|
75
|
+
emitter.emit("request:end", { request, requestId });
|
|
76
|
+
(_b = handleRequestOptions == null ? void 0 : handleRequestOptions.onPassthroughResponse) == null ? void 0 : _b.call(handleRequestOptions, request);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const { response } = lookupResult.data;
|
|
80
|
+
if (!response) {
|
|
81
|
+
emitter.emit("request:end", { request, requestId });
|
|
82
|
+
(_c = handleRequestOptions == null ? void 0 : handleRequestOptions.onPassthroughResponse) == null ? void 0 : _c.call(handleRequestOptions, request);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (response.status === 302 && response.headers.get("x-msw-intention") === "passthrough") {
|
|
86
|
+
emitter.emit("request:end", { request, requestId });
|
|
87
|
+
(_d = handleRequestOptions == null ? void 0 : handleRequestOptions.onPassthroughResponse) == null ? void 0 : _d.call(handleRequestOptions, request);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
(0, import_readResponseCookies.readResponseCookies)(request, response);
|
|
91
|
+
emitter.emit("request:match", { request, requestId });
|
|
92
|
+
const requiredLookupResult = lookupResult.data;
|
|
93
|
+
const transformedResponse = ((_e = handleRequestOptions == null ? void 0 : handleRequestOptions.transformResponse) == null ? void 0 : _e.call(handleRequestOptions, response)) || response;
|
|
94
|
+
(_f = handleRequestOptions == null ? void 0 : handleRequestOptions.onMockedResponse) == null ? void 0 : _f.call(
|
|
95
|
+
handleRequestOptions,
|
|
96
|
+
transformedResponse,
|
|
97
|
+
requiredLookupResult
|
|
98
|
+
);
|
|
99
|
+
emitter.emit("request:end", { request, requestId });
|
|
100
|
+
return transformedResponse;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
import { until } from "@open-draft/until";
|
|
22
|
+
import { getResponse } from './getResponse.mjs';
|
|
23
|
+
import { onUnhandledRequest } from './request/onUnhandledRequest.mjs';
|
|
24
|
+
import { readResponseCookies } from './request/readResponseCookies.mjs';
|
|
25
|
+
function handleRequest(request, requestId, handlers, options, emitter, handleRequestOptions) {
|
|
26
|
+
return __async(this, null, function* () {
|
|
27
|
+
var _a, _b, _c, _d, _e, _f;
|
|
28
|
+
emitter.emit("request:start", { request, requestId });
|
|
29
|
+
if (request.headers.get("x-msw-intention") === "bypass") {
|
|
30
|
+
emitter.emit("request:end", { request, requestId });
|
|
31
|
+
(_a = handleRequestOptions == null ? void 0 : handleRequestOptions.onPassthroughResponse) == null ? void 0 : _a.call(handleRequestOptions, request);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const lookupResult = yield until(() => {
|
|
35
|
+
return getResponse(
|
|
36
|
+
request,
|
|
37
|
+
handlers,
|
|
38
|
+
handleRequestOptions == null ? void 0 : handleRequestOptions.resolutionContext
|
|
39
|
+
);
|
|
40
|
+
});
|
|
41
|
+
if (lookupResult.error) {
|
|
42
|
+
emitter.emit("unhandledException", {
|
|
43
|
+
error: lookupResult.error,
|
|
44
|
+
request,
|
|
45
|
+
requestId
|
|
46
|
+
});
|
|
47
|
+
throw lookupResult.error;
|
|
48
|
+
}
|
|
49
|
+
if (!lookupResult.data) {
|
|
50
|
+
yield onUnhandledRequest(request, handlers, options.onUnhandledRequest);
|
|
51
|
+
emitter.emit("request:unhandled", { request, requestId });
|
|
52
|
+
emitter.emit("request:end", { request, requestId });
|
|
53
|
+
(_b = handleRequestOptions == null ? void 0 : handleRequestOptions.onPassthroughResponse) == null ? void 0 : _b.call(handleRequestOptions, request);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const { response } = lookupResult.data;
|
|
57
|
+
if (!response) {
|
|
58
|
+
emitter.emit("request:end", { request, requestId });
|
|
59
|
+
(_c = handleRequestOptions == null ? void 0 : handleRequestOptions.onPassthroughResponse) == null ? void 0 : _c.call(handleRequestOptions, request);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (response.status === 302 && response.headers.get("x-msw-intention") === "passthrough") {
|
|
63
|
+
emitter.emit("request:end", { request, requestId });
|
|
64
|
+
(_d = handleRequestOptions == null ? void 0 : handleRequestOptions.onPassthroughResponse) == null ? void 0 : _d.call(handleRequestOptions, request);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
readResponseCookies(request, response);
|
|
68
|
+
emitter.emit("request:match", { request, requestId });
|
|
69
|
+
const requiredLookupResult = lookupResult.data;
|
|
70
|
+
const transformedResponse = ((_e = handleRequestOptions == null ? void 0 : handleRequestOptions.transformResponse) == null ? void 0 : _e.call(handleRequestOptions, response)) || response;
|
|
71
|
+
(_f = handleRequestOptions == null ? void 0 : handleRequestOptions.onMockedResponse) == null ? void 0 : _f.call(
|
|
72
|
+
handleRequestOptions,
|
|
73
|
+
transformedResponse,
|
|
74
|
+
requiredLookupResult
|
|
75
|
+
);
|
|
76
|
+
emitter.emit("request:end", { request, requestId });
|
|
77
|
+
return transformedResponse;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
export {
|
|
81
|
+
handleRequest
|
|
82
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var __async = (__this, __arguments, generator) => {
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
var fulfilled = (value) => {
|
|
22
|
+
try {
|
|
23
|
+
step(generator.next(value));
|
|
24
|
+
} catch (e) {
|
|
25
|
+
reject(e);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var rejected = (value) => {
|
|
29
|
+
try {
|
|
30
|
+
step(generator.throw(value));
|
|
31
|
+
} catch (e) {
|
|
32
|
+
reject(e);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
36
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
var Disposable_exports = {};
|
|
40
|
+
__export(Disposable_exports, {
|
|
41
|
+
Disposable: () => Disposable
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(Disposable_exports);
|
|
44
|
+
class Disposable {
|
|
45
|
+
constructor() {
|
|
46
|
+
this.subscriptions = [];
|
|
47
|
+
}
|
|
48
|
+
dispose() {
|
|
49
|
+
return __async(this, null, function* () {
|
|
50
|
+
yield Promise.all(this.subscriptions.map((subscription) => subscription()));
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
class Disposable {
|
|
22
|
+
constructor() {
|
|
23
|
+
this.subscriptions = [];
|
|
24
|
+
}
|
|
25
|
+
dispose() {
|
|
26
|
+
return __async(this, null, function* () {
|
|
27
|
+
yield Promise.all(this.subscriptions.map((subscription) => subscription()));
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
Disposable
|
|
33
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var checkGlobals_exports = {};
|
|
20
|
+
__export(checkGlobals_exports, {
|
|
21
|
+
checkGlobals: () => checkGlobals
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(checkGlobals_exports);
|
|
24
|
+
var import_outvariant = require("outvariant");
|
|
25
|
+
var import_devUtils = require("./devUtils.js");
|
|
26
|
+
function checkGlobals() {
|
|
27
|
+
(0, import_outvariant.invariant)(
|
|
28
|
+
typeof URL !== "undefined",
|
|
29
|
+
import_devUtils.devUtils.formatMessage(
|
|
30
|
+
`Global "URL" class is not defined. This likely means that you're running MSW in an environment that doesn't support all Node.js standard API (e.g. React Native). If that's the case, please use an appropriate polyfill for the "URL" class, like "react-native-url-polyfill".`
|
|
31
|
+
)
|
|
32
|
+
);
|
|
33
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { invariant } from "outvariant";
|
|
2
|
+
import { devUtils } from './devUtils.mjs';
|
|
3
|
+
function checkGlobals() {
|
|
4
|
+
invariant(
|
|
5
|
+
typeof URL !== "undefined",
|
|
6
|
+
devUtils.formatMessage(
|
|
7
|
+
`Global "URL" class is not defined. This likely means that you're running MSW in an environment that doesn't support all Node.js standard API (e.g. React Native). If that's the case, please use an appropriate polyfill for the "URL" class, like "react-native-url-polyfill".`
|
|
8
|
+
)
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
checkGlobals
|
|
13
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats a given message by appending the library's prefix string.
|
|
3
|
+
*/
|
|
4
|
+
declare function formatMessage(message: string, ...positionals: any[]): string;
|
|
5
|
+
/**
|
|
6
|
+
* Prints a library-specific warning.
|
|
7
|
+
*/
|
|
8
|
+
declare function warn(message: string, ...positionals: any[]): void;
|
|
9
|
+
/**
|
|
10
|
+
* Prints a library-specific error.
|
|
11
|
+
*/
|
|
12
|
+
declare function error(message: string, ...positionals: any[]): void;
|
|
13
|
+
declare const devUtils: {
|
|
14
|
+
formatMessage: typeof formatMessage;
|
|
15
|
+
warn: typeof warn;
|
|
16
|
+
error: typeof error;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { devUtils };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var devUtils_exports = {};
|
|
20
|
+
__export(devUtils_exports, {
|
|
21
|
+
devUtils: () => devUtils
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(devUtils_exports);
|
|
24
|
+
var import_outvariant = require("outvariant");
|
|
25
|
+
const LIBRARY_PREFIX = "[MSW]";
|
|
26
|
+
function formatMessage(message, ...positionals) {
|
|
27
|
+
const interpolatedMessage = (0, import_outvariant.format)(message, ...positionals);
|
|
28
|
+
return `${LIBRARY_PREFIX} ${interpolatedMessage}`;
|
|
29
|
+
}
|
|
30
|
+
function warn(message, ...positionals) {
|
|
31
|
+
console.warn(formatMessage(message, ...positionals));
|
|
32
|
+
}
|
|
33
|
+
function error(message, ...positionals) {
|
|
34
|
+
console.error(formatMessage(message, ...positionals));
|
|
35
|
+
}
|
|
36
|
+
const devUtils = {
|
|
37
|
+
formatMessage,
|
|
38
|
+
warn,
|
|
39
|
+
error
|
|
40
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { format } from "outvariant";
|
|
2
|
+
const LIBRARY_PREFIX = "[MSW]";
|
|
3
|
+
function formatMessage(message, ...positionals) {
|
|
4
|
+
const interpolatedMessage = format(message, ...positionals);
|
|
5
|
+
return `${LIBRARY_PREFIX} ${interpolatedMessage}`;
|
|
6
|
+
}
|
|
7
|
+
function warn(message, ...positionals) {
|
|
8
|
+
console.warn(formatMessage(message, ...positionals));
|
|
9
|
+
}
|
|
10
|
+
function error(message, ...positionals) {
|
|
11
|
+
console.error(formatMessage(message, ...positionals));
|
|
12
|
+
}
|
|
13
|
+
const devUtils = {
|
|
14
|
+
formatMessage,
|
|
15
|
+
warn,
|
|
16
|
+
error
|
|
17
|
+
};
|
|
18
|
+
export {
|
|
19
|
+
devUtils
|
|
20
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var getCallFrame_exports = {};
|
|
20
|
+
__export(getCallFrame_exports, {
|
|
21
|
+
getCallFrame: () => getCallFrame
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(getCallFrame_exports);
|
|
24
|
+
const SOURCE_FRAME = /[\/\\]msw[\/\\]src[\/\\](.+)/;
|
|
25
|
+
const BUILD_FRAME = /(node_modules)?[\/\\]lib[\/\\](core|browser|node|native|iife)[\/\\]|^[^\/\\]*$/;
|
|
26
|
+
function getCallFrame(error) {
|
|
27
|
+
const stack = error.stack;
|
|
28
|
+
if (!stack) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const frames = stack.split("\n").slice(1);
|
|
32
|
+
const declarationFrame = frames.find((frame) => {
|
|
33
|
+
return !(SOURCE_FRAME.test(frame) || BUILD_FRAME.test(frame));
|
|
34
|
+
});
|
|
35
|
+
if (!declarationFrame) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const declarationPath = declarationFrame.replace(/\s*at [^()]*\(([^)]+)\)/, "$1").replace(/^@/, "");
|
|
39
|
+
return declarationPath;
|
|
40
|
+
}
|