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.js
CHANGED
|
@@ -1,38 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
9
7
|
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
|
-
var __objRest = (source, exclude) => {
|
|
25
|
-
var target = {};
|
|
26
|
-
for (var prop in source)
|
|
27
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
28
|
-
target[prop] = source[prop];
|
|
29
|
-
if (source != null && __getOwnPropSymbols)
|
|
30
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
31
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
32
|
-
target[prop] = source[prop];
|
|
33
|
-
}
|
|
34
|
-
return target;
|
|
35
|
-
};
|
|
36
8
|
var __export = (target, all) => {
|
|
37
9
|
for (var name in all)
|
|
38
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -45,7 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
45
17
|
}
|
|
46
18
|
return to;
|
|
47
19
|
};
|
|
48
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
49
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
50
25
|
|
|
51
26
|
// src/native/index.ts
|
|
@@ -117,7 +92,13 @@ var SetupApi = class {
|
|
|
117
92
|
}
|
|
118
93
|
validateHandlers(...handlers) {
|
|
119
94
|
for (const handler of handlers) {
|
|
120
|
-
(0, import_outvariant2.invariant)(
|
|
95
|
+
(0, import_outvariant2.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
|
+
);
|
|
121
102
|
}
|
|
122
103
|
}
|
|
123
104
|
dispose() {
|
|
@@ -337,15 +318,23 @@ var MockedRequest = class extends import_interceptors.IsomorphicRequest {
|
|
|
337
318
|
const requestCookiesString = this.headers.get("cookie");
|
|
338
319
|
const ownCookies = requestCookiesString ? cookieUtils2.parse(requestCookiesString) : {};
|
|
339
320
|
import_cookies.store.hydrate();
|
|
340
|
-
const cookiesFromStore = Array.from(
|
|
321
|
+
const cookiesFromStore = Array.from(
|
|
322
|
+
(_a = import_cookies.store.get({ ...this, url: this.url.href })) == null ? void 0 : _a.entries()
|
|
323
|
+
).reduce((cookies, [name, { value }]) => {
|
|
341
324
|
return Object.assign(cookies, { [name.trim()]: value });
|
|
342
325
|
}, {});
|
|
343
326
|
const cookiesFromDocument = getRequestCookies(this);
|
|
344
|
-
const forwardedCookies =
|
|
327
|
+
const forwardedCookies = {
|
|
328
|
+
...cookiesFromDocument,
|
|
329
|
+
...cookiesFromStore
|
|
330
|
+
};
|
|
345
331
|
for (const [name, value] of Object.entries(forwardedCookies)) {
|
|
346
332
|
this.headers.append("cookie", `${name}=${value}`);
|
|
347
333
|
}
|
|
348
|
-
return
|
|
334
|
+
return {
|
|
335
|
+
...forwardedCookies,
|
|
336
|
+
...ownCookies
|
|
337
|
+
};
|
|
349
338
|
}
|
|
350
339
|
};
|
|
351
340
|
|
|
@@ -407,7 +396,10 @@ var import_graphql = require("graphql");
|
|
|
407
396
|
|
|
408
397
|
// src/utils/request/getPublicUrlFromRequest.ts
|
|
409
398
|
var getPublicUrlFromRequest = (request) => {
|
|
410
|
-
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;
|
|
411
403
|
};
|
|
412
404
|
|
|
413
405
|
// src/utils/internal/parseGraphQLRequest.ts
|
|
@@ -470,13 +462,19 @@ function getGraphQLInput(request) {
|
|
|
470
462
|
};
|
|
471
463
|
}
|
|
472
464
|
if ((_b = request.body) == null ? void 0 : _b.operations) {
|
|
473
|
-
const
|
|
474
|
-
const parsedOperations = jsonParse(
|
|
465
|
+
const { operations, map, ...files } = request.body;
|
|
466
|
+
const parsedOperations = jsonParse(
|
|
467
|
+
operations
|
|
468
|
+
) || {};
|
|
475
469
|
if (!parsedOperations.query) {
|
|
476
470
|
return null;
|
|
477
471
|
}
|
|
478
472
|
const parsedMap = jsonParse(map || "") || {};
|
|
479
|
-
const variables = parsedOperations.variables ? extractMultipartVariables(
|
|
473
|
+
const variables = parsedOperations.variables ? extractMultipartVariables(
|
|
474
|
+
parsedOperations.variables,
|
|
475
|
+
parsedMap,
|
|
476
|
+
files
|
|
477
|
+
) : {};
|
|
480
478
|
return {
|
|
481
479
|
query: parsedOperations.query,
|
|
482
480
|
variables
|
|
@@ -496,7 +494,14 @@ function parseGraphQLRequest(request) {
|
|
|
496
494
|
const parsedResult = parseQuery(query);
|
|
497
495
|
if (parsedResult instanceof Error) {
|
|
498
496
|
const requestPublicUrl = getPublicUrlFromRequest(request);
|
|
499
|
-
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
|
+
);
|
|
500
505
|
}
|
|
501
506
|
return {
|
|
502
507
|
operationType: parsedResult.operationType,
|
|
@@ -505,134 +510,71 @@ function parseGraphQLRequest(request) {
|
|
|
505
510
|
};
|
|
506
511
|
}
|
|
507
512
|
|
|
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";
|
|
513
|
+
// node_modules/.pnpm/statuses@2.0.1/node_modules/statuses/codes.json
|
|
572
514
|
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":
|
|
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"
|
|
636
578
|
};
|
|
637
579
|
|
|
638
580
|
// src/context/status.ts
|
|
@@ -719,7 +661,9 @@ var getRandomServerResponseTime = () => {
|
|
|
719
661
|
if ((0, import_is_node_process.isNodeProcess)()) {
|
|
720
662
|
return NODE_SERVER_RESPONSE_TIME;
|
|
721
663
|
}
|
|
722
|
-
return Math.floor(
|
|
664
|
+
return Math.floor(
|
|
665
|
+
Math.random() * (MAX_SERVER_RESPONSE_TIME - MIN_SERVER_RESPONSE_TIME) + MIN_SERVER_RESPONSE_TIME
|
|
666
|
+
);
|
|
723
667
|
};
|
|
724
668
|
var delay = (durationOrMode) => {
|
|
725
669
|
return (res) => {
|
|
@@ -735,14 +679,18 @@ var delay = (durationOrMode) => {
|
|
|
735
679
|
break;
|
|
736
680
|
}
|
|
737
681
|
default: {
|
|
738
|
-
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
|
+
);
|
|
739
685
|
}
|
|
740
686
|
}
|
|
741
687
|
} else if (typeof durationOrMode === "undefined") {
|
|
742
688
|
delayTime = getRandomServerResponseTime();
|
|
743
689
|
} else {
|
|
744
690
|
if (durationOrMode > SET_TIMEOUT_MAX_ALLOWED_INT) {
|
|
745
|
-
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
|
+
);
|
|
746
694
|
}
|
|
747
695
|
delayTime = durationOrMode;
|
|
748
696
|
}
|
|
@@ -766,19 +714,23 @@ var errors = (errorsList) => {
|
|
|
766
714
|
// src/context/fetch.ts
|
|
767
715
|
var import_is_node_process2 = require("is-node-process");
|
|
768
716
|
var import_headers_polyfill4 = require("headers-polyfill");
|
|
769
|
-
var useFetch = (0, import_is_node_process2.isNodeProcess)() ? (input, init) => Promise.resolve().then(() => __toESM(require("node-fetch"))).then(
|
|
717
|
+
var useFetch = (0, import_is_node_process2.isNodeProcess)() ? (input, init) => Promise.resolve().then(() => __toESM(require("node-fetch"))).then(
|
|
718
|
+
({ default: nodeFetch }) => nodeFetch(input, init)
|
|
719
|
+
) : globalThis.fetch;
|
|
770
720
|
var augmentRequestInit = (requestInit) => {
|
|
771
721
|
const headers = new import_headers_polyfill4.Headers(requestInit.headers);
|
|
772
722
|
headers.set("x-msw-bypass", "true");
|
|
773
|
-
return
|
|
723
|
+
return {
|
|
724
|
+
...requestInit,
|
|
774
725
|
headers: headers.all()
|
|
775
|
-
}
|
|
726
|
+
};
|
|
776
727
|
};
|
|
777
728
|
var createFetchRequestParameters = (input) => {
|
|
778
729
|
const { body: body2, method } = input;
|
|
779
|
-
const requestParameters =
|
|
730
|
+
const requestParameters = {
|
|
731
|
+
...input,
|
|
780
732
|
body: void 0
|
|
781
|
-
}
|
|
733
|
+
};
|
|
782
734
|
if (["GET", "HEAD"].includes(method)) {
|
|
783
735
|
return requestParameters;
|
|
784
736
|
}
|
|
@@ -835,19 +787,21 @@ function getTimestamp() {
|
|
|
835
787
|
|
|
836
788
|
// src/utils/logging/prepareRequest.ts
|
|
837
789
|
function prepareRequest(request) {
|
|
838
|
-
return
|
|
790
|
+
return {
|
|
791
|
+
...request,
|
|
839
792
|
body: request.body,
|
|
840
793
|
headers: request.headers.all()
|
|
841
|
-
}
|
|
794
|
+
};
|
|
842
795
|
}
|
|
843
796
|
|
|
844
797
|
// src/utils/logging/prepareResponse.ts
|
|
845
798
|
var import_headers_polyfill5 = require("headers-polyfill");
|
|
846
799
|
function prepareResponse(res) {
|
|
847
800
|
const responseHeaders = (0, import_headers_polyfill5.objectToHeaders)(res.headers);
|
|
848
|
-
return
|
|
801
|
+
return {
|
|
802
|
+
...res,
|
|
849
803
|
body: parseBody(res.body, responseHeaders)
|
|
850
|
-
}
|
|
804
|
+
};
|
|
851
805
|
}
|
|
852
806
|
|
|
853
807
|
// src/utils/matching/matchRequestUrl.ts
|
|
@@ -891,13 +845,16 @@ function normalizePath(path, baseUrl) {
|
|
|
891
845
|
|
|
892
846
|
// src/utils/matching/matchRequestUrl.ts
|
|
893
847
|
function coercePath(path) {
|
|
894
|
-
return path.replace(
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
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}`;
|
|
898
856
|
}
|
|
899
|
-
|
|
900
|
-
}).replace(/([^\/])(:)(?=\d+)/, "$1\\$2").replace(/^([^\/]+)(:)(?=\/\/)/, "$1\\$2");
|
|
857
|
+
).replace(/([^\/])(:)(?=\d+)/, "$1\\$2").replace(/^([^\/]+)(:)(?=\/\/)/, "$1\\$2");
|
|
901
858
|
}
|
|
902
859
|
function matchRequestUrl(url, path, baseUrl) {
|
|
903
860
|
const normalizedPath = normalizePath(path, baseUrl);
|
|
@@ -946,11 +903,16 @@ var defaultResponse = {
|
|
|
946
903
|
var defaultResponseTransformers = [];
|
|
947
904
|
function createResponseComposition(responseOverrides, defaultTransformers = defaultResponseTransformers) {
|
|
948
905
|
return async (...transformers) => {
|
|
949
|
-
const initialResponse = Object.assign(
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
906
|
+
const initialResponse = Object.assign(
|
|
907
|
+
{},
|
|
908
|
+
defaultResponse,
|
|
909
|
+
{
|
|
910
|
+
headers: new import_headers_polyfill6.Headers({
|
|
911
|
+
"x-powered-by": "msw"
|
|
912
|
+
})
|
|
913
|
+
},
|
|
914
|
+
responseOverrides
|
|
915
|
+
);
|
|
954
916
|
const resolvedTransformers = [
|
|
955
917
|
...defaultTransformers,
|
|
956
918
|
...transformers
|
|
@@ -1006,15 +968,20 @@ var RequestHandler = class {
|
|
|
1006
968
|
this.ctx = options.ctx || defaultContext;
|
|
1007
969
|
this.resolver = options.resolver;
|
|
1008
970
|
const callFrame = getCallFrame(new Error());
|
|
1009
|
-
this.info =
|
|
971
|
+
this.info = {
|
|
972
|
+
...options.info,
|
|
1010
973
|
callFrame
|
|
1011
|
-
}
|
|
974
|
+
};
|
|
1012
975
|
}
|
|
1013
976
|
parse(_request, _resolutionContext) {
|
|
1014
977
|
return null;
|
|
1015
978
|
}
|
|
1016
979
|
test(request, resolutionContext) {
|
|
1017
|
-
return this.predicate(
|
|
980
|
+
return this.predicate(
|
|
981
|
+
request,
|
|
982
|
+
this.parse(request, resolutionContext),
|
|
983
|
+
resolutionContext
|
|
984
|
+
);
|
|
1018
985
|
}
|
|
1019
986
|
getPublicRequest(request, _parsedResult) {
|
|
1020
987
|
return request;
|
|
@@ -1027,14 +994,26 @@ var RequestHandler = class {
|
|
|
1027
994
|
return null;
|
|
1028
995
|
}
|
|
1029
996
|
const parsedResult = this.parse(request, resolutionContext);
|
|
1030
|
-
const shouldIntercept = this.predicate(
|
|
997
|
+
const shouldIntercept = this.predicate(
|
|
998
|
+
request,
|
|
999
|
+
parsedResult,
|
|
1000
|
+
resolutionContext
|
|
1001
|
+
);
|
|
1031
1002
|
if (!shouldIntercept) {
|
|
1032
1003
|
return null;
|
|
1033
1004
|
}
|
|
1034
1005
|
const publicRequest = this.getPublicRequest(request, parsedResult);
|
|
1035
1006
|
const executeResolver = this.wrapResolver(this.resolver);
|
|
1036
|
-
const mockedResponse = await executeResolver(
|
|
1037
|
-
|
|
1007
|
+
const mockedResponse = await executeResolver(
|
|
1008
|
+
publicRequest,
|
|
1009
|
+
response,
|
|
1010
|
+
this.ctx
|
|
1011
|
+
);
|
|
1012
|
+
return this.createExecutionResult(
|
|
1013
|
+
parsedResult,
|
|
1014
|
+
publicRequest,
|
|
1015
|
+
mockedResponse
|
|
1016
|
+
);
|
|
1038
1017
|
}
|
|
1039
1018
|
wrapResolver(resolver) {
|
|
1040
1019
|
return async (req, res, ctx) => {
|
|
@@ -1065,18 +1044,20 @@ var RequestHandler = class {
|
|
|
1065
1044
|
};
|
|
1066
1045
|
|
|
1067
1046
|
// src/handlers/RestHandler.ts
|
|
1068
|
-
var restContext =
|
|
1047
|
+
var restContext = {
|
|
1048
|
+
...defaultContext,
|
|
1069
1049
|
cookie,
|
|
1070
1050
|
body,
|
|
1071
1051
|
text,
|
|
1072
1052
|
json,
|
|
1073
1053
|
xml
|
|
1074
|
-
}
|
|
1054
|
+
};
|
|
1075
1055
|
var RestRequest = class extends MockedRequest {
|
|
1076
1056
|
constructor(request, params) {
|
|
1077
|
-
super(request.url,
|
|
1057
|
+
super(request.url, {
|
|
1058
|
+
...request,
|
|
1078
1059
|
body: request["_body"]
|
|
1079
|
-
})
|
|
1060
|
+
});
|
|
1080
1061
|
this.params = params;
|
|
1081
1062
|
this.id = request.id;
|
|
1082
1063
|
}
|
|
@@ -1108,10 +1089,16 @@ var RestHandler = class extends RequestHandler {
|
|
|
1108
1089
|
searchParams.forEach((_, paramName) => {
|
|
1109
1090
|
queryParams.push(paramName);
|
|
1110
1091
|
});
|
|
1111
|
-
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
|
+
);
|
|
1112
1095
|
}
|
|
1113
1096
|
parse(request, resolutionContext) {
|
|
1114
|
-
return matchRequestUrl(
|
|
1097
|
+
return matchRequestUrl(
|
|
1098
|
+
request.url,
|
|
1099
|
+
this.info.path,
|
|
1100
|
+
resolutionContext == null ? void 0 : resolutionContext.baseUrl
|
|
1101
|
+
);
|
|
1115
1102
|
}
|
|
1116
1103
|
getPublicRequest(request, parsedResult) {
|
|
1117
1104
|
return new RestRequest(request, parsedResult.params || {});
|
|
@@ -1125,7 +1112,15 @@ var RestHandler = class extends RequestHandler {
|
|
|
1125
1112
|
const loggedRequest = prepareRequest(request);
|
|
1126
1113
|
const loggedResponse = prepareResponse(response2);
|
|
1127
1114
|
const statusColor = getStatusCodeColor(response2.status);
|
|
1128
|
-
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
|
+
);
|
|
1129
1124
|
console.log("Request", loggedRequest);
|
|
1130
1125
|
console.log("Handler:", this);
|
|
1131
1126
|
console.log("Response", loggedResponse);
|
|
@@ -1144,10 +1139,33 @@ var field = (fieldName, fieldValue) => {
|
|
|
1144
1139
|
};
|
|
1145
1140
|
};
|
|
1146
1141
|
function validateFieldName(fieldName) {
|
|
1147
|
-
(0, import_outvariant3.invariant)(
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1142
|
+
(0, import_outvariant3.invariant)(
|
|
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
|
+
(0, import_outvariant3.invariant)(
|
|
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
|
+
(0, import_outvariant3.invariant)(
|
|
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
|
+
(0, import_outvariant3.invariant)(
|
|
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
|
+
);
|
|
1151
1169
|
}
|
|
1152
1170
|
|
|
1153
1171
|
// src/utils/internal/tryCatch.ts
|
|
@@ -1161,13 +1179,14 @@ function tryCatch(fn, onException) {
|
|
|
1161
1179
|
}
|
|
1162
1180
|
|
|
1163
1181
|
// src/handlers/GraphQLHandler.ts
|
|
1164
|
-
var graphqlContext =
|
|
1182
|
+
var graphqlContext = {
|
|
1183
|
+
...defaultContext,
|
|
1165
1184
|
data,
|
|
1166
1185
|
extensions,
|
|
1167
1186
|
errors,
|
|
1168
1187
|
cookie,
|
|
1169
1188
|
field
|
|
1170
|
-
}
|
|
1189
|
+
};
|
|
1171
1190
|
function isDocumentNode(value) {
|
|
1172
1191
|
if (value == null) {
|
|
1173
1192
|
return false;
|
|
@@ -1176,9 +1195,10 @@ function isDocumentNode(value) {
|
|
|
1176
1195
|
}
|
|
1177
1196
|
var GraphQLRequest = class extends MockedRequest {
|
|
1178
1197
|
constructor(request, variables) {
|
|
1179
|
-
super(request.url,
|
|
1198
|
+
super(request.url, {
|
|
1199
|
+
...request,
|
|
1180
1200
|
body: request["_body"]
|
|
1181
|
-
})
|
|
1201
|
+
});
|
|
1182
1202
|
this.variables = variables;
|
|
1183
1203
|
}
|
|
1184
1204
|
};
|
|
@@ -1188,10 +1208,14 @@ var GraphQLHandler = class extends RequestHandler {
|
|
|
1188
1208
|
if (isDocumentNode(operationName)) {
|
|
1189
1209
|
const parsedNode = parseDocumentNode(operationName);
|
|
1190
1210
|
if (parsedNode.operationType !== operationType) {
|
|
1191
|
-
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
|
+
);
|
|
1192
1214
|
}
|
|
1193
1215
|
if (!parsedNode.operationName) {
|
|
1194
|
-
throw new Error(
|
|
1216
|
+
throw new Error(
|
|
1217
|
+
`Failed to create a GraphQL handler: provided a DocumentNode with no operation name.`
|
|
1218
|
+
);
|
|
1195
1219
|
}
|
|
1196
1220
|
resolvedOperationName = parsedNode.operationName;
|
|
1197
1221
|
}
|
|
@@ -1208,7 +1232,10 @@ var GraphQLHandler = class extends RequestHandler {
|
|
|
1208
1232
|
this.endpoint = endpoint;
|
|
1209
1233
|
}
|
|
1210
1234
|
parse(request) {
|
|
1211
|
-
return tryCatch(
|
|
1235
|
+
return tryCatch(
|
|
1236
|
+
() => parseGraphQLRequest(request),
|
|
1237
|
+
(error2) => console.error(error2.message)
|
|
1238
|
+
);
|
|
1212
1239
|
}
|
|
1213
1240
|
getPublicRequest(request, parsedResult) {
|
|
1214
1241
|
return new GraphQLRequest(request, (parsedResult == null ? void 0 : parsedResult.variables) || {});
|
|
@@ -1221,7 +1248,7 @@ var GraphQLHandler = class extends RequestHandler {
|
|
|
1221
1248
|
const publicUrl = getPublicUrlFromRequest(request);
|
|
1222
1249
|
devUtils.warn(`Failed to intercept a GraphQL request at "${request.method} ${publicUrl}": anonymous GraphQL operations are not supported.
|
|
1223
1250
|
|
|
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 `);
|
|
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 `);
|
|
1225
1252
|
return false;
|
|
1226
1253
|
}
|
|
1227
1254
|
const hasMatchingUrl = matchRequestUrl(request.url, this.endpoint);
|
|
@@ -1234,7 +1261,14 @@ Consider naming this operation or using "graphql.operation" request handler to i
|
|
|
1234
1261
|
const loggedResponse = prepareResponse(response2);
|
|
1235
1262
|
const statusColor = getStatusCodeColor(response2.status);
|
|
1236
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}`;
|
|
1237
|
-
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
|
+
);
|
|
1238
1272
|
console.log("Request:", loggedRequest);
|
|
1239
1273
|
console.log("Handler:", this);
|
|
1240
1274
|
console.log("Response:", loggedResponse);
|
|
@@ -1247,18 +1281,21 @@ var MAX_MATCH_SCORE = 3;
|
|
|
1247
1281
|
var MAX_SUGGESTION_COUNT = 4;
|
|
1248
1282
|
var TYPE_MATCH_DELTA = 0.5;
|
|
1249
1283
|
function groupHandlersByType(handlers) {
|
|
1250
|
-
return handlers.reduce(
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
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: []
|
|
1256
1297
|
}
|
|
1257
|
-
|
|
1258
|
-
}, {
|
|
1259
|
-
rest: [],
|
|
1260
|
-
graphql: []
|
|
1261
|
-
});
|
|
1298
|
+
);
|
|
1262
1299
|
}
|
|
1263
1300
|
function getRestHandlerScore() {
|
|
1264
1301
|
return (request, handler) => {
|
|
@@ -1308,7 +1345,11 @@ function onUnhandledRequest(request, handlers, strategy = "warn") {
|
|
|
1308
1345
|
function generateHandlerSuggestion() {
|
|
1309
1346
|
const handlerGroups = groupHandlersByType(handlers);
|
|
1310
1347
|
const relevantHandlers = parsedGraphQLQuery ? handlerGroups.graphql : handlerGroups.rest;
|
|
1311
|
-
const suggestedHandlers = getSuggestedHandler(
|
|
1348
|
+
const suggestedHandlers = getSuggestedHandler(
|
|
1349
|
+
request,
|
|
1350
|
+
relevantHandlers,
|
|
1351
|
+
parsedGraphQLQuery ? getGraphQLHandlerScore(parsedGraphQLQuery) : getRestHandlerScore()
|
|
1352
|
+
);
|
|
1312
1353
|
return suggestedHandlers.length > 0 ? getSuggestedHandlersMessage(suggestedHandlers) : "";
|
|
1313
1354
|
}
|
|
1314
1355
|
function generateUnhandledRequestMessage() {
|
|
@@ -1329,7 +1370,11 @@ Read more: https://mswjs.io/docs/getting-started/mocks`
|
|
|
1329
1370
|
switch (strategy2) {
|
|
1330
1371
|
case "error": {
|
|
1331
1372
|
devUtils.error("Error: %s", message);
|
|
1332
|
-
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
|
+
);
|
|
1333
1378
|
}
|
|
1334
1379
|
case "warn": {
|
|
1335
1380
|
devUtils.warn("Warning: %s", message);
|
|
@@ -1338,7 +1383,12 @@ Read more: https://mswjs.io/docs/getting-started/mocks`
|
|
|
1338
1383
|
case "bypass":
|
|
1339
1384
|
break;
|
|
1340
1385
|
default:
|
|
1341
|
-
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
|
+
);
|
|
1342
1392
|
}
|
|
1343
1393
|
}
|
|
1344
1394
|
if (typeof strategy === "function") {
|
|
@@ -1354,7 +1404,7 @@ Read more: https://mswjs.io/docs/getting-started/mocks`
|
|
|
1354
1404
|
// src/utils/request/readResponseCookies.ts
|
|
1355
1405
|
var import_cookies2 = require("@mswjs/cookies");
|
|
1356
1406
|
function readResponseCookies(request, response2) {
|
|
1357
|
-
import_cookies2.store.add(
|
|
1407
|
+
import_cookies2.store.add({ ...request, url: request.url.toString() }, response2);
|
|
1358
1408
|
import_cookies2.store.persist();
|
|
1359
1409
|
}
|
|
1360
1410
|
|
|
@@ -1368,7 +1418,11 @@ async function handleRequest(request, handlers, options, emitter, handleRequestO
|
|
|
1368
1418
|
return;
|
|
1369
1419
|
}
|
|
1370
1420
|
const [lookupError, lookupResult] = await (0, import_until.until)(() => {
|
|
1371
|
-
return getResponse(
|
|
1421
|
+
return getResponse(
|
|
1422
|
+
request,
|
|
1423
|
+
handlers,
|
|
1424
|
+
handleRequestOptions == null ? void 0 : handleRequestOptions.resolutionContext
|
|
1425
|
+
);
|
|
1372
1426
|
});
|
|
1373
1427
|
if (lookupError) {
|
|
1374
1428
|
emitter.emit("unhandledException", lookupError, request);
|
|
@@ -1383,10 +1437,15 @@ async function handleRequest(request, handlers, options, emitter, handleRequestO
|
|
|
1383
1437
|
return;
|
|
1384
1438
|
}
|
|
1385
1439
|
if (!response2) {
|
|
1386
|
-
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.
|
|
1387
1442
|
|
|
1388
1443
|
\u2022 %s
|
|
1389
|
-
%s`,
|
|
1444
|
+
%s`,
|
|
1445
|
+
response2,
|
|
1446
|
+
handler.info.header,
|
|
1447
|
+
handler.info.callFrame
|
|
1448
|
+
);
|
|
1390
1449
|
emitter.emit("request:end", request);
|
|
1391
1450
|
(_c = handleRequestOptions == null ? void 0 : handleRequestOptions.onPassthroughResponse) == null ? void 0 : _c.call(handleRequestOptions, request);
|
|
1392
1451
|
return;
|
|
@@ -1400,7 +1459,11 @@ async function handleRequest(request, handlers, options, emitter, handleRequestO
|
|
|
1400
1459
|
emitter.emit("request:match", request);
|
|
1401
1460
|
const requiredLookupResult = lookupResult;
|
|
1402
1461
|
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(
|
|
1462
|
+
(_f = handleRequestOptions == null ? void 0 : handleRequestOptions.onMockedResponse) == null ? void 0 : _f.call(
|
|
1463
|
+
handleRequestOptions,
|
|
1464
|
+
transformedResponse,
|
|
1465
|
+
requiredLookupResult
|
|
1466
|
+
);
|
|
1404
1467
|
emitter.emit("request:end", request);
|
|
1405
1468
|
return transformedResponse;
|
|
1406
1469
|
}
|
|
@@ -1422,20 +1485,27 @@ var SetupServerApi = class extends SetupApi {
|
|
|
1422
1485
|
}
|
|
1423
1486
|
init() {
|
|
1424
1487
|
this.interceptor.on("request", async (request) => {
|
|
1425
|
-
const mockedRequest = new MockedRequest(request.url,
|
|
1488
|
+
const mockedRequest = new MockedRequest(request.url, {
|
|
1489
|
+
...request,
|
|
1426
1490
|
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
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
|
+
);
|
|
1439
1509
|
if (response2) {
|
|
1440
1510
|
if (response2.delay) {
|
|
1441
1511
|
await new Promise((resolve) => {
|
|
@@ -1458,9 +1528,20 @@ var SetupServerApi = class extends SetupApi {
|
|
|
1458
1528
|
});
|
|
1459
1529
|
}
|
|
1460
1530
|
listen(options = {}) {
|
|
1461
|
-
this.resolvedOptions = mergeRight(
|
|
1531
|
+
this.resolvedOptions = mergeRight(
|
|
1532
|
+
DEFAULT_LISTEN_OPTIONS,
|
|
1533
|
+
options
|
|
1534
|
+
);
|
|
1462
1535
|
this.interceptor.apply();
|
|
1463
|
-
(0, import_outvariant4.invariant)(
|
|
1536
|
+
(0, import_outvariant4.invariant)(
|
|
1537
|
+
[import_interceptors2.InterceptorReadyState.APPLYING, import_interceptors2.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
|
+
);
|
|
1464
1545
|
}
|
|
1465
1546
|
printHandlers() {
|
|
1466
1547
|
const handlers = this.listHandlers();
|