msw 0.41.1 → 0.42.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/lib/{glossary-eda04a15.d.ts → glossary-58eca5a8.d.ts} +50 -49
- package/lib/iife/index.js +2045 -907
- package/lib/iife/index.js.map +1 -1
- package/lib/index.d.ts +22 -22
- package/lib/index.js +38 -288
- 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 +22 -250
- package/lib/native/index.mjs +25 -266
- package/lib/node/index.d.ts +2 -2
- package/lib/node/index.js +26 -315
- package/lib/node/index.js.map +1 -1
- package/lib/node/index.mjs +27 -331
- package/lib/node/index.mjs.map +1 -1
- package/package.json +3 -4
- package/lib/esm/index.js +0 -2109
- package/lib/esm/index.js.map +0 -1
package/lib/mockServiceWorker.js
CHANGED
package/lib/native/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { b as RequestHandler, i as RequestHandlerDefaultInfo, M as MockedRequest, c as DefaultBodyType, z as SetupServerApi } from '../glossary-
|
|
1
|
+
import { b as RequestHandler, i as RequestHandlerDefaultInfo, M as MockedRequest, c as DefaultBodyType, z as SetupServerApi } from '../glossary-58eca5a8.js';
|
|
2
2
|
import 'type-fest';
|
|
3
3
|
import '@mswjs/interceptors';
|
|
4
4
|
import 'headers-polyfill';
|
package/lib/native/index.js
CHANGED
|
@@ -33,12 +33,6 @@ var __objRest = (source, exclude) => {
|
|
|
33
33
|
}
|
|
34
34
|
return target;
|
|
35
35
|
};
|
|
36
|
-
var __esm = (fn, res) => function __init() {
|
|
37
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
38
|
-
};
|
|
39
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
40
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
41
|
-
};
|
|
42
36
|
var __export = (target, all) => {
|
|
43
37
|
for (var name in all)
|
|
44
38
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -54,182 +48,21 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
54
48
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
55
49
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
56
50
|
|
|
57
|
-
// node_modules/tsup/assets/cjs_shims.js
|
|
58
|
-
var init_cjs_shims = __esm({
|
|
59
|
-
"node_modules/tsup/assets/cjs_shims.js"() {
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
// node_modules/outvariant/lib/format.js
|
|
64
|
-
var require_format = __commonJS({
|
|
65
|
-
"node_modules/outvariant/lib/format.js"(exports) {
|
|
66
|
-
"use strict";
|
|
67
|
-
init_cjs_shims();
|
|
68
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
69
|
-
exports.format = void 0;
|
|
70
|
-
var POSITIONALS_EXP = /(%?)(%([sdjo]))/g;
|
|
71
|
-
function serializePositional(positional, flag) {
|
|
72
|
-
switch (flag) {
|
|
73
|
-
case "s":
|
|
74
|
-
return positional;
|
|
75
|
-
case "d":
|
|
76
|
-
case "i":
|
|
77
|
-
return Number(positional);
|
|
78
|
-
case "j":
|
|
79
|
-
return JSON.stringify(positional);
|
|
80
|
-
case "o": {
|
|
81
|
-
if (typeof positional === "string") {
|
|
82
|
-
return positional;
|
|
83
|
-
}
|
|
84
|
-
var json2 = JSON.stringify(positional);
|
|
85
|
-
if (json2 === "{}" || json2 === "[]" || /^\[object .+?\]$/.test(json2)) {
|
|
86
|
-
return positional;
|
|
87
|
-
}
|
|
88
|
-
return json2;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
function format2(message) {
|
|
93
|
-
var positionals = [];
|
|
94
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
95
|
-
positionals[_i - 1] = arguments[_i];
|
|
96
|
-
}
|
|
97
|
-
if (positionals.length === 0) {
|
|
98
|
-
return message;
|
|
99
|
-
}
|
|
100
|
-
var positionalIndex = 0;
|
|
101
|
-
var formattedMessage = message.replace(POSITIONALS_EXP, function(match2, isEscaped, _, flag) {
|
|
102
|
-
var positional = positionals[positionalIndex];
|
|
103
|
-
var value = serializePositional(positional, flag);
|
|
104
|
-
if (!isEscaped) {
|
|
105
|
-
positionalIndex++;
|
|
106
|
-
return value;
|
|
107
|
-
}
|
|
108
|
-
return match2;
|
|
109
|
-
});
|
|
110
|
-
if (positionalIndex < positionals.length) {
|
|
111
|
-
formattedMessage += " " + positionals.slice(positionalIndex).join(" ");
|
|
112
|
-
}
|
|
113
|
-
formattedMessage = formattedMessage.replace(/%{2,2}/g, "%");
|
|
114
|
-
return formattedMessage;
|
|
115
|
-
}
|
|
116
|
-
exports.format = format2;
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
// node_modules/outvariant/lib/invariant.js
|
|
121
|
-
var require_invariant = __commonJS({
|
|
122
|
-
"node_modules/outvariant/lib/invariant.js"(exports) {
|
|
123
|
-
"use strict";
|
|
124
|
-
init_cjs_shims();
|
|
125
|
-
var __extends = exports && exports.__extends || function() {
|
|
126
|
-
var extendStatics = function(d, b) {
|
|
127
|
-
extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
|
|
128
|
-
d2.__proto__ = b2;
|
|
129
|
-
} || function(d2, b2) {
|
|
130
|
-
for (var p in b2)
|
|
131
|
-
if (Object.prototype.hasOwnProperty.call(b2, p))
|
|
132
|
-
d2[p] = b2[p];
|
|
133
|
-
};
|
|
134
|
-
return extendStatics(d, b);
|
|
135
|
-
};
|
|
136
|
-
return function(d, b) {
|
|
137
|
-
if (typeof b !== "function" && b !== null)
|
|
138
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
139
|
-
extendStatics(d, b);
|
|
140
|
-
function __() {
|
|
141
|
-
this.constructor = d;
|
|
142
|
-
}
|
|
143
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
144
|
-
};
|
|
145
|
-
}();
|
|
146
|
-
var __spreadArray = exports && exports.__spreadArray || function(to, from) {
|
|
147
|
-
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
148
|
-
to[j] = from[i];
|
|
149
|
-
return to;
|
|
150
|
-
};
|
|
151
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
152
|
-
exports.invariant = exports.InvariantError = void 0;
|
|
153
|
-
var format_1 = require_format();
|
|
154
|
-
var STACK_FRAMES_TO_IGNORE = 2;
|
|
155
|
-
var InvariantError = function(_super) {
|
|
156
|
-
__extends(InvariantError2, _super);
|
|
157
|
-
function InvariantError2(message) {
|
|
158
|
-
var positionals = [];
|
|
159
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
160
|
-
positionals[_i - 1] = arguments[_i];
|
|
161
|
-
}
|
|
162
|
-
var _this = _super.call(this, message) || this;
|
|
163
|
-
_this.name = "Invariant Violation";
|
|
164
|
-
_this.message = format_1.format.apply(void 0, __spreadArray([message], positionals));
|
|
165
|
-
if (_this.stack) {
|
|
166
|
-
var nextStack = _this.stack.split("\n");
|
|
167
|
-
nextStack.splice(1, STACK_FRAMES_TO_IGNORE);
|
|
168
|
-
_this.stack = nextStack.join("\n");
|
|
169
|
-
}
|
|
170
|
-
return _this;
|
|
171
|
-
}
|
|
172
|
-
return InvariantError2;
|
|
173
|
-
}(Error);
|
|
174
|
-
exports.InvariantError = InvariantError;
|
|
175
|
-
function invariant(predicate, message) {
|
|
176
|
-
var positionals = [];
|
|
177
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
178
|
-
positionals[_i - 2] = arguments[_i];
|
|
179
|
-
}
|
|
180
|
-
if (!predicate) {
|
|
181
|
-
throw new (InvariantError.bind.apply(InvariantError, __spreadArray([void 0, message], positionals)))();
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
exports.invariant = invariant;
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
// node_modules/outvariant/lib/index.js
|
|
189
|
-
var require_lib = __commonJS({
|
|
190
|
-
"node_modules/outvariant/lib/index.js"(exports) {
|
|
191
|
-
"use strict";
|
|
192
|
-
init_cjs_shims();
|
|
193
|
-
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
194
|
-
if (k2 === void 0)
|
|
195
|
-
k2 = k;
|
|
196
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() {
|
|
197
|
-
return m[k];
|
|
198
|
-
} });
|
|
199
|
-
} : function(o, m, k, k2) {
|
|
200
|
-
if (k2 === void 0)
|
|
201
|
-
k2 = k;
|
|
202
|
-
o[k2] = m[k];
|
|
203
|
-
});
|
|
204
|
-
var __exportStar = exports && exports.__exportStar || function(m, exports2) {
|
|
205
|
-
for (var p in m)
|
|
206
|
-
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p))
|
|
207
|
-
__createBinding(exports2, m, p);
|
|
208
|
-
};
|
|
209
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
210
|
-
__exportStar(require_invariant(), exports);
|
|
211
|
-
__exportStar(require_format(), exports);
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
|
|
215
51
|
// src/native/index.ts
|
|
216
52
|
var native_exports = {};
|
|
217
53
|
__export(native_exports, {
|
|
218
54
|
setupServer: () => setupServer
|
|
219
55
|
});
|
|
220
56
|
module.exports = __toCommonJS(native_exports);
|
|
221
|
-
init_cjs_shims();
|
|
222
57
|
var import_XMLHttpRequest = require("@mswjs/interceptors/lib/interceptors/XMLHttpRequest");
|
|
223
58
|
|
|
224
59
|
// src/node/createSetupServer.ts
|
|
225
|
-
init_cjs_shims();
|
|
226
60
|
var import_chalk = require("chalk");
|
|
227
61
|
var import_is_node_process3 = require("is-node-process");
|
|
228
62
|
var import_strict_event_emitter = require("strict-event-emitter");
|
|
229
63
|
var import_interceptors = require("@mswjs/interceptors");
|
|
230
64
|
|
|
231
65
|
// src/utils/internal/requestHandlerUtils.ts
|
|
232
|
-
init_cjs_shims();
|
|
233
66
|
function use(currentHandlers, ...handlers) {
|
|
234
67
|
currentHandlers.unshift(...handlers);
|
|
235
68
|
}
|
|
@@ -242,19 +75,13 @@ function resetHandlers(initialHandlers, ...nextHandlers) {
|
|
|
242
75
|
return nextHandlers.length > 0 ? [...nextHandlers] : [...initialHandlers];
|
|
243
76
|
}
|
|
244
77
|
|
|
245
|
-
// src/utils/request/parseIsomorphicRequest.ts
|
|
246
|
-
init_cjs_shims();
|
|
247
|
-
|
|
248
78
|
// src/handlers/RequestHandler.ts
|
|
249
|
-
init_cjs_shims();
|
|
250
79
|
var import_headers_polyfill4 = require("headers-polyfill");
|
|
251
80
|
|
|
252
81
|
// src/response.ts
|
|
253
|
-
init_cjs_shims();
|
|
254
82
|
var import_headers_polyfill = require("headers-polyfill");
|
|
255
83
|
|
|
256
84
|
// src/utils/internal/compose.ts
|
|
257
|
-
init_cjs_shims();
|
|
258
85
|
function compose(...fns) {
|
|
259
86
|
return (...args) => {
|
|
260
87
|
return fns.reduceRight((leftFn, rightFn) => {
|
|
@@ -264,7 +91,6 @@ function compose(...fns) {
|
|
|
264
91
|
}
|
|
265
92
|
|
|
266
93
|
// src/utils/NetworkError.ts
|
|
267
|
-
init_cjs_shims();
|
|
268
94
|
var NetworkError = class extends Error {
|
|
269
95
|
constructor(message) {
|
|
270
96
|
super(message);
|
|
@@ -305,7 +131,6 @@ var response = Object.assign(createResponseComposition(), {
|
|
|
305
131
|
});
|
|
306
132
|
|
|
307
133
|
// src/utils/internal/getCallFrame.ts
|
|
308
|
-
init_cjs_shims();
|
|
309
134
|
var SOURCE_FRAME = /\/msw\/src\/(.+)/;
|
|
310
135
|
var BUILD_FRAME = /(node_modules)?[\/\\]lib[\/\\](umd|esm|iief|cjs)[\/\\]|^[^\/\\]*$/;
|
|
311
136
|
function getCallFrame(error2) {
|
|
@@ -325,7 +150,6 @@ function getCallFrame(error2) {
|
|
|
325
150
|
}
|
|
326
151
|
|
|
327
152
|
// src/utils/internal/isIterable.ts
|
|
328
|
-
init_cjs_shims();
|
|
329
153
|
function isIterable(fn) {
|
|
330
154
|
if (!fn) {
|
|
331
155
|
return false;
|
|
@@ -334,7 +158,6 @@ function isIterable(fn) {
|
|
|
334
158
|
}
|
|
335
159
|
|
|
336
160
|
// src/context/status.ts
|
|
337
|
-
init_cjs_shims();
|
|
338
161
|
var import_codes = __toESM(require("statuses/codes.json"));
|
|
339
162
|
var status = (statusCode, statusText) => {
|
|
340
163
|
return (res) => {
|
|
@@ -345,7 +168,6 @@ var status = (statusCode, statusText) => {
|
|
|
345
168
|
};
|
|
346
169
|
|
|
347
170
|
// src/context/set.ts
|
|
348
|
-
init_cjs_shims();
|
|
349
171
|
var import_headers_polyfill2 = require("headers-polyfill");
|
|
350
172
|
function set(...args) {
|
|
351
173
|
return (res) => {
|
|
@@ -363,7 +185,6 @@ function set(...args) {
|
|
|
363
185
|
}
|
|
364
186
|
|
|
365
187
|
// src/context/delay.ts
|
|
366
|
-
init_cjs_shims();
|
|
367
188
|
var import_is_node_process = require("is-node-process");
|
|
368
189
|
var SET_TIMEOUT_MAX_ALLOWED_INT = 2147483647;
|
|
369
190
|
var MIN_SERVER_RESPONSE_TIME = 100;
|
|
@@ -406,7 +227,6 @@ var delay = (durationOrMode) => {
|
|
|
406
227
|
};
|
|
407
228
|
|
|
408
229
|
// src/context/fetch.ts
|
|
409
|
-
init_cjs_shims();
|
|
410
230
|
var import_is_node_process2 = require("is-node-process");
|
|
411
231
|
var import_headers_polyfill3 = require("headers-polyfill");
|
|
412
232
|
var useFetch = (0, import_is_node_process2.isNodeProcess)() ? require("node-fetch") : window.fetch;
|
|
@@ -522,11 +342,7 @@ function passthrough() {
|
|
|
522
342
|
};
|
|
523
343
|
}
|
|
524
344
|
|
|
525
|
-
// src/utils/request/parseBody.ts
|
|
526
|
-
init_cjs_shims();
|
|
527
|
-
|
|
528
345
|
// src/utils/internal/jsonParse.ts
|
|
529
|
-
init_cjs_shims();
|
|
530
346
|
function jsonParse(value) {
|
|
531
347
|
try {
|
|
532
348
|
return JSON.parse(value);
|
|
@@ -536,7 +352,6 @@ function jsonParse(value) {
|
|
|
536
352
|
}
|
|
537
353
|
|
|
538
354
|
// src/utils/internal/parseMultipartData.ts
|
|
539
|
-
init_cjs_shims();
|
|
540
355
|
var import_headers_polyfill5 = require("headers-polyfill");
|
|
541
356
|
function parseContentHeaders(headersString) {
|
|
542
357
|
var _a, _b;
|
|
@@ -615,12 +430,10 @@ function parseBody(body2, headers) {
|
|
|
615
430
|
}
|
|
616
431
|
|
|
617
432
|
// src/utils/request/setRequestCookies.ts
|
|
618
|
-
init_cjs_shims();
|
|
619
433
|
var cookieUtils2 = __toESM(require("cookie"));
|
|
620
434
|
var import_cookies = require("@mswjs/cookies");
|
|
621
435
|
|
|
622
436
|
// src/utils/request/getRequestCookies.ts
|
|
623
|
-
init_cjs_shims();
|
|
624
437
|
var cookieUtils = __toESM(require("cookie"));
|
|
625
438
|
function getAllCookies() {
|
|
626
439
|
return cookieUtils.parse(document.cookie);
|
|
@@ -685,11 +498,9 @@ function parseIsomorphicRequest(request) {
|
|
|
685
498
|
}
|
|
686
499
|
|
|
687
500
|
// src/utils/handleRequest.ts
|
|
688
|
-
init_cjs_shims();
|
|
689
501
|
var import_until = require("@open-draft/until");
|
|
690
502
|
|
|
691
503
|
// src/utils/getResponse.ts
|
|
692
|
-
init_cjs_shims();
|
|
693
504
|
var getResponse = async (request, handlers, resolutionContext) => {
|
|
694
505
|
const relevantHandlers = handlers.filter((handler) => {
|
|
695
506
|
return handler.test(request, resolutionContext);
|
|
@@ -737,8 +548,7 @@ var getResponse = async (request, handlers, resolutionContext) => {
|
|
|
737
548
|
};
|
|
738
549
|
|
|
739
550
|
// src/utils/internal/devUtils.ts
|
|
740
|
-
|
|
741
|
-
var import_outvariant = __toESM(require_lib());
|
|
551
|
+
var import_outvariant = require("outvariant");
|
|
742
552
|
var LIBRARY_PREFIX = "[MSW]";
|
|
743
553
|
function formatMessage(message, ...positionals) {
|
|
744
554
|
const interpolatedMessage = (0, import_outvariant.format)(message, ...positionals);
|
|
@@ -757,15 +567,12 @@ var devUtils = {
|
|
|
757
567
|
};
|
|
758
568
|
|
|
759
569
|
// src/utils/request/onUnhandledRequest.ts
|
|
760
|
-
init_cjs_shims();
|
|
761
570
|
var import_js_levenshtein = __toESM(require("js-levenshtein"));
|
|
762
571
|
|
|
763
572
|
// src/utils/internal/parseGraphQLRequest.ts
|
|
764
|
-
init_cjs_shims();
|
|
765
573
|
var import_graphql = require("graphql");
|
|
766
574
|
|
|
767
575
|
// src/utils/request/getPublicUrlFromRequest.ts
|
|
768
|
-
init_cjs_shims();
|
|
769
576
|
var getPublicUrlFromRequest = (request) => {
|
|
770
577
|
return request.referrer.startsWith(request.url.origin) ? request.url.pathname : new URL(request.url.pathname, `${request.url.protocol}//${request.url.host}`).href;
|
|
771
578
|
};
|
|
@@ -866,19 +673,11 @@ function parseGraphQLRequest(request) {
|
|
|
866
673
|
}
|
|
867
674
|
|
|
868
675
|
// src/utils/internal/isStringEqual.ts
|
|
869
|
-
init_cjs_shims();
|
|
870
676
|
function isStringEqual(actual, expected) {
|
|
871
677
|
return actual.toLowerCase() === expected.toLowerCase();
|
|
872
678
|
}
|
|
873
679
|
|
|
874
|
-
// src/handlers/RestHandler.ts
|
|
875
|
-
init_cjs_shims();
|
|
876
|
-
|
|
877
|
-
// src/context/index.ts
|
|
878
|
-
init_cjs_shims();
|
|
879
|
-
|
|
880
680
|
// src/context/cookie.ts
|
|
881
|
-
init_cjs_shims();
|
|
882
681
|
var cookieUtils3 = __toESM(require("cookie"));
|
|
883
682
|
var cookie = (name, value, options) => {
|
|
884
683
|
return (res) => {
|
|
@@ -892,7 +691,6 @@ var cookie = (name, value, options) => {
|
|
|
892
691
|
};
|
|
893
692
|
|
|
894
693
|
// src/context/body.ts
|
|
895
|
-
init_cjs_shims();
|
|
896
694
|
var body = (value) => {
|
|
897
695
|
return (res) => {
|
|
898
696
|
res.body = value;
|
|
@@ -900,14 +698,7 @@ var body = (value) => {
|
|
|
900
698
|
};
|
|
901
699
|
};
|
|
902
700
|
|
|
903
|
-
// src/context/data.ts
|
|
904
|
-
init_cjs_shims();
|
|
905
|
-
|
|
906
|
-
// src/utils/internal/mergeRight.ts
|
|
907
|
-
init_cjs_shims();
|
|
908
|
-
|
|
909
701
|
// src/utils/internal/isObject.ts
|
|
910
|
-
init_cjs_shims();
|
|
911
702
|
function isObject(value) {
|
|
912
703
|
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
913
704
|
}
|
|
@@ -930,7 +721,6 @@ function mergeRight(left, right) {
|
|
|
930
721
|
}
|
|
931
722
|
|
|
932
723
|
// src/context/json.ts
|
|
933
|
-
init_cjs_shims();
|
|
934
724
|
var json = (body2) => {
|
|
935
725
|
return (res) => {
|
|
936
726
|
res.headers.set("Content-Type", "application/json");
|
|
@@ -949,7 +739,6 @@ var data = (payload) => {
|
|
|
949
739
|
};
|
|
950
740
|
|
|
951
741
|
// src/context/extensions.ts
|
|
952
|
-
init_cjs_shims();
|
|
953
742
|
var extensions = (payload) => {
|
|
954
743
|
return (res) => {
|
|
955
744
|
const prevBody = jsonParse(res.body) || {};
|
|
@@ -959,7 +748,6 @@ var extensions = (payload) => {
|
|
|
959
748
|
};
|
|
960
749
|
|
|
961
750
|
// src/context/errors.ts
|
|
962
|
-
init_cjs_shims();
|
|
963
751
|
var errors = (errorsList) => {
|
|
964
752
|
return (res) => {
|
|
965
753
|
if (errorsList == null) {
|
|
@@ -972,7 +760,6 @@ var errors = (errorsList) => {
|
|
|
972
760
|
};
|
|
973
761
|
|
|
974
762
|
// src/context/text.ts
|
|
975
|
-
init_cjs_shims();
|
|
976
763
|
var text = (body2) => {
|
|
977
764
|
return (res) => {
|
|
978
765
|
res.headers.set("Content-Type", "text/plain");
|
|
@@ -982,7 +769,6 @@ var text = (body2) => {
|
|
|
982
769
|
};
|
|
983
770
|
|
|
984
771
|
// src/context/xml.ts
|
|
985
|
-
init_cjs_shims();
|
|
986
772
|
var xml = (body2) => {
|
|
987
773
|
return (res) => {
|
|
988
774
|
res.headers.set("Content-Type", "text/xml");
|
|
@@ -992,7 +778,6 @@ var xml = (body2) => {
|
|
|
992
778
|
};
|
|
993
779
|
|
|
994
780
|
// src/utils/logging/getStatusCodeColor.ts
|
|
995
|
-
init_cjs_shims();
|
|
996
781
|
function getStatusCodeColor(status2) {
|
|
997
782
|
if (status2 < 300) {
|
|
998
783
|
return "#69AB32" /* Success */;
|
|
@@ -1004,14 +789,12 @@ function getStatusCodeColor(status2) {
|
|
|
1004
789
|
}
|
|
1005
790
|
|
|
1006
791
|
// src/utils/logging/getTimestamp.ts
|
|
1007
|
-
init_cjs_shims();
|
|
1008
792
|
function getTimestamp() {
|
|
1009
793
|
const now = new Date();
|
|
1010
794
|
return [now.getHours(), now.getMinutes(), now.getSeconds()].map(String).map((chunk) => chunk.slice(0, 2)).map((chunk) => chunk.padStart(2, "0")).join(":");
|
|
1011
795
|
}
|
|
1012
796
|
|
|
1013
797
|
// src/utils/logging/prepareRequest.ts
|
|
1014
|
-
init_cjs_shims();
|
|
1015
798
|
function prepareRequest(request) {
|
|
1016
799
|
return __spreadProps(__spreadValues({}, request), {
|
|
1017
800
|
headers: request.headers.all()
|
|
@@ -1019,7 +802,6 @@ function prepareRequest(request) {
|
|
|
1019
802
|
}
|
|
1020
803
|
|
|
1021
804
|
// src/utils/logging/prepareResponse.ts
|
|
1022
|
-
init_cjs_shims();
|
|
1023
805
|
var import_headers_polyfill6 = require("headers-polyfill");
|
|
1024
806
|
function prepareResponse(res) {
|
|
1025
807
|
const responseHeaders = (0, import_headers_polyfill6.objectToHeaders)(res.headers);
|
|
@@ -1029,15 +811,10 @@ function prepareResponse(res) {
|
|
|
1029
811
|
}
|
|
1030
812
|
|
|
1031
813
|
// src/utils/matching/matchRequestUrl.ts
|
|
1032
|
-
init_cjs_shims();
|
|
1033
814
|
var import_path_to_regexp = require("path-to-regexp");
|
|
1034
815
|
var import_getCleanUrl = require("@mswjs/interceptors/lib/utils/getCleanUrl");
|
|
1035
816
|
|
|
1036
|
-
// src/utils/matching/normalizePath.ts
|
|
1037
|
-
init_cjs_shims();
|
|
1038
|
-
|
|
1039
817
|
// src/utils/url/cleanUrl.ts
|
|
1040
|
-
init_cjs_shims();
|
|
1041
818
|
var REDUNDANT_CHARACTERS_EXP = /[\?|#].*$/g;
|
|
1042
819
|
function getSearchParams(path) {
|
|
1043
820
|
return new URL(`/${path}`, "http://localhost").searchParams;
|
|
@@ -1046,11 +823,7 @@ function cleanUrl(path) {
|
|
|
1046
823
|
return path.replace(REDUNDANT_CHARACTERS_EXP, "");
|
|
1047
824
|
}
|
|
1048
825
|
|
|
1049
|
-
// src/utils/url/getAbsoluteUrl.ts
|
|
1050
|
-
init_cjs_shims();
|
|
1051
|
-
|
|
1052
826
|
// src/utils/url/isAbsoluteUrl.ts
|
|
1053
|
-
init_cjs_shims();
|
|
1054
827
|
function isAbsoluteUrl(url) {
|
|
1055
828
|
return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url);
|
|
1056
829
|
}
|
|
@@ -1163,11 +936,7 @@ var RestHandler = class extends RequestHandler {
|
|
|
1163
936
|
}
|
|
1164
937
|
};
|
|
1165
938
|
|
|
1166
|
-
// src/handlers/GraphQLHandler.ts
|
|
1167
|
-
init_cjs_shims();
|
|
1168
|
-
|
|
1169
939
|
// src/utils/internal/tryCatch.ts
|
|
1170
|
-
init_cjs_shims();
|
|
1171
940
|
function tryCatch(fn, onException) {
|
|
1172
941
|
try {
|
|
1173
942
|
const result = fn();
|
|
@@ -1362,7 +1131,6 @@ Read more: https://mswjs.io/docs/getting-started/mocks`
|
|
|
1362
1131
|
}
|
|
1363
1132
|
|
|
1364
1133
|
// src/utils/request/readResponseCookies.ts
|
|
1365
|
-
init_cjs_shims();
|
|
1366
1134
|
var import_cookies2 = require("@mswjs/cookies");
|
|
1367
1135
|
function readResponseCookies(request, response2) {
|
|
1368
1136
|
import_cookies2.store.add(__spreadProps(__spreadValues({}, request), { url: request.url.toString() }), response2);
|
|
@@ -1424,7 +1192,6 @@ async function handleRequest(request, handlers, options, emitter, handleRequestO
|
|
|
1424
1192
|
}
|
|
1425
1193
|
|
|
1426
1194
|
// src/utils/internal/pipeEvents.ts
|
|
1427
|
-
init_cjs_shims();
|
|
1428
1195
|
function pipeEvents(source, destination) {
|
|
1429
1196
|
const rawEmit = source.emit;
|
|
1430
1197
|
if (rawEmit._isPiped) {
|
|
@@ -1455,21 +1222,26 @@ function createSetupServer(...interceptors) {
|
|
|
1455
1222
|
throw new Error(devUtils.formatMessage("Failed to execute `setupServer` in the environment that is not Node.js (i.e. a browser). Consider using `setupWorker` instead."));
|
|
1456
1223
|
}
|
|
1457
1224
|
let resolvedOptions = {};
|
|
1458
|
-
const interceptor =
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1225
|
+
const interceptor = new import_interceptors.BatchInterceptor({
|
|
1226
|
+
name: "setup-server",
|
|
1227
|
+
interceptors
|
|
1228
|
+
});
|
|
1229
|
+
interceptor.on("request", async function setupServerListener(request) {
|
|
1230
|
+
const mockedRequest = parseIsomorphicRequest(request);
|
|
1231
|
+
const response2 = await handleRequest(mockedRequest, currentHandlers, resolvedOptions, emitter, {
|
|
1232
|
+
transformResponse(response3) {
|
|
1233
|
+
return {
|
|
1234
|
+
status: response3.status,
|
|
1235
|
+
statusText: response3.statusText,
|
|
1236
|
+
headers: response3.headers.all(),
|
|
1237
|
+
body: response3.body
|
|
1238
|
+
};
|
|
1239
|
+
}
|
|
1240
|
+
});
|
|
1241
|
+
if (response2) {
|
|
1242
|
+
request.respondWith(response2);
|
|
1472
1243
|
}
|
|
1244
|
+
return;
|
|
1473
1245
|
});
|
|
1474
1246
|
interceptor.on("response", (request, response2) => {
|
|
1475
1247
|
if (!request.id) {
|
|
@@ -1518,14 +1290,14 @@ function createSetupServer(...interceptors) {
|
|
|
1518
1290
|
close() {
|
|
1519
1291
|
emitter.removeAllListeners();
|
|
1520
1292
|
publicEmitter.removeAllListeners();
|
|
1521
|
-
interceptor.
|
|
1293
|
+
interceptor.dispose();
|
|
1522
1294
|
}
|
|
1523
1295
|
};
|
|
1524
1296
|
};
|
|
1525
1297
|
}
|
|
1526
1298
|
|
|
1527
1299
|
// src/native/index.ts
|
|
1528
|
-
var setupServer = createSetupServer(import_XMLHttpRequest.
|
|
1300
|
+
var setupServer = createSetupServer(new import_XMLHttpRequest.XMLHttpRequestInterceptor());
|
|
1529
1301
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1530
1302
|
0 && (module.exports = {
|
|
1531
1303
|
setupServer
|