msw 1.0.1 → 1.1.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/cli/init.js +0 -0
- package/config/scripts/postinstall.js +0 -0
- package/lib/{SetupServerApi-39df862c.d.ts → SetupServerApi-1855d9c6.d.ts} +1 -1
- package/lib/iife/index.js +1510 -1442
- package/lib/iife/index.js.map +1 -1
- package/lib/index.d.ts +19 -19
- package/lib/index.js +547 -345
- package/lib/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/lib/native/index.d.ts +1 -1
- package/lib/native/index.js +329 -248
- package/lib/native/index.mjs +328 -248
- package/lib/node/index.d.ts +3 -4
- package/lib/node/index.js +334 -249
- package/lib/node/index.js.map +1 -1
- package/lib/node/index.mjs +333 -249
- package/lib/node/index.mjs.map +1 -1
- package/package.json +32 -29
- package/CHANGELOG.md +0 -4
package/lib/native/index.mjs
CHANGED
|
@@ -1,26 +1,9 @@
|
|
|
1
1
|
var __create = Object.create;
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
9
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
-
var __spreadValues = (a, b) => {
|
|
13
|
-
for (var prop in b || (b = {}))
|
|
14
|
-
if (__hasOwnProp.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
if (__getOwnPropSymbols)
|
|
17
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
-
if (__propIsEnum.call(b, prop))
|
|
19
|
-
__defNormalProp(a, prop, b[prop]);
|
|
20
|
-
}
|
|
21
|
-
return a;
|
|
22
|
-
};
|
|
23
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
7
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
25
8
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
26
9
|
}) : x)(function(x) {
|
|
@@ -28,18 +11,6 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
28
11
|
return require.apply(this, arguments);
|
|
29
12
|
throw new Error('Dynamic require of "' + x + '" is not supported');
|
|
30
13
|
});
|
|
31
|
-
var __objRest = (source, exclude) => {
|
|
32
|
-
var target = {};
|
|
33
|
-
for (var prop in source)
|
|
34
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
35
|
-
target[prop] = source[prop];
|
|
36
|
-
if (source != null && __getOwnPropSymbols)
|
|
37
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
38
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
39
|
-
target[prop] = source[prop];
|
|
40
|
-
}
|
|
41
|
-
return target;
|
|
42
|
-
};
|
|
43
14
|
var __copyProps = (to, from, except, desc) => {
|
|
44
15
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
45
16
|
for (let key of __getOwnPropNames(from))
|
|
@@ -48,7 +19,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
48
19
|
}
|
|
49
20
|
return to;
|
|
50
21
|
};
|
|
51
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
+
mod
|
|
25
|
+
));
|
|
52
26
|
|
|
53
27
|
// src/native/index.ts
|
|
54
28
|
import { XMLHttpRequestInterceptor } from "@mswjs/interceptors/lib/interceptors/XMLHttpRequest";
|
|
@@ -117,7 +91,13 @@ var SetupApi = class {
|
|
|
117
91
|
}
|
|
118
92
|
validateHandlers(...handlers) {
|
|
119
93
|
for (const handler of handlers) {
|
|
120
|
-
invariant(
|
|
94
|
+
invariant(
|
|
95
|
+
!Array.isArray(handler),
|
|
96
|
+
devUtils.formatMessage(
|
|
97
|
+
'Failed to construct "%s" given an Array of request handlers. Make sure you spread the request handlers when calling the respective setup function.'
|
|
98
|
+
),
|
|
99
|
+
this.constructor.name
|
|
100
|
+
);
|
|
121
101
|
}
|
|
122
102
|
}
|
|
123
103
|
dispose() {
|
|
@@ -337,15 +317,23 @@ var MockedRequest = class extends IsomorphicRequest {
|
|
|
337
317
|
const requestCookiesString = this.headers.get("cookie");
|
|
338
318
|
const ownCookies = requestCookiesString ? cookieUtils2.parse(requestCookiesString) : {};
|
|
339
319
|
store.hydrate();
|
|
340
|
-
const cookiesFromStore = Array.from(
|
|
320
|
+
const cookiesFromStore = Array.from(
|
|
321
|
+
(_a = store.get({ ...this, url: this.url.href })) == null ? void 0 : _a.entries()
|
|
322
|
+
).reduce((cookies, [name, { value }]) => {
|
|
341
323
|
return Object.assign(cookies, { [name.trim()]: value });
|
|
342
324
|
}, {});
|
|
343
325
|
const cookiesFromDocument = getRequestCookies(this);
|
|
344
|
-
const forwardedCookies =
|
|
326
|
+
const forwardedCookies = {
|
|
327
|
+
...cookiesFromDocument,
|
|
328
|
+
...cookiesFromStore
|
|
329
|
+
};
|
|
345
330
|
for (const [name, value] of Object.entries(forwardedCookies)) {
|
|
346
331
|
this.headers.append("cookie", `${name}=${value}`);
|
|
347
332
|
}
|
|
348
|
-
return
|
|
333
|
+
return {
|
|
334
|
+
...forwardedCookies,
|
|
335
|
+
...ownCookies
|
|
336
|
+
};
|
|
349
337
|
}
|
|
350
338
|
};
|
|
351
339
|
|
|
@@ -407,7 +395,10 @@ import { parse as parse3 } from "graphql";
|
|
|
407
395
|
|
|
408
396
|
// src/utils/request/getPublicUrlFromRequest.ts
|
|
409
397
|
var getPublicUrlFromRequest = (request) => {
|
|
410
|
-
return request.referrer.startsWith(request.url.origin) ? request.url.pathname : new URL(
|
|
398
|
+
return request.referrer.startsWith(request.url.origin) ? request.url.pathname : new URL(
|
|
399
|
+
request.url.pathname,
|
|
400
|
+
`${request.url.protocol}//${request.url.host}`
|
|
401
|
+
).href;
|
|
411
402
|
};
|
|
412
403
|
|
|
413
404
|
// src/utils/internal/parseGraphQLRequest.ts
|
|
@@ -470,13 +461,19 @@ function getGraphQLInput(request) {
|
|
|
470
461
|
};
|
|
471
462
|
}
|
|
472
463
|
if ((_b = request.body) == null ? void 0 : _b.operations) {
|
|
473
|
-
const
|
|
474
|
-
const parsedOperations = jsonParse(
|
|
464
|
+
const { operations, map, ...files } = request.body;
|
|
465
|
+
const parsedOperations = jsonParse(
|
|
466
|
+
operations
|
|
467
|
+
) || {};
|
|
475
468
|
if (!parsedOperations.query) {
|
|
476
469
|
return null;
|
|
477
470
|
}
|
|
478
471
|
const parsedMap = jsonParse(map || "") || {};
|
|
479
|
-
const variables = parsedOperations.variables ? extractMultipartVariables(
|
|
472
|
+
const variables = parsedOperations.variables ? extractMultipartVariables(
|
|
473
|
+
parsedOperations.variables,
|
|
474
|
+
parsedMap,
|
|
475
|
+
files
|
|
476
|
+
) : {};
|
|
480
477
|
return {
|
|
481
478
|
query: parsedOperations.query,
|
|
482
479
|
variables
|
|
@@ -496,7 +493,14 @@ function parseGraphQLRequest(request) {
|
|
|
496
493
|
const parsedResult = parseQuery(query);
|
|
497
494
|
if (parsedResult instanceof Error) {
|
|
498
495
|
const requestPublicUrl = getPublicUrlFromRequest(request);
|
|
499
|
-
throw new Error(
|
|
496
|
+
throw new Error(
|
|
497
|
+
devUtils.formatMessage(
|
|
498
|
+
'Failed to intercept a GraphQL request to "%s %s": cannot parse query. See the error message from the parser below.\n\n%s',
|
|
499
|
+
request.method,
|
|
500
|
+
requestPublicUrl,
|
|
501
|
+
parsedResult.message
|
|
502
|
+
)
|
|
503
|
+
);
|
|
500
504
|
}
|
|
501
505
|
return {
|
|
502
506
|
operationType: parsedResult.operationType,
|
|
@@ -505,134 +509,71 @@ function parseGraphQLRequest(request) {
|
|
|
505
509
|
};
|
|
506
510
|
}
|
|
507
511
|
|
|
508
|
-
// node_modules/statuses/codes.json
|
|
509
|
-
var _00 = "Continue";
|
|
510
|
-
var _01 = "Switching Protocols";
|
|
511
|
-
var _02 = "Processing";
|
|
512
|
-
var _03 = "Early Hints";
|
|
513
|
-
var _002 = "OK";
|
|
514
|
-
var _012 = "Created";
|
|
515
|
-
var _022 = "Accepted";
|
|
516
|
-
var _032 = "Non-Authoritative Information";
|
|
517
|
-
var _04 = "No Content";
|
|
518
|
-
var _05 = "Reset Content";
|
|
519
|
-
var _06 = "Partial Content";
|
|
520
|
-
var _07 = "Multi-Status";
|
|
521
|
-
var _08 = "Already Reported";
|
|
522
|
-
var _26 = "IM Used";
|
|
523
|
-
var _003 = "Multiple Choices";
|
|
524
|
-
var _013 = "Moved Permanently";
|
|
525
|
-
var _023 = "Found";
|
|
526
|
-
var _033 = "See Other";
|
|
527
|
-
var _042 = "Not Modified";
|
|
528
|
-
var _052 = "Use Proxy";
|
|
529
|
-
var _072 = "Temporary Redirect";
|
|
530
|
-
var _082 = "Permanent Redirect";
|
|
531
|
-
var _004 = "Bad Request";
|
|
532
|
-
var _014 = "Unauthorized";
|
|
533
|
-
var _024 = "Payment Required";
|
|
534
|
-
var _034 = "Forbidden";
|
|
535
|
-
var _043 = "Not Found";
|
|
536
|
-
var _053 = "Method Not Allowed";
|
|
537
|
-
var _062 = "Not Acceptable";
|
|
538
|
-
var _073 = "Proxy Authentication Required";
|
|
539
|
-
var _083 = "Request Timeout";
|
|
540
|
-
var _09 = "Conflict";
|
|
541
|
-
var _10 = "Gone";
|
|
542
|
-
var _11 = "Length Required";
|
|
543
|
-
var _12 = "Precondition Failed";
|
|
544
|
-
var _13 = "Payload Too Large";
|
|
545
|
-
var _14 = "URI Too Long";
|
|
546
|
-
var _15 = "Unsupported Media Type";
|
|
547
|
-
var _16 = "Range Not Satisfiable";
|
|
548
|
-
var _17 = "Expectation Failed";
|
|
549
|
-
var _18 = "I'm a Teapot";
|
|
550
|
-
var _21 = "Misdirected Request";
|
|
551
|
-
var _22 = "Unprocessable Entity";
|
|
552
|
-
var _23 = "Locked";
|
|
553
|
-
var _24 = "Failed Dependency";
|
|
554
|
-
var _25 = "Too Early";
|
|
555
|
-
var _262 = "Upgrade Required";
|
|
556
|
-
var _28 = "Precondition Required";
|
|
557
|
-
var _29 = "Too Many Requests";
|
|
558
|
-
var _31 = "Request Header Fields Too Large";
|
|
559
|
-
var _51 = "Unavailable For Legal Reasons";
|
|
560
|
-
var _005 = "Internal Server Error";
|
|
561
|
-
var _015 = "Not Implemented";
|
|
562
|
-
var _025 = "Bad Gateway";
|
|
563
|
-
var _035 = "Service Unavailable";
|
|
564
|
-
var _044 = "Gateway Timeout";
|
|
565
|
-
var _054 = "HTTP Version Not Supported";
|
|
566
|
-
var _063 = "Variant Also Negotiates";
|
|
567
|
-
var _074 = "Insufficient Storage";
|
|
568
|
-
var _084 = "Loop Detected";
|
|
569
|
-
var _092 = "Bandwidth Limit Exceeded";
|
|
570
|
-
var _102 = "Not Extended";
|
|
571
|
-
var _112 = "Network Authentication Required";
|
|
512
|
+
// node_modules/.pnpm/statuses@2.0.1/node_modules/statuses/codes.json
|
|
572
513
|
var codes_default = {
|
|
573
|
-
"100":
|
|
574
|
-
"101":
|
|
575
|
-
"102":
|
|
576
|
-
"103":
|
|
577
|
-
"200":
|
|
578
|
-
"201":
|
|
579
|
-
"202":
|
|
580
|
-
"203":
|
|
581
|
-
"204":
|
|
582
|
-
"205":
|
|
583
|
-
"206":
|
|
584
|
-
"207":
|
|
585
|
-
"208":
|
|
586
|
-
"226":
|
|
587
|
-
"300":
|
|
588
|
-
"301":
|
|
589
|
-
"302":
|
|
590
|
-
"303":
|
|
591
|
-
"304":
|
|
592
|
-
"305":
|
|
593
|
-
"307":
|
|
594
|
-
"308":
|
|
595
|
-
"400":
|
|
596
|
-
"401":
|
|
597
|
-
"402":
|
|
598
|
-
"403":
|
|
599
|
-
"404":
|
|
600
|
-
"405":
|
|
601
|
-
"406":
|
|
602
|
-
"407":
|
|
603
|
-
"408":
|
|
604
|
-
"409":
|
|
605
|
-
"410":
|
|
606
|
-
"411":
|
|
607
|
-
"412":
|
|
608
|
-
"413":
|
|
609
|
-
"414":
|
|
610
|
-
"415":
|
|
611
|
-
"416":
|
|
612
|
-
"417":
|
|
613
|
-
"418":
|
|
614
|
-
"421":
|
|
615
|
-
"422":
|
|
616
|
-
"423":
|
|
617
|
-
"424":
|
|
618
|
-
"425":
|
|
619
|
-
"426":
|
|
620
|
-
"428":
|
|
621
|
-
"429":
|
|
622
|
-
"431":
|
|
623
|
-
"451":
|
|
624
|
-
"500":
|
|
625
|
-
"501":
|
|
626
|
-
"502":
|
|
627
|
-
"503":
|
|
628
|
-
"504":
|
|
629
|
-
"505":
|
|
630
|
-
"506":
|
|
631
|
-
"507":
|
|
632
|
-
"508":
|
|
633
|
-
"509":
|
|
634
|
-
"510":
|
|
635
|
-
"511":
|
|
514
|
+
"100": "Continue",
|
|
515
|
+
"101": "Switching Protocols",
|
|
516
|
+
"102": "Processing",
|
|
517
|
+
"103": "Early Hints",
|
|
518
|
+
"200": "OK",
|
|
519
|
+
"201": "Created",
|
|
520
|
+
"202": "Accepted",
|
|
521
|
+
"203": "Non-Authoritative Information",
|
|
522
|
+
"204": "No Content",
|
|
523
|
+
"205": "Reset Content",
|
|
524
|
+
"206": "Partial Content",
|
|
525
|
+
"207": "Multi-Status",
|
|
526
|
+
"208": "Already Reported",
|
|
527
|
+
"226": "IM Used",
|
|
528
|
+
"300": "Multiple Choices",
|
|
529
|
+
"301": "Moved Permanently",
|
|
530
|
+
"302": "Found",
|
|
531
|
+
"303": "See Other",
|
|
532
|
+
"304": "Not Modified",
|
|
533
|
+
"305": "Use Proxy",
|
|
534
|
+
"307": "Temporary Redirect",
|
|
535
|
+
"308": "Permanent Redirect",
|
|
536
|
+
"400": "Bad Request",
|
|
537
|
+
"401": "Unauthorized",
|
|
538
|
+
"402": "Payment Required",
|
|
539
|
+
"403": "Forbidden",
|
|
540
|
+
"404": "Not Found",
|
|
541
|
+
"405": "Method Not Allowed",
|
|
542
|
+
"406": "Not Acceptable",
|
|
543
|
+
"407": "Proxy Authentication Required",
|
|
544
|
+
"408": "Request Timeout",
|
|
545
|
+
"409": "Conflict",
|
|
546
|
+
"410": "Gone",
|
|
547
|
+
"411": "Length Required",
|
|
548
|
+
"412": "Precondition Failed",
|
|
549
|
+
"413": "Payload Too Large",
|
|
550
|
+
"414": "URI Too Long",
|
|
551
|
+
"415": "Unsupported Media Type",
|
|
552
|
+
"416": "Range Not Satisfiable",
|
|
553
|
+
"417": "Expectation Failed",
|
|
554
|
+
"418": "I'm a Teapot",
|
|
555
|
+
"421": "Misdirected Request",
|
|
556
|
+
"422": "Unprocessable Entity",
|
|
557
|
+
"423": "Locked",
|
|
558
|
+
"424": "Failed Dependency",
|
|
559
|
+
"425": "Too Early",
|
|
560
|
+
"426": "Upgrade Required",
|
|
561
|
+
"428": "Precondition Required",
|
|
562
|
+
"429": "Too Many Requests",
|
|
563
|
+
"431": "Request Header Fields Too Large",
|
|
564
|
+
"451": "Unavailable For Legal Reasons",
|
|
565
|
+
"500": "Internal Server Error",
|
|
566
|
+
"501": "Not Implemented",
|
|
567
|
+
"502": "Bad Gateway",
|
|
568
|
+
"503": "Service Unavailable",
|
|
569
|
+
"504": "Gateway Timeout",
|
|
570
|
+
"505": "HTTP Version Not Supported",
|
|
571
|
+
"506": "Variant Also Negotiates",
|
|
572
|
+
"507": "Insufficient Storage",
|
|
573
|
+
"508": "Loop Detected",
|
|
574
|
+
"509": "Bandwidth Limit Exceeded",
|
|
575
|
+
"510": "Not Extended",
|
|
576
|
+
"511": "Network Authentication Required"
|
|
636
577
|
};
|
|
637
578
|
|
|
638
579
|
// src/context/status.ts
|
|
@@ -719,7 +660,9 @@ var getRandomServerResponseTime = () => {
|
|
|
719
660
|
if (isNodeProcess()) {
|
|
720
661
|
return NODE_SERVER_RESPONSE_TIME;
|
|
721
662
|
}
|
|
722
|
-
return Math.floor(
|
|
663
|
+
return Math.floor(
|
|
664
|
+
Math.random() * (MAX_SERVER_RESPONSE_TIME - MIN_SERVER_RESPONSE_TIME) + MIN_SERVER_RESPONSE_TIME
|
|
665
|
+
);
|
|
723
666
|
};
|
|
724
667
|
var delay = (durationOrMode) => {
|
|
725
668
|
return (res) => {
|
|
@@ -735,14 +678,18 @@ var delay = (durationOrMode) => {
|
|
|
735
678
|
break;
|
|
736
679
|
}
|
|
737
680
|
default: {
|
|
738
|
-
throw new Error(
|
|
681
|
+
throw new Error(
|
|
682
|
+
`Failed to delay a response: unknown delay mode "${durationOrMode}". Please make sure you provide one of the supported modes ("real", "infinite") or a number to "ctx.delay".`
|
|
683
|
+
);
|
|
739
684
|
}
|
|
740
685
|
}
|
|
741
686
|
} else if (typeof durationOrMode === "undefined") {
|
|
742
687
|
delayTime = getRandomServerResponseTime();
|
|
743
688
|
} else {
|
|
744
689
|
if (durationOrMode > SET_TIMEOUT_MAX_ALLOWED_INT) {
|
|
745
|
-
throw new Error(
|
|
690
|
+
throw new Error(
|
|
691
|
+
`Failed to delay a response: provided delay duration (${durationOrMode}) exceeds the maximum allowed duration for "setTimeout" (${SET_TIMEOUT_MAX_ALLOWED_INT}). This will cause the response to be returned immediately. Please use a number within the allowed range to delay the response by exact duration, or consider the "infinite" delay mode to delay the response indefinitely.`
|
|
692
|
+
);
|
|
746
693
|
}
|
|
747
694
|
delayTime = durationOrMode;
|
|
748
695
|
}
|
|
@@ -766,19 +713,23 @@ var errors = (errorsList) => {
|
|
|
766
713
|
// src/context/fetch.ts
|
|
767
714
|
import { isNodeProcess as isNodeProcess2 } from "is-node-process";
|
|
768
715
|
import { Headers as Headers2 } from "headers-polyfill";
|
|
769
|
-
var useFetch = isNodeProcess2() ? (input, init) => Promise.resolve().then(() => __toESM(__require("node-fetch"))).then(
|
|
716
|
+
var useFetch = isNodeProcess2() ? (input, init) => Promise.resolve().then(() => __toESM(__require("node-fetch"))).then(
|
|
717
|
+
({ default: nodeFetch }) => nodeFetch(input, init)
|
|
718
|
+
) : globalThis.fetch;
|
|
770
719
|
var augmentRequestInit = (requestInit) => {
|
|
771
720
|
const headers = new Headers2(requestInit.headers);
|
|
772
721
|
headers.set("x-msw-bypass", "true");
|
|
773
|
-
return
|
|
722
|
+
return {
|
|
723
|
+
...requestInit,
|
|
774
724
|
headers: headers.all()
|
|
775
|
-
}
|
|
725
|
+
};
|
|
776
726
|
};
|
|
777
727
|
var createFetchRequestParameters = (input) => {
|
|
778
728
|
const { body: body2, method } = input;
|
|
779
|
-
const requestParameters =
|
|
729
|
+
const requestParameters = {
|
|
730
|
+
...input,
|
|
780
731
|
body: void 0
|
|
781
|
-
}
|
|
732
|
+
};
|
|
782
733
|
if (["GET", "HEAD"].includes(method)) {
|
|
783
734
|
return requestParameters;
|
|
784
735
|
}
|
|
@@ -835,19 +786,21 @@ function getTimestamp() {
|
|
|
835
786
|
|
|
836
787
|
// src/utils/logging/prepareRequest.ts
|
|
837
788
|
function prepareRequest(request) {
|
|
838
|
-
return
|
|
789
|
+
return {
|
|
790
|
+
...request,
|
|
839
791
|
body: request.body,
|
|
840
792
|
headers: request.headers.all()
|
|
841
|
-
}
|
|
793
|
+
};
|
|
842
794
|
}
|
|
843
795
|
|
|
844
796
|
// src/utils/logging/prepareResponse.ts
|
|
845
797
|
import { objectToHeaders as objectToHeaders2 } from "headers-polyfill";
|
|
846
798
|
function prepareResponse(res) {
|
|
847
799
|
const responseHeaders = objectToHeaders2(res.headers);
|
|
848
|
-
return
|
|
800
|
+
return {
|
|
801
|
+
...res,
|
|
849
802
|
body: parseBody(res.body, responseHeaders)
|
|
850
|
-
}
|
|
803
|
+
};
|
|
851
804
|
}
|
|
852
805
|
|
|
853
806
|
// src/utils/matching/matchRequestUrl.ts
|
|
@@ -891,13 +844,16 @@ function normalizePath(path, baseUrl) {
|
|
|
891
844
|
|
|
892
845
|
// src/utils/matching/matchRequestUrl.ts
|
|
893
846
|
function coercePath(path) {
|
|
894
|
-
return path.replace(
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
847
|
+
return path.replace(
|
|
848
|
+
/([:a-zA-Z_-]*)(\*{1,2})+/g,
|
|
849
|
+
(_, parameterName, wildcard) => {
|
|
850
|
+
const expression = "(.*)";
|
|
851
|
+
if (!parameterName) {
|
|
852
|
+
return expression;
|
|
853
|
+
}
|
|
854
|
+
return parameterName.startsWith(":") ? `${parameterName}${wildcard}` : `${parameterName}${expression}`;
|
|
898
855
|
}
|
|
899
|
-
|
|
900
|
-
}).replace(/([^\/])(:)(?=\d+)/, "$1\\$2").replace(/^([^\/]+)(:)(?=\/\/)/, "$1\\$2");
|
|
856
|
+
).replace(/([^\/])(:)(?=\d+)/, "$1\\$2").replace(/^([^\/]+)(:)(?=\/\/)/, "$1\\$2");
|
|
901
857
|
}
|
|
902
858
|
function matchRequestUrl(url, path, baseUrl) {
|
|
903
859
|
const normalizedPath = normalizePath(path, baseUrl);
|
|
@@ -946,11 +902,16 @@ var defaultResponse = {
|
|
|
946
902
|
var defaultResponseTransformers = [];
|
|
947
903
|
function createResponseComposition(responseOverrides, defaultTransformers = defaultResponseTransformers) {
|
|
948
904
|
return async (...transformers) => {
|
|
949
|
-
const initialResponse = Object.assign(
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
905
|
+
const initialResponse = Object.assign(
|
|
906
|
+
{},
|
|
907
|
+
defaultResponse,
|
|
908
|
+
{
|
|
909
|
+
headers: new Headers3({
|
|
910
|
+
"x-powered-by": "msw"
|
|
911
|
+
})
|
|
912
|
+
},
|
|
913
|
+
responseOverrides
|
|
914
|
+
);
|
|
954
915
|
const resolvedTransformers = [
|
|
955
916
|
...defaultTransformers,
|
|
956
917
|
...transformers
|
|
@@ -1006,15 +967,20 @@ var RequestHandler = class {
|
|
|
1006
967
|
this.ctx = options.ctx || defaultContext;
|
|
1007
968
|
this.resolver = options.resolver;
|
|
1008
969
|
const callFrame = getCallFrame(new Error());
|
|
1009
|
-
this.info =
|
|
970
|
+
this.info = {
|
|
971
|
+
...options.info,
|
|
1010
972
|
callFrame
|
|
1011
|
-
}
|
|
973
|
+
};
|
|
1012
974
|
}
|
|
1013
975
|
parse(_request, _resolutionContext) {
|
|
1014
976
|
return null;
|
|
1015
977
|
}
|
|
1016
978
|
test(request, resolutionContext) {
|
|
1017
|
-
return this.predicate(
|
|
979
|
+
return this.predicate(
|
|
980
|
+
request,
|
|
981
|
+
this.parse(request, resolutionContext),
|
|
982
|
+
resolutionContext
|
|
983
|
+
);
|
|
1018
984
|
}
|
|
1019
985
|
getPublicRequest(request, _parsedResult) {
|
|
1020
986
|
return request;
|
|
@@ -1027,14 +993,26 @@ var RequestHandler = class {
|
|
|
1027
993
|
return null;
|
|
1028
994
|
}
|
|
1029
995
|
const parsedResult = this.parse(request, resolutionContext);
|
|
1030
|
-
const shouldIntercept = this.predicate(
|
|
996
|
+
const shouldIntercept = this.predicate(
|
|
997
|
+
request,
|
|
998
|
+
parsedResult,
|
|
999
|
+
resolutionContext
|
|
1000
|
+
);
|
|
1031
1001
|
if (!shouldIntercept) {
|
|
1032
1002
|
return null;
|
|
1033
1003
|
}
|
|
1034
1004
|
const publicRequest = this.getPublicRequest(request, parsedResult);
|
|
1035
1005
|
const executeResolver = this.wrapResolver(this.resolver);
|
|
1036
|
-
const mockedResponse = await executeResolver(
|
|
1037
|
-
|
|
1006
|
+
const mockedResponse = await executeResolver(
|
|
1007
|
+
publicRequest,
|
|
1008
|
+
response,
|
|
1009
|
+
this.ctx
|
|
1010
|
+
);
|
|
1011
|
+
return this.createExecutionResult(
|
|
1012
|
+
parsedResult,
|
|
1013
|
+
publicRequest,
|
|
1014
|
+
mockedResponse
|
|
1015
|
+
);
|
|
1038
1016
|
}
|
|
1039
1017
|
wrapResolver(resolver) {
|
|
1040
1018
|
return async (req, res, ctx) => {
|
|
@@ -1065,18 +1043,20 @@ var RequestHandler = class {
|
|
|
1065
1043
|
};
|
|
1066
1044
|
|
|
1067
1045
|
// src/handlers/RestHandler.ts
|
|
1068
|
-
var restContext =
|
|
1046
|
+
var restContext = {
|
|
1047
|
+
...defaultContext,
|
|
1069
1048
|
cookie,
|
|
1070
1049
|
body,
|
|
1071
1050
|
text,
|
|
1072
1051
|
json,
|
|
1073
1052
|
xml
|
|
1074
|
-
}
|
|
1053
|
+
};
|
|
1075
1054
|
var RestRequest = class extends MockedRequest {
|
|
1076
1055
|
constructor(request, params) {
|
|
1077
|
-
super(request.url,
|
|
1056
|
+
super(request.url, {
|
|
1057
|
+
...request,
|
|
1078
1058
|
body: request["_body"]
|
|
1079
|
-
})
|
|
1059
|
+
});
|
|
1080
1060
|
this.params = params;
|
|
1081
1061
|
this.id = request.id;
|
|
1082
1062
|
}
|
|
@@ -1108,10 +1088,16 @@ var RestHandler = class extends RequestHandler {
|
|
|
1108
1088
|
searchParams.forEach((_, paramName) => {
|
|
1109
1089
|
queryParams.push(paramName);
|
|
1110
1090
|
});
|
|
1111
|
-
devUtils.warn(
|
|
1091
|
+
devUtils.warn(
|
|
1092
|
+
`Found a redundant usage of query parameters in the request handler URL for "${method} ${path}". Please match against a path instead and access query parameters in the response resolver function using "req.url.searchParams".`
|
|
1093
|
+
);
|
|
1112
1094
|
}
|
|
1113
1095
|
parse(request, resolutionContext) {
|
|
1114
|
-
return matchRequestUrl(
|
|
1096
|
+
return matchRequestUrl(
|
|
1097
|
+
request.url,
|
|
1098
|
+
this.info.path,
|
|
1099
|
+
resolutionContext == null ? void 0 : resolutionContext.baseUrl
|
|
1100
|
+
);
|
|
1115
1101
|
}
|
|
1116
1102
|
getPublicRequest(request, parsedResult) {
|
|
1117
1103
|
return new RestRequest(request, parsedResult.params || {});
|
|
@@ -1125,7 +1111,15 @@ var RestHandler = class extends RequestHandler {
|
|
|
1125
1111
|
const loggedRequest = prepareRequest(request);
|
|
1126
1112
|
const loggedResponse = prepareResponse(response2);
|
|
1127
1113
|
const statusColor = getStatusCodeColor(response2.status);
|
|
1128
|
-
console.groupCollapsed(
|
|
1114
|
+
console.groupCollapsed(
|
|
1115
|
+
devUtils.formatMessage("%s %s %s (%c%s%c)"),
|
|
1116
|
+
getTimestamp(),
|
|
1117
|
+
request.method,
|
|
1118
|
+
publicUrl,
|
|
1119
|
+
`color:${statusColor}`,
|
|
1120
|
+
`${response2.status} ${response2.statusText}`,
|
|
1121
|
+
"color:inherit"
|
|
1122
|
+
);
|
|
1129
1123
|
console.log("Request", loggedRequest);
|
|
1130
1124
|
console.log("Handler:", this);
|
|
1131
1125
|
console.log("Response", loggedResponse);
|
|
@@ -1144,10 +1138,33 @@ var field = (fieldName, fieldValue) => {
|
|
|
1144
1138
|
};
|
|
1145
1139
|
};
|
|
1146
1140
|
function validateFieldName(fieldName) {
|
|
1147
|
-
invariant2(
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1141
|
+
invariant2(
|
|
1142
|
+
fieldName.trim() !== "",
|
|
1143
|
+
devUtils.formatMessage(
|
|
1144
|
+
"Failed to set a custom field on a GraphQL response: field name cannot be empty."
|
|
1145
|
+
)
|
|
1146
|
+
);
|
|
1147
|
+
invariant2(
|
|
1148
|
+
fieldName !== "data",
|
|
1149
|
+
devUtils.formatMessage(
|
|
1150
|
+
'Failed to set a custom "%s" field on a mocked GraphQL response: forbidden field name. Did you mean to call "ctx.data()" instead?',
|
|
1151
|
+
fieldName
|
|
1152
|
+
)
|
|
1153
|
+
);
|
|
1154
|
+
invariant2(
|
|
1155
|
+
fieldName !== "errors",
|
|
1156
|
+
devUtils.formatMessage(
|
|
1157
|
+
'Failed to set a custom "%s" field on a mocked GraphQL response: forbidden field name. Did you mean to call "ctx.errors()" instead?',
|
|
1158
|
+
fieldName
|
|
1159
|
+
)
|
|
1160
|
+
);
|
|
1161
|
+
invariant2(
|
|
1162
|
+
fieldName !== "extensions",
|
|
1163
|
+
devUtils.formatMessage(
|
|
1164
|
+
'Failed to set a custom "%s" field on a mocked GraphQL response: forbidden field name. Did you mean to call "ctx.extensions()" instead?',
|
|
1165
|
+
fieldName
|
|
1166
|
+
)
|
|
1167
|
+
);
|
|
1151
1168
|
}
|
|
1152
1169
|
|
|
1153
1170
|
// src/utils/internal/tryCatch.ts
|
|
@@ -1161,13 +1178,14 @@ function tryCatch(fn, onException) {
|
|
|
1161
1178
|
}
|
|
1162
1179
|
|
|
1163
1180
|
// src/handlers/GraphQLHandler.ts
|
|
1164
|
-
var graphqlContext =
|
|
1181
|
+
var graphqlContext = {
|
|
1182
|
+
...defaultContext,
|
|
1165
1183
|
data,
|
|
1166
1184
|
extensions,
|
|
1167
1185
|
errors,
|
|
1168
1186
|
cookie,
|
|
1169
1187
|
field
|
|
1170
|
-
}
|
|
1188
|
+
};
|
|
1171
1189
|
function isDocumentNode(value) {
|
|
1172
1190
|
if (value == null) {
|
|
1173
1191
|
return false;
|
|
@@ -1176,9 +1194,10 @@ function isDocumentNode(value) {
|
|
|
1176
1194
|
}
|
|
1177
1195
|
var GraphQLRequest = class extends MockedRequest {
|
|
1178
1196
|
constructor(request, variables) {
|
|
1179
|
-
super(request.url,
|
|
1197
|
+
super(request.url, {
|
|
1198
|
+
...request,
|
|
1180
1199
|
body: request["_body"]
|
|
1181
|
-
})
|
|
1200
|
+
});
|
|
1182
1201
|
this.variables = variables;
|
|
1183
1202
|
}
|
|
1184
1203
|
};
|
|
@@ -1188,10 +1207,14 @@ var GraphQLHandler = class extends RequestHandler {
|
|
|
1188
1207
|
if (isDocumentNode(operationName)) {
|
|
1189
1208
|
const parsedNode = parseDocumentNode(operationName);
|
|
1190
1209
|
if (parsedNode.operationType !== operationType) {
|
|
1191
|
-
throw new Error(
|
|
1210
|
+
throw new Error(
|
|
1211
|
+
`Failed to create a GraphQL handler: provided a DocumentNode with a mismatched operation type (expected "${operationType}", but got "${parsedNode.operationType}").`
|
|
1212
|
+
);
|
|
1192
1213
|
}
|
|
1193
1214
|
if (!parsedNode.operationName) {
|
|
1194
|
-
throw new Error(
|
|
1215
|
+
throw new Error(
|
|
1216
|
+
`Failed to create a GraphQL handler: provided a DocumentNode with no operation name.`
|
|
1217
|
+
);
|
|
1195
1218
|
}
|
|
1196
1219
|
resolvedOperationName = parsedNode.operationName;
|
|
1197
1220
|
}
|
|
@@ -1208,7 +1231,10 @@ var GraphQLHandler = class extends RequestHandler {
|
|
|
1208
1231
|
this.endpoint = endpoint;
|
|
1209
1232
|
}
|
|
1210
1233
|
parse(request) {
|
|
1211
|
-
return tryCatch(
|
|
1234
|
+
return tryCatch(
|
|
1235
|
+
() => parseGraphQLRequest(request),
|
|
1236
|
+
(error2) => console.error(error2.message)
|
|
1237
|
+
);
|
|
1212
1238
|
}
|
|
1213
1239
|
getPublicRequest(request, parsedResult) {
|
|
1214
1240
|
return new GraphQLRequest(request, (parsedResult == null ? void 0 : parsedResult.variables) || {});
|
|
@@ -1221,7 +1247,7 @@ var GraphQLHandler = class extends RequestHandler {
|
|
|
1221
1247
|
const publicUrl = getPublicUrlFromRequest(request);
|
|
1222
1248
|
devUtils.warn(`Failed to intercept a GraphQL request at "${request.method} ${publicUrl}": anonymous GraphQL operations are not supported.
|
|
1223
1249
|
|
|
1224
|
-
Consider naming this operation or using "graphql.operation" request handler to intercept GraphQL requests regardless of their operation name/type. Read more: https://mswjs.io/docs/api/graphql/operation `);
|
|
1250
|
+
Consider naming this operation or using "graphql.operation()" request handler to intercept GraphQL requests regardless of their operation name/type. Read more: https://mswjs.io/docs/api/graphql/operation `);
|
|
1225
1251
|
return false;
|
|
1226
1252
|
}
|
|
1227
1253
|
const hasMatchingUrl = matchRequestUrl(request.url, this.endpoint);
|
|
@@ -1234,7 +1260,14 @@ Consider naming this operation or using "graphql.operation" request handler to i
|
|
|
1234
1260
|
const loggedResponse = prepareResponse(response2);
|
|
1235
1261
|
const statusColor = getStatusCodeColor(response2.status);
|
|
1236
1262
|
const requestInfo = (parsedRequest == null ? void 0 : parsedRequest.operationName) ? `${parsedRequest == null ? void 0 : parsedRequest.operationType} ${parsedRequest == null ? void 0 : parsedRequest.operationName}` : `anonymous ${parsedRequest == null ? void 0 : parsedRequest.operationType}`;
|
|
1237
|
-
console.groupCollapsed(
|
|
1263
|
+
console.groupCollapsed(
|
|
1264
|
+
devUtils.formatMessage("%s %s (%c%s%c)"),
|
|
1265
|
+
getTimestamp(),
|
|
1266
|
+
`${requestInfo}`,
|
|
1267
|
+
`color:${statusColor}`,
|
|
1268
|
+
`${response2.status} ${response2.statusText}`,
|
|
1269
|
+
"color:inherit"
|
|
1270
|
+
);
|
|
1238
1271
|
console.log("Request:", loggedRequest);
|
|
1239
1272
|
console.log("Handler:", this);
|
|
1240
1273
|
console.log("Response:", loggedResponse);
|
|
@@ -1247,18 +1280,21 @@ var MAX_MATCH_SCORE = 3;
|
|
|
1247
1280
|
var MAX_SUGGESTION_COUNT = 4;
|
|
1248
1281
|
var TYPE_MATCH_DELTA = 0.5;
|
|
1249
1282
|
function groupHandlersByType(handlers) {
|
|
1250
|
-
return handlers.reduce(
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1283
|
+
return handlers.reduce(
|
|
1284
|
+
(groups, handler) => {
|
|
1285
|
+
if (handler instanceof RestHandler) {
|
|
1286
|
+
groups.rest.push(handler);
|
|
1287
|
+
}
|
|
1288
|
+
if (handler instanceof GraphQLHandler) {
|
|
1289
|
+
groups.graphql.push(handler);
|
|
1290
|
+
}
|
|
1291
|
+
return groups;
|
|
1292
|
+
},
|
|
1293
|
+
{
|
|
1294
|
+
rest: [],
|
|
1295
|
+
graphql: []
|
|
1256
1296
|
}
|
|
1257
|
-
|
|
1258
|
-
}, {
|
|
1259
|
-
rest: [],
|
|
1260
|
-
graphql: []
|
|
1261
|
-
});
|
|
1297
|
+
);
|
|
1262
1298
|
}
|
|
1263
1299
|
function getRestHandlerScore() {
|
|
1264
1300
|
return (request, handler) => {
|
|
@@ -1308,7 +1344,11 @@ function onUnhandledRequest(request, handlers, strategy = "warn") {
|
|
|
1308
1344
|
function generateHandlerSuggestion() {
|
|
1309
1345
|
const handlerGroups = groupHandlersByType(handlers);
|
|
1310
1346
|
const relevantHandlers = parsedGraphQLQuery ? handlerGroups.graphql : handlerGroups.rest;
|
|
1311
|
-
const suggestedHandlers = getSuggestedHandler(
|
|
1347
|
+
const suggestedHandlers = getSuggestedHandler(
|
|
1348
|
+
request,
|
|
1349
|
+
relevantHandlers,
|
|
1350
|
+
parsedGraphQLQuery ? getGraphQLHandlerScore(parsedGraphQLQuery) : getRestHandlerScore()
|
|
1351
|
+
);
|
|
1312
1352
|
return suggestedHandlers.length > 0 ? getSuggestedHandlersMessage(suggestedHandlers) : "";
|
|
1313
1353
|
}
|
|
1314
1354
|
function generateUnhandledRequestMessage() {
|
|
@@ -1329,7 +1369,11 @@ Read more: https://mswjs.io/docs/getting-started/mocks`
|
|
|
1329
1369
|
switch (strategy2) {
|
|
1330
1370
|
case "error": {
|
|
1331
1371
|
devUtils.error("Error: %s", message);
|
|
1332
|
-
throw new Error(
|
|
1372
|
+
throw new Error(
|
|
1373
|
+
devUtils.formatMessage(
|
|
1374
|
+
'Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option.'
|
|
1375
|
+
)
|
|
1376
|
+
);
|
|
1333
1377
|
}
|
|
1334
1378
|
case "warn": {
|
|
1335
1379
|
devUtils.warn("Warning: %s", message);
|
|
@@ -1338,7 +1382,12 @@ Read more: https://mswjs.io/docs/getting-started/mocks`
|
|
|
1338
1382
|
case "bypass":
|
|
1339
1383
|
break;
|
|
1340
1384
|
default:
|
|
1341
|
-
throw new Error(
|
|
1385
|
+
throw new Error(
|
|
1386
|
+
devUtils.formatMessage(
|
|
1387
|
+
'Failed to react to an unhandled request: unknown strategy "%s". Please provide one of the supported strategies ("bypass", "warn", "error") or a custom callback function as the value of the "onUnhandledRequest" option.',
|
|
1388
|
+
strategy2
|
|
1389
|
+
)
|
|
1390
|
+
);
|
|
1342
1391
|
}
|
|
1343
1392
|
}
|
|
1344
1393
|
if (typeof strategy === "function") {
|
|
@@ -1354,7 +1403,7 @@ Read more: https://mswjs.io/docs/getting-started/mocks`
|
|
|
1354
1403
|
// src/utils/request/readResponseCookies.ts
|
|
1355
1404
|
import { store as store2 } from "@mswjs/cookies";
|
|
1356
1405
|
function readResponseCookies(request, response2) {
|
|
1357
|
-
store2.add(
|
|
1406
|
+
store2.add({ ...request, url: request.url.toString() }, response2);
|
|
1358
1407
|
store2.persist();
|
|
1359
1408
|
}
|
|
1360
1409
|
|
|
@@ -1368,7 +1417,11 @@ async function handleRequest(request, handlers, options, emitter, handleRequestO
|
|
|
1368
1417
|
return;
|
|
1369
1418
|
}
|
|
1370
1419
|
const [lookupError, lookupResult] = await until(() => {
|
|
1371
|
-
return getResponse(
|
|
1420
|
+
return getResponse(
|
|
1421
|
+
request,
|
|
1422
|
+
handlers,
|
|
1423
|
+
handleRequestOptions == null ? void 0 : handleRequestOptions.resolutionContext
|
|
1424
|
+
);
|
|
1372
1425
|
});
|
|
1373
1426
|
if (lookupError) {
|
|
1374
1427
|
emitter.emit("unhandledException", lookupError, request);
|
|
@@ -1383,10 +1436,15 @@ async function handleRequest(request, handlers, options, emitter, handleRequestO
|
|
|
1383
1436
|
return;
|
|
1384
1437
|
}
|
|
1385
1438
|
if (!response2) {
|
|
1386
|
-
devUtils.warn(
|
|
1439
|
+
devUtils.warn(
|
|
1440
|
+
`Expected response resolver to return a mocked response Object, but got %s. The original response is going to be used instead.
|
|
1387
1441
|
|
|
1388
1442
|
\u2022 %s
|
|
1389
|
-
%s`,
|
|
1443
|
+
%s`,
|
|
1444
|
+
response2,
|
|
1445
|
+
handler.info.header,
|
|
1446
|
+
handler.info.callFrame
|
|
1447
|
+
);
|
|
1390
1448
|
emitter.emit("request:end", request);
|
|
1391
1449
|
(_c = handleRequestOptions == null ? void 0 : handleRequestOptions.onPassthroughResponse) == null ? void 0 : _c.call(handleRequestOptions, request);
|
|
1392
1450
|
return;
|
|
@@ -1400,7 +1458,11 @@ async function handleRequest(request, handlers, options, emitter, handleRequestO
|
|
|
1400
1458
|
emitter.emit("request:match", request);
|
|
1401
1459
|
const requiredLookupResult = lookupResult;
|
|
1402
1460
|
const transformedResponse = ((_e = handleRequestOptions == null ? void 0 : handleRequestOptions.transformResponse) == null ? void 0 : _e.call(handleRequestOptions, response2)) || response2;
|
|
1403
|
-
(_f = handleRequestOptions == null ? void 0 : handleRequestOptions.onMockedResponse) == null ? void 0 : _f.call(
|
|
1461
|
+
(_f = handleRequestOptions == null ? void 0 : handleRequestOptions.onMockedResponse) == null ? void 0 : _f.call(
|
|
1462
|
+
handleRequestOptions,
|
|
1463
|
+
transformedResponse,
|
|
1464
|
+
requiredLookupResult
|
|
1465
|
+
);
|
|
1404
1466
|
emitter.emit("request:end", request);
|
|
1405
1467
|
return transformedResponse;
|
|
1406
1468
|
}
|
|
@@ -1422,20 +1484,27 @@ var SetupServerApi = class extends SetupApi {
|
|
|
1422
1484
|
}
|
|
1423
1485
|
init() {
|
|
1424
1486
|
this.interceptor.on("request", async (request) => {
|
|
1425
|
-
const mockedRequest = new MockedRequest(request.url,
|
|
1487
|
+
const mockedRequest = new MockedRequest(request.url, {
|
|
1488
|
+
...request,
|
|
1426
1489
|
body: await request.arrayBuffer()
|
|
1427
|
-
}));
|
|
1428
|
-
const response2 = await handleRequest(mockedRequest, this.currentHandlers, this.resolvedOptions, this.emitter, {
|
|
1429
|
-
transformResponse(response3) {
|
|
1430
|
-
return {
|
|
1431
|
-
status: response3.status,
|
|
1432
|
-
statusText: response3.statusText,
|
|
1433
|
-
headers: response3.headers.all(),
|
|
1434
|
-
body: response3.body,
|
|
1435
|
-
delay: response3.delay
|
|
1436
|
-
};
|
|
1437
|
-
}
|
|
1438
1490
|
});
|
|
1491
|
+
const response2 = await handleRequest(
|
|
1492
|
+
mockedRequest,
|
|
1493
|
+
this.currentHandlers,
|
|
1494
|
+
this.resolvedOptions,
|
|
1495
|
+
this.emitter,
|
|
1496
|
+
{
|
|
1497
|
+
transformResponse(response3) {
|
|
1498
|
+
return {
|
|
1499
|
+
status: response3.status,
|
|
1500
|
+
statusText: response3.statusText,
|
|
1501
|
+
headers: response3.headers.all(),
|
|
1502
|
+
body: response3.body,
|
|
1503
|
+
delay: response3.delay
|
|
1504
|
+
};
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
);
|
|
1439
1508
|
if (response2) {
|
|
1440
1509
|
if (response2.delay) {
|
|
1441
1510
|
await new Promise((resolve) => {
|
|
@@ -1458,9 +1527,20 @@ var SetupServerApi = class extends SetupApi {
|
|
|
1458
1527
|
});
|
|
1459
1528
|
}
|
|
1460
1529
|
listen(options = {}) {
|
|
1461
|
-
this.resolvedOptions = mergeRight(
|
|
1530
|
+
this.resolvedOptions = mergeRight(
|
|
1531
|
+
DEFAULT_LISTEN_OPTIONS,
|
|
1532
|
+
options
|
|
1533
|
+
);
|
|
1462
1534
|
this.interceptor.apply();
|
|
1463
|
-
invariant3(
|
|
1535
|
+
invariant3(
|
|
1536
|
+
[InterceptorReadyState.APPLYING, InterceptorReadyState.APPLIED].includes(
|
|
1537
|
+
this.interceptor.readyState
|
|
1538
|
+
),
|
|
1539
|
+
devUtils.formatMessage(
|
|
1540
|
+
'Failed to start "setupServer": the interceptor failed to apply. This is likely an issue with the library and you should report it at "%s".'
|
|
1541
|
+
),
|
|
1542
|
+
"https://github.com/mswjs/msw/issues/new/choose"
|
|
1543
|
+
);
|
|
1464
1544
|
}
|
|
1465
1545
|
printHandlers() {
|
|
1466
1546
|
const handlers = this.listHandlers();
|