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