msw 0.47.3 → 0.48.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-dc3fd077.d.ts → SetupApi-75fbec12.d.ts} +20 -41
- package/lib/SetupServerApi-49722346.d.ts +20 -0
- package/lib/glossary-a22f5c13.d.ts +45 -0
- package/lib/iife/index.js +2684 -2641
- package/lib/iife/index.js.map +1 -1
- package/lib/index.d.ts +19 -8
- package/lib/index.js +163 -146
- package/lib/index.js.map +1 -1
- package/lib/mockServiceWorker.js +3 -3
- package/lib/native/index.d.ts +10 -5
- package/lib/native/index.js +340 -332
- package/lib/native/index.mjs +353 -331
- package/lib/node/index.d.ts +8 -6
- package/lib/node/index.js +341 -335
- package/lib/node/index.js.map +1 -1
- package/lib/node/index.mjs +369 -349
- package/lib/node/index.mjs.map +1 -1
- package/package.json +7 -4
package/lib/node/index.mjs
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
5
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
7
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
9
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
10
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
11
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -36,36 +40,316 @@ var __objRest = (source, exclude) => {
|
|
|
36
40
|
}
|
|
37
41
|
return target;
|
|
38
42
|
};
|
|
43
|
+
var __copyProps = (to, from, except, desc) => {
|
|
44
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
45
|
+
for (let key of __getOwnPropNames(from))
|
|
46
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
47
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
48
|
+
}
|
|
49
|
+
return to;
|
|
50
|
+
};
|
|
51
|
+
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));
|
|
39
52
|
|
|
40
53
|
// config/polyfills-node.ts
|
|
41
54
|
import { setTimeout as nodeSetTimeout } from "timers";
|
|
42
55
|
var setTimeout = nodeSetTimeout;
|
|
43
56
|
|
|
44
|
-
// src/node/
|
|
45
|
-
import
|
|
46
|
-
import {
|
|
47
|
-
|
|
48
|
-
// src/node/createSetupServer.ts
|
|
49
|
-
import { bold } from "chalk";
|
|
50
|
-
import { isNodeProcess as isNodeProcess3 } from "is-node-process";
|
|
51
|
-
import { StrictEventEmitter } from "strict-event-emitter";
|
|
57
|
+
// src/node/SetupServerApi.ts
|
|
58
|
+
import chalk from "chalk";
|
|
59
|
+
import { invariant as invariant3 } from "outvariant";
|
|
52
60
|
import {
|
|
53
|
-
BatchInterceptor
|
|
61
|
+
BatchInterceptor,
|
|
62
|
+
InterceptorReadyState
|
|
54
63
|
} from "@mswjs/interceptors";
|
|
55
64
|
|
|
56
|
-
// src/
|
|
57
|
-
|
|
58
|
-
|
|
65
|
+
// src/SetupApi.ts
|
|
66
|
+
import { invariant } from "outvariant";
|
|
67
|
+
import { StrictEventEmitter } from "strict-event-emitter";
|
|
68
|
+
|
|
69
|
+
// src/utils/internal/devUtils.ts
|
|
70
|
+
import { format } from "outvariant";
|
|
71
|
+
var LIBRARY_PREFIX = "[MSW]";
|
|
72
|
+
function formatMessage(message, ...positionals) {
|
|
73
|
+
const interpolatedMessage = format(message, ...positionals);
|
|
74
|
+
return `${LIBRARY_PREFIX} ${interpolatedMessage}`;
|
|
59
75
|
}
|
|
60
|
-
function
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
76
|
+
function warn(message, ...positionals) {
|
|
77
|
+
console.warn(formatMessage(message, ...positionals));
|
|
78
|
+
}
|
|
79
|
+
function error(message, ...positionals) {
|
|
80
|
+
console.error(formatMessage(message, ...positionals));
|
|
81
|
+
}
|
|
82
|
+
var devUtils = {
|
|
83
|
+
formatMessage,
|
|
84
|
+
warn,
|
|
85
|
+
error
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// src/utils/internal/pipeEvents.ts
|
|
89
|
+
function pipeEvents(source, destination) {
|
|
90
|
+
const rawEmit = source.emit;
|
|
91
|
+
if (rawEmit._isPiped) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
source.emit = function(event, ...data2) {
|
|
95
|
+
destination.emit(event, ...data2);
|
|
96
|
+
return rawEmit.call(this, event, ...data2);
|
|
97
|
+
};
|
|
98
|
+
source.emit._isPiped = true;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// src/utils/internal/toReadonlyArray.ts
|
|
102
|
+
function toReadonlyArray(source) {
|
|
103
|
+
const clone = [...source];
|
|
104
|
+
Object.freeze(clone);
|
|
105
|
+
return clone;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// src/SetupApi.ts
|
|
109
|
+
var SetupApi = class {
|
|
110
|
+
constructor(initialHandlers) {
|
|
111
|
+
this.validateHandlers(initialHandlers);
|
|
112
|
+
this.initialHandlers = toReadonlyArray(initialHandlers);
|
|
113
|
+
this.currentHandlers = [...initialHandlers];
|
|
114
|
+
this.emitter = new StrictEventEmitter();
|
|
115
|
+
this.publicEmitter = new StrictEventEmitter();
|
|
116
|
+
pipeEvents(this.emitter, this.publicEmitter);
|
|
117
|
+
this.events = this.createLifeCycleEvents();
|
|
118
|
+
}
|
|
119
|
+
validateHandlers(handlers) {
|
|
120
|
+
for (const handler of handlers) {
|
|
121
|
+
invariant(!Array.isArray(handler), devUtils.formatMessage('Failed to construct "%s" given an Array of request handlers. Make sure you spread the request handlers when calling the respective setup function.'), this.constructor.name);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
dispose() {
|
|
125
|
+
this.emitter.removeAllListeners();
|
|
126
|
+
this.publicEmitter.removeAllListeners();
|
|
127
|
+
}
|
|
128
|
+
use(...runtimeHandlers) {
|
|
129
|
+
this.currentHandlers.unshift(...runtimeHandlers);
|
|
130
|
+
}
|
|
131
|
+
restoreHandlers() {
|
|
132
|
+
this.currentHandlers.forEach((handler) => {
|
|
133
|
+
handler.markAsSkipped(false);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
resetHandlers(...nextHandlers) {
|
|
137
|
+
this.currentHandlers = nextHandlers.length > 0 ? [...nextHandlers] : [...this.initialHandlers];
|
|
138
|
+
}
|
|
139
|
+
listHandlers() {
|
|
140
|
+
return toReadonlyArray(this.currentHandlers);
|
|
141
|
+
}
|
|
142
|
+
createLifeCycleEvents() {
|
|
143
|
+
return {
|
|
144
|
+
on: (...args) => {
|
|
145
|
+
return this.publicEmitter.on(...args);
|
|
146
|
+
},
|
|
147
|
+
removeListener: (...args) => {
|
|
148
|
+
return this.publicEmitter.removeListener(...args);
|
|
149
|
+
},
|
|
150
|
+
removeAllListeners: (...args) => {
|
|
151
|
+
return this.publicEmitter.removeAllListeners(...args);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// src/utils/internal/isObject.ts
|
|
158
|
+
function isObject(value) {
|
|
159
|
+
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// src/utils/internal/mergeRight.ts
|
|
163
|
+
function mergeRight(left, right) {
|
|
164
|
+
return Object.entries(right).reduce((result, [key, rightValue]) => {
|
|
165
|
+
const leftValue = result[key];
|
|
166
|
+
if (Array.isArray(leftValue) && Array.isArray(rightValue)) {
|
|
167
|
+
result[key] = leftValue.concat(rightValue);
|
|
168
|
+
return result;
|
|
169
|
+
}
|
|
170
|
+
if (isObject(leftValue) && isObject(rightValue)) {
|
|
171
|
+
result[key] = mergeRight(leftValue, rightValue);
|
|
172
|
+
return result;
|
|
173
|
+
}
|
|
174
|
+
result[key] = rightValue;
|
|
175
|
+
return result;
|
|
176
|
+
}, Object.assign({}, left));
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// src/utils/request/MockedRequest.ts
|
|
180
|
+
import * as cookieUtils2 from "cookie";
|
|
181
|
+
import { store } from "@mswjs/cookies";
|
|
182
|
+
import { IsomorphicRequest } from "@mswjs/interceptors";
|
|
183
|
+
import { decodeBuffer } from "@mswjs/interceptors/lib/utils/bufferUtils";
|
|
184
|
+
import { Headers } from "headers-polyfill";
|
|
185
|
+
|
|
186
|
+
// src/utils/request/getRequestCookies.ts
|
|
187
|
+
import * as cookieUtils from "cookie";
|
|
188
|
+
function getAllCookies() {
|
|
189
|
+
return cookieUtils.parse(document.cookie);
|
|
190
|
+
}
|
|
191
|
+
function getRequestCookies(request) {
|
|
192
|
+
if (typeof document === "undefined" || typeof location === "undefined") {
|
|
193
|
+
return {};
|
|
194
|
+
}
|
|
195
|
+
switch (request.credentials) {
|
|
196
|
+
case "same-origin": {
|
|
197
|
+
return location.origin === request.url.origin ? getAllCookies() : {};
|
|
198
|
+
}
|
|
199
|
+
case "include": {
|
|
200
|
+
return getAllCookies();
|
|
201
|
+
}
|
|
202
|
+
default: {
|
|
203
|
+
return {};
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// src/utils/internal/jsonParse.ts
|
|
209
|
+
function jsonParse(value) {
|
|
210
|
+
try {
|
|
211
|
+
return JSON.parse(value);
|
|
212
|
+
} catch (error2) {
|
|
213
|
+
return void 0;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// src/utils/internal/parseMultipartData.ts
|
|
218
|
+
import { stringToHeaders } from "headers-polyfill";
|
|
219
|
+
function parseContentHeaders(headersString) {
|
|
220
|
+
var _a, _b;
|
|
221
|
+
const headers = stringToHeaders(headersString);
|
|
222
|
+
const contentType = headers.get("content-type") || "text/plain";
|
|
223
|
+
const disposition = headers.get("content-disposition");
|
|
224
|
+
if (!disposition) {
|
|
225
|
+
throw new Error('"Content-Disposition" header is required.');
|
|
226
|
+
}
|
|
227
|
+
const directives = disposition.split(";").reduce((acc, chunk) => {
|
|
228
|
+
const [name2, ...rest] = chunk.trim().split("=");
|
|
229
|
+
acc[name2] = rest.join("=");
|
|
230
|
+
return acc;
|
|
231
|
+
}, {});
|
|
232
|
+
const name = (_a = directives.name) == null ? void 0 : _a.slice(1, -1);
|
|
233
|
+
const filename = (_b = directives.filename) == null ? void 0 : _b.slice(1, -1);
|
|
234
|
+
return {
|
|
235
|
+
name,
|
|
236
|
+
filename,
|
|
237
|
+
contentType
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
function parseMultipartData(data2, headers) {
|
|
241
|
+
const contentType = headers == null ? void 0 : headers.get("content-type");
|
|
242
|
+
if (!contentType) {
|
|
243
|
+
return void 0;
|
|
244
|
+
}
|
|
245
|
+
const [, ...directives] = contentType.split(/; */);
|
|
246
|
+
const boundary = directives.filter((d) => d.startsWith("boundary=")).map((s) => s.replace(/^boundary=/, ""))[0];
|
|
247
|
+
if (!boundary) {
|
|
248
|
+
return void 0;
|
|
249
|
+
}
|
|
250
|
+
const boundaryRegExp = new RegExp(`--+${boundary}`);
|
|
251
|
+
const fields = data2.split(boundaryRegExp).filter((chunk) => chunk.startsWith("\r\n") && chunk.endsWith("\r\n")).map((chunk) => chunk.trimStart().replace(/\r\n$/, ""));
|
|
252
|
+
if (!fields.length) {
|
|
253
|
+
return void 0;
|
|
254
|
+
}
|
|
255
|
+
const parsedBody = {};
|
|
256
|
+
try {
|
|
257
|
+
for (const field2 of fields) {
|
|
258
|
+
const [contentHeaders, ...rest] = field2.split("\r\n\r\n");
|
|
259
|
+
const contentBody = rest.join("\r\n\r\n");
|
|
260
|
+
const { contentType: contentType2, filename, name } = parseContentHeaders(contentHeaders);
|
|
261
|
+
const value = filename === void 0 ? contentBody : new File([contentBody], filename, { type: contentType2 });
|
|
262
|
+
const parsedValue = parsedBody[name];
|
|
263
|
+
if (parsedValue === void 0) {
|
|
264
|
+
parsedBody[name] = value;
|
|
265
|
+
} else if (Array.isArray(parsedValue)) {
|
|
266
|
+
parsedBody[name] = [...parsedValue, value];
|
|
267
|
+
} else {
|
|
268
|
+
parsedBody[name] = [parsedValue, value];
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return parsedBody;
|
|
272
|
+
} catch (error2) {
|
|
273
|
+
return void 0;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// src/utils/request/parseBody.ts
|
|
278
|
+
function parseBody(body2, headers) {
|
|
279
|
+
var _a;
|
|
280
|
+
if (!body2) {
|
|
281
|
+
return body2;
|
|
282
|
+
}
|
|
283
|
+
const contentType = ((_a = headers == null ? void 0 : headers.get("content-type")) == null ? void 0 : _a.toLowerCase()) || "";
|
|
284
|
+
const hasMultipartContent = contentType.startsWith("multipart/form-data");
|
|
285
|
+
if (hasMultipartContent && typeof body2 !== "object") {
|
|
286
|
+
return parseMultipartData(body2.toString(), headers) || body2;
|
|
287
|
+
}
|
|
288
|
+
const hasJsonContent = contentType.includes("json");
|
|
289
|
+
if (hasJsonContent && typeof body2 !== "object") {
|
|
290
|
+
return jsonParse(body2.toString()) || body2;
|
|
291
|
+
}
|
|
292
|
+
return body2;
|
|
64
293
|
}
|
|
65
|
-
|
|
66
|
-
|
|
294
|
+
|
|
295
|
+
// src/utils/internal/isStringEqual.ts
|
|
296
|
+
function isStringEqual(actual, expected) {
|
|
297
|
+
return actual.toLowerCase() === expected.toLowerCase();
|
|
67
298
|
}
|
|
68
299
|
|
|
300
|
+
// src/utils/request/MockedRequest.ts
|
|
301
|
+
var MockedRequest = class extends IsomorphicRequest {
|
|
302
|
+
constructor(url, init = {}) {
|
|
303
|
+
super(url, init);
|
|
304
|
+
if (init.id) {
|
|
305
|
+
this.id = init.id;
|
|
306
|
+
}
|
|
307
|
+
this.cache = init.cache || "default";
|
|
308
|
+
this.destination = init.destination || "";
|
|
309
|
+
this.integrity = init.integrity || "";
|
|
310
|
+
this.keepalive = init.keepalive || false;
|
|
311
|
+
this.mode = init.mode || "cors";
|
|
312
|
+
this.priority = init.priority || "auto";
|
|
313
|
+
this.redirect = init.redirect || "follow";
|
|
314
|
+
this.referrer = init.referrer || "";
|
|
315
|
+
this.referrerPolicy = init.referrerPolicy || "no-referrer";
|
|
316
|
+
this.cookies = init.cookies || this.getCookies();
|
|
317
|
+
}
|
|
318
|
+
get body() {
|
|
319
|
+
const text2 = decodeBuffer(this["_body"]);
|
|
320
|
+
const body2 = parseBody(text2, this.headers);
|
|
321
|
+
if (isStringEqual(this.method, "GET") && body2 === "") {
|
|
322
|
+
return void 0;
|
|
323
|
+
}
|
|
324
|
+
return body2;
|
|
325
|
+
}
|
|
326
|
+
passthrough() {
|
|
327
|
+
return {
|
|
328
|
+
status: 101,
|
|
329
|
+
statusText: "Continue",
|
|
330
|
+
headers: new Headers(),
|
|
331
|
+
body: null,
|
|
332
|
+
passthrough: true,
|
|
333
|
+
once: false
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
getCookies() {
|
|
337
|
+
var _a;
|
|
338
|
+
const requestCookiesString = this.headers.get("cookie");
|
|
339
|
+
const ownCookies = requestCookiesString ? cookieUtils2.parse(requestCookiesString) : {};
|
|
340
|
+
store.hydrate();
|
|
341
|
+
const cookiesFromStore = Array.from((_a = store.get(__spreadProps(__spreadValues({}, this), { url: this.url.href }))) == null ? void 0 : _a.entries()).reduce((cookies, [name, { value }]) => {
|
|
342
|
+
return Object.assign(cookies, { [name.trim()]: value });
|
|
343
|
+
}, {});
|
|
344
|
+
const cookiesFromDocument = getRequestCookies(this);
|
|
345
|
+
const forwardedCookies = __spreadValues(__spreadValues({}, cookiesFromDocument), cookiesFromStore);
|
|
346
|
+
for (const [name, value] of Object.entries(forwardedCookies)) {
|
|
347
|
+
this.headers.append("cookie", `${name}=${value}`);
|
|
348
|
+
}
|
|
349
|
+
return __spreadValues(__spreadValues({}, forwardedCookies), ownCookies);
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
|
|
69
353
|
// src/utils/handleRequest.ts
|
|
70
354
|
import { until } from "@open-draft/until";
|
|
71
355
|
|
|
@@ -100,61 +384,33 @@ var getResponse = async (request, handlers, resolutionContext) => {
|
|
|
100
384
|
if (result2.response.once) {
|
|
101
385
|
handler.markAsSkipped(true);
|
|
102
386
|
}
|
|
103
|
-
return result2;
|
|
104
|
-
}, Promise.resolve(null));
|
|
105
|
-
if (!result) {
|
|
106
|
-
return {
|
|
107
|
-
handler: void 0,
|
|
108
|
-
response: void 0
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
return {
|
|
112
|
-
handler: result.handler,
|
|
113
|
-
publicRequest: result.request,
|
|
114
|
-
parsedRequest: result.parsedResult,
|
|
115
|
-
response: result.response
|
|
116
|
-
};
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
// src/utils/internal/devUtils.ts
|
|
120
|
-
import { format } from "outvariant";
|
|
121
|
-
var LIBRARY_PREFIX = "[MSW]";
|
|
122
|
-
function formatMessage(message, ...positionals) {
|
|
123
|
-
const interpolatedMessage = format(message, ...positionals);
|
|
124
|
-
return `${LIBRARY_PREFIX} ${interpolatedMessage}`;
|
|
125
|
-
}
|
|
126
|
-
function warn(message, ...positionals) {
|
|
127
|
-
console.warn(formatMessage(message, ...positionals));
|
|
128
|
-
}
|
|
129
|
-
function error(message, ...positionals) {
|
|
130
|
-
console.error(formatMessage(message, ...positionals));
|
|
131
|
-
}
|
|
132
|
-
var devUtils = {
|
|
133
|
-
formatMessage,
|
|
134
|
-
warn,
|
|
135
|
-
error
|
|
387
|
+
return result2;
|
|
388
|
+
}, Promise.resolve(null));
|
|
389
|
+
if (!result) {
|
|
390
|
+
return {
|
|
391
|
+
handler: void 0,
|
|
392
|
+
response: void 0
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
return {
|
|
396
|
+
handler: result.handler,
|
|
397
|
+
publicRequest: result.request,
|
|
398
|
+
parsedRequest: result.parsedResult,
|
|
399
|
+
response: result.response
|
|
400
|
+
};
|
|
136
401
|
};
|
|
137
402
|
|
|
138
403
|
// src/utils/request/onUnhandledRequest.ts
|
|
139
404
|
import getStringMatchScore from "js-levenshtein";
|
|
140
405
|
|
|
141
406
|
// src/utils/internal/parseGraphQLRequest.ts
|
|
142
|
-
import { parse } from "graphql";
|
|
407
|
+
import { parse as parse3 } from "graphql";
|
|
143
408
|
|
|
144
409
|
// src/utils/request/getPublicUrlFromRequest.ts
|
|
145
410
|
var getPublicUrlFromRequest = (request) => {
|
|
146
411
|
return request.referrer.startsWith(request.url.origin) ? request.url.pathname : new URL(request.url.pathname, `${request.url.protocol}//${request.url.host}`).href;
|
|
147
412
|
};
|
|
148
413
|
|
|
149
|
-
// src/utils/internal/jsonParse.ts
|
|
150
|
-
function jsonParse(value) {
|
|
151
|
-
try {
|
|
152
|
-
return JSON.parse(value);
|
|
153
|
-
} catch (error2) {
|
|
154
|
-
return void 0;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
414
|
// src/utils/internal/parseGraphQLRequest.ts
|
|
159
415
|
function parseDocumentNode(node) {
|
|
160
416
|
var _a;
|
|
@@ -168,7 +424,7 @@ function parseDocumentNode(node) {
|
|
|
168
424
|
}
|
|
169
425
|
function parseQuery(query) {
|
|
170
426
|
try {
|
|
171
|
-
const ast =
|
|
427
|
+
const ast = parse3(query);
|
|
172
428
|
return parseDocumentNode(ast);
|
|
173
429
|
} catch (error2) {
|
|
174
430
|
return error2;
|
|
@@ -250,11 +506,6 @@ function parseGraphQLRequest(request) {
|
|
|
250
506
|
};
|
|
251
507
|
}
|
|
252
508
|
|
|
253
|
-
// src/utils/internal/isStringEqual.ts
|
|
254
|
-
function isStringEqual(actual, expected) {
|
|
255
|
-
return actual.toLowerCase() === expected.toLowerCase();
|
|
256
|
-
}
|
|
257
|
-
|
|
258
509
|
// src/context/status.ts
|
|
259
510
|
import statuses from "statuses/codes.json";
|
|
260
511
|
var status = (statusCode, statusText) => {
|
|
@@ -283,10 +534,10 @@ function set(...args) {
|
|
|
283
534
|
}
|
|
284
535
|
|
|
285
536
|
// src/context/cookie.ts
|
|
286
|
-
import * as
|
|
537
|
+
import * as cookieUtils3 from "cookie";
|
|
287
538
|
var cookie = (name, value, options) => {
|
|
288
539
|
return (res) => {
|
|
289
|
-
const serializedCookie =
|
|
540
|
+
const serializedCookie = cookieUtils3.serialize(name, value, options);
|
|
290
541
|
res.headers.append("Set-Cookie", serializedCookie);
|
|
291
542
|
if (typeof document !== "undefined") {
|
|
292
543
|
document.cookie = serializedCookie;
|
|
@@ -303,28 +554,6 @@ var body = (value) => {
|
|
|
303
554
|
};
|
|
304
555
|
};
|
|
305
556
|
|
|
306
|
-
// src/utils/internal/isObject.ts
|
|
307
|
-
function isObject(value) {
|
|
308
|
-
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
// src/utils/internal/mergeRight.ts
|
|
312
|
-
function mergeRight(left, right) {
|
|
313
|
-
return Object.entries(right).reduce((result, [key, rightValue]) => {
|
|
314
|
-
const leftValue = result[key];
|
|
315
|
-
if (Array.isArray(leftValue) && Array.isArray(rightValue)) {
|
|
316
|
-
result[key] = leftValue.concat(rightValue);
|
|
317
|
-
return result;
|
|
318
|
-
}
|
|
319
|
-
if (isObject(leftValue) && isObject(rightValue)) {
|
|
320
|
-
result[key] = mergeRight(leftValue, rightValue);
|
|
321
|
-
return result;
|
|
322
|
-
}
|
|
323
|
-
result[key] = rightValue;
|
|
324
|
-
return result;
|
|
325
|
-
}, Object.assign({}, left));
|
|
326
|
-
}
|
|
327
|
-
|
|
328
557
|
// src/context/json.ts
|
|
329
558
|
var json = (body2) => {
|
|
330
559
|
return (res) => {
|
|
@@ -408,10 +637,10 @@ var errors = (errorsList) => {
|
|
|
408
637
|
|
|
409
638
|
// src/context/fetch.ts
|
|
410
639
|
import { isNodeProcess as isNodeProcess2 } from "is-node-process";
|
|
411
|
-
import { Headers } from "headers-polyfill";
|
|
412
|
-
var useFetch = isNodeProcess2() ? __require("node-fetch") : window.fetch;
|
|
640
|
+
import { Headers as Headers2 } from "headers-polyfill";
|
|
641
|
+
var useFetch = isNodeProcess2() ? (input, init) => Promise.resolve().then(() => __toESM(__require("node-fetch"))).then(({ default: nodeFetch }) => nodeFetch(input, init)) : window.fetch;
|
|
413
642
|
var augmentRequestInit = (requestInit) => {
|
|
414
|
-
const headers = new
|
|
643
|
+
const headers = new Headers2(requestInit.headers);
|
|
415
644
|
headers.set("x-msw-bypass", "true");
|
|
416
645
|
return __spreadProps(__spreadValues({}, requestInit), {
|
|
417
646
|
headers: headers.all()
|
|
@@ -486,86 +715,6 @@ function prepareRequest(request) {
|
|
|
486
715
|
|
|
487
716
|
// src/utils/logging/prepareResponse.ts
|
|
488
717
|
import { objectToHeaders as objectToHeaders2 } from "headers-polyfill";
|
|
489
|
-
|
|
490
|
-
// src/utils/internal/parseMultipartData.ts
|
|
491
|
-
import { stringToHeaders } from "headers-polyfill";
|
|
492
|
-
function parseContentHeaders(headersString) {
|
|
493
|
-
var _a, _b;
|
|
494
|
-
const headers = stringToHeaders(headersString);
|
|
495
|
-
const contentType = headers.get("content-type") || "text/plain";
|
|
496
|
-
const disposition = headers.get("content-disposition");
|
|
497
|
-
if (!disposition) {
|
|
498
|
-
throw new Error('"Content-Disposition" header is required.');
|
|
499
|
-
}
|
|
500
|
-
const directives = disposition.split(";").reduce((acc, chunk) => {
|
|
501
|
-
const [name2, ...rest] = chunk.trim().split("=");
|
|
502
|
-
acc[name2] = rest.join("=");
|
|
503
|
-
return acc;
|
|
504
|
-
}, {});
|
|
505
|
-
const name = (_a = directives.name) == null ? void 0 : _a.slice(1, -1);
|
|
506
|
-
const filename = (_b = directives.filename) == null ? void 0 : _b.slice(1, -1);
|
|
507
|
-
return {
|
|
508
|
-
name,
|
|
509
|
-
filename,
|
|
510
|
-
contentType
|
|
511
|
-
};
|
|
512
|
-
}
|
|
513
|
-
function parseMultipartData(data2, headers) {
|
|
514
|
-
const contentType = headers == null ? void 0 : headers.get("content-type");
|
|
515
|
-
if (!contentType) {
|
|
516
|
-
return void 0;
|
|
517
|
-
}
|
|
518
|
-
const [, ...directives] = contentType.split(/; */);
|
|
519
|
-
const boundary = directives.filter((d) => d.startsWith("boundary=")).map((s) => s.replace(/^boundary=/, ""))[0];
|
|
520
|
-
if (!boundary) {
|
|
521
|
-
return void 0;
|
|
522
|
-
}
|
|
523
|
-
const boundaryRegExp = new RegExp(`--+${boundary}`);
|
|
524
|
-
const fields = data2.split(boundaryRegExp).filter((chunk) => chunk.startsWith("\r\n") && chunk.endsWith("\r\n")).map((chunk) => chunk.trimStart().replace(/\r\n$/, ""));
|
|
525
|
-
if (!fields.length) {
|
|
526
|
-
return void 0;
|
|
527
|
-
}
|
|
528
|
-
const parsedBody = {};
|
|
529
|
-
try {
|
|
530
|
-
for (const field2 of fields) {
|
|
531
|
-
const [contentHeaders, ...rest] = field2.split("\r\n\r\n");
|
|
532
|
-
const contentBody = rest.join("\r\n\r\n");
|
|
533
|
-
const { contentType: contentType2, filename, name } = parseContentHeaders(contentHeaders);
|
|
534
|
-
const value = filename === void 0 ? contentBody : new File([contentBody], filename, { type: contentType2 });
|
|
535
|
-
const parsedValue = parsedBody[name];
|
|
536
|
-
if (parsedValue === void 0) {
|
|
537
|
-
parsedBody[name] = value;
|
|
538
|
-
} else if (Array.isArray(parsedValue)) {
|
|
539
|
-
parsedBody[name] = [...parsedValue, value];
|
|
540
|
-
} else {
|
|
541
|
-
parsedBody[name] = [parsedValue, value];
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
return parsedBody;
|
|
545
|
-
} catch (error2) {
|
|
546
|
-
return void 0;
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
// src/utils/request/parseBody.ts
|
|
551
|
-
function parseBody(body2, headers) {
|
|
552
|
-
var _a;
|
|
553
|
-
if (!body2) {
|
|
554
|
-
return body2;
|
|
555
|
-
}
|
|
556
|
-
const contentType = ((_a = headers == null ? void 0 : headers.get("content-type")) == null ? void 0 : _a.toLowerCase()) || "";
|
|
557
|
-
const hasMultipartContent = contentType.startsWith("multipart/form-data");
|
|
558
|
-
if (hasMultipartContent && typeof body2 !== "object") {
|
|
559
|
-
return parseMultipartData(body2.toString(), headers) || body2;
|
|
560
|
-
}
|
|
561
|
-
const hasJsonContent = contentType.includes("json");
|
|
562
|
-
if (hasJsonContent && typeof body2 !== "object") {
|
|
563
|
-
return jsonParse(body2.toString()) || body2;
|
|
564
|
-
}
|
|
565
|
-
return body2;
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
// src/utils/logging/prepareResponse.ts
|
|
569
718
|
function prepareResponse(res) {
|
|
570
719
|
const responseHeaders = objectToHeaders2(res.headers);
|
|
571
720
|
return __spreadProps(__spreadValues({}, res), {
|
|
@@ -575,7 +724,7 @@ function prepareResponse(res) {
|
|
|
575
724
|
|
|
576
725
|
// src/utils/matching/matchRequestUrl.ts
|
|
577
726
|
import { match } from "path-to-regexp";
|
|
578
|
-
import { getCleanUrl } from "@mswjs/interceptors/lib/utils/getCleanUrl";
|
|
727
|
+
import { getCleanUrl } from "@mswjs/interceptors/lib/utils/getCleanUrl.js";
|
|
579
728
|
|
|
580
729
|
// src/utils/url/cleanUrl.ts
|
|
581
730
|
var REDUNDANT_CHARACTERS_EXP = /[\?|#].*$/g;
|
|
@@ -634,88 +783,6 @@ function matchRequestUrl(url, path, baseUrl) {
|
|
|
634
783
|
};
|
|
635
784
|
}
|
|
636
785
|
|
|
637
|
-
// src/utils/request/MockedRequest.ts
|
|
638
|
-
import * as cookieUtils3 from "cookie";
|
|
639
|
-
import { store } from "@mswjs/cookies";
|
|
640
|
-
import { IsomorphicRequest } from "@mswjs/interceptors";
|
|
641
|
-
import { decodeBuffer } from "@mswjs/interceptors/lib/utils/bufferUtils";
|
|
642
|
-
import { Headers as Headers2 } from "headers-polyfill";
|
|
643
|
-
|
|
644
|
-
// src/utils/request/getRequestCookies.ts
|
|
645
|
-
import * as cookieUtils2 from "cookie";
|
|
646
|
-
function getAllCookies() {
|
|
647
|
-
return cookieUtils2.parse(document.cookie);
|
|
648
|
-
}
|
|
649
|
-
function getRequestCookies(request) {
|
|
650
|
-
if (typeof document === "undefined" || typeof location === "undefined") {
|
|
651
|
-
return {};
|
|
652
|
-
}
|
|
653
|
-
switch (request.credentials) {
|
|
654
|
-
case "same-origin": {
|
|
655
|
-
return location.origin === request.url.origin ? getAllCookies() : {};
|
|
656
|
-
}
|
|
657
|
-
case "include": {
|
|
658
|
-
return getAllCookies();
|
|
659
|
-
}
|
|
660
|
-
default: {
|
|
661
|
-
return {};
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
// src/utils/request/MockedRequest.ts
|
|
667
|
-
var MockedRequest = class extends IsomorphicRequest {
|
|
668
|
-
constructor(url, init = {}) {
|
|
669
|
-
super(url, init);
|
|
670
|
-
if (init.id) {
|
|
671
|
-
this.id = init.id;
|
|
672
|
-
}
|
|
673
|
-
this.cache = init.cache || "default";
|
|
674
|
-
this.destination = init.destination || "";
|
|
675
|
-
this.integrity = init.integrity || "";
|
|
676
|
-
this.keepalive = init.keepalive || false;
|
|
677
|
-
this.mode = init.mode || "cors";
|
|
678
|
-
this.priority = init.priority || "auto";
|
|
679
|
-
this.redirect = init.redirect || "follow";
|
|
680
|
-
this.referrer = init.referrer || "";
|
|
681
|
-
this.referrerPolicy = init.referrerPolicy || "no-referrer";
|
|
682
|
-
this.cookies = init.cookies || this.getCookies();
|
|
683
|
-
}
|
|
684
|
-
get body() {
|
|
685
|
-
const text2 = decodeBuffer(this["_body"]);
|
|
686
|
-
const body2 = parseBody(text2, this.headers);
|
|
687
|
-
if (isStringEqual(this.method, "GET") && body2 === "") {
|
|
688
|
-
return void 0;
|
|
689
|
-
}
|
|
690
|
-
return body2;
|
|
691
|
-
}
|
|
692
|
-
passthrough() {
|
|
693
|
-
return {
|
|
694
|
-
status: 101,
|
|
695
|
-
statusText: "Continue",
|
|
696
|
-
headers: new Headers2(),
|
|
697
|
-
body: null,
|
|
698
|
-
passthrough: true,
|
|
699
|
-
once: false
|
|
700
|
-
};
|
|
701
|
-
}
|
|
702
|
-
getCookies() {
|
|
703
|
-
var _a;
|
|
704
|
-
const requestCookiesString = this.headers.get("cookie");
|
|
705
|
-
const ownCookies = requestCookiesString ? cookieUtils3.parse(requestCookiesString) : {};
|
|
706
|
-
store.hydrate();
|
|
707
|
-
const cookiesFromStore = Array.from((_a = store.get(__spreadProps(__spreadValues({}, this), { url: this.url.href }))) == null ? void 0 : _a.entries()).reduce((cookies, [name, { value }]) => {
|
|
708
|
-
return Object.assign(cookies, { [name.trim()]: value });
|
|
709
|
-
}, {});
|
|
710
|
-
const cookiesFromDocument = getRequestCookies(this);
|
|
711
|
-
const forwardedCookies = __spreadValues(__spreadValues({}, cookiesFromDocument), cookiesFromStore);
|
|
712
|
-
for (const [name, value] of Object.entries(forwardedCookies)) {
|
|
713
|
-
this.headers.append("cookie", `${name}=${value}`);
|
|
714
|
-
}
|
|
715
|
-
return __spreadValues(__spreadValues({}, forwardedCookies), ownCookies);
|
|
716
|
-
}
|
|
717
|
-
};
|
|
718
|
-
|
|
719
786
|
// src/handlers/RequestHandler.ts
|
|
720
787
|
import { Headers as Headers4 } from "headers-polyfill";
|
|
721
788
|
|
|
@@ -772,7 +839,7 @@ var response = Object.assign(createResponseComposition(), {
|
|
|
772
839
|
});
|
|
773
840
|
|
|
774
841
|
// src/utils/internal/getCallFrame.ts
|
|
775
|
-
var SOURCE_FRAME =
|
|
842
|
+
var SOURCE_FRAME = /[\/\\]msw[\/\\]src[\/\\](.+)/;
|
|
776
843
|
var BUILD_FRAME = /(node_modules)?[\/\\]lib[\/\\](umd|esm|iief|cjs)[\/\\]|^[^\/\\]*$/;
|
|
777
844
|
function getCallFrame(error2) {
|
|
778
845
|
const stack = error2.stack;
|
|
@@ -939,7 +1006,7 @@ var RestHandler = class extends RequestHandler {
|
|
|
939
1006
|
};
|
|
940
1007
|
|
|
941
1008
|
// src/context/field.ts
|
|
942
|
-
import { invariant } from "outvariant";
|
|
1009
|
+
import { invariant as invariant2 } from "outvariant";
|
|
943
1010
|
var field = (fieldName, fieldValue) => {
|
|
944
1011
|
return (res) => {
|
|
945
1012
|
validateFieldName(fieldName);
|
|
@@ -949,10 +1016,10 @@ var field = (fieldName, fieldValue) => {
|
|
|
949
1016
|
};
|
|
950
1017
|
};
|
|
951
1018
|
function validateFieldName(fieldName) {
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
1019
|
+
invariant2(fieldName.trim() !== "", devUtils.formatMessage("Failed to set a custom field on a GraphQL response: field name cannot be empty."));
|
|
1020
|
+
invariant2(fieldName !== "data", devUtils.formatMessage('Failed to set a custom "%s" field on a mocked GraphQL response: forbidden field name. Did you mean to call "ctx.data()" instead?', fieldName));
|
|
1021
|
+
invariant2(fieldName !== "errors", devUtils.formatMessage('Failed to set a custom "%s" field on a mocked GraphQL response: forbidden field name. Did you mean to call "ctx.errors()" instead?', fieldName));
|
|
1022
|
+
invariant2(fieldName !== "extensions", devUtils.formatMessage('Failed to set a custom "%s" field on a mocked GraphQL response: forbidden field name. Did you mean to call "ctx.extensions()" instead?', fieldName));
|
|
956
1023
|
}
|
|
957
1024
|
|
|
958
1025
|
// src/utils/internal/tryCatch.ts
|
|
@@ -1210,53 +1277,27 @@ async function handleRequest(request, handlers, options, emitter, handleRequestO
|
|
|
1210
1277
|
return transformedResponse;
|
|
1211
1278
|
}
|
|
1212
1279
|
|
|
1213
|
-
// src/
|
|
1214
|
-
|
|
1215
|
-
const rawEmit = source.emit;
|
|
1216
|
-
if (rawEmit._isPiped) {
|
|
1217
|
-
return;
|
|
1218
|
-
}
|
|
1219
|
-
source.emit = function(event, ...data2) {
|
|
1220
|
-
destination.emit(event, ...data2);
|
|
1221
|
-
return rawEmit.call(this, event, ...data2);
|
|
1222
|
-
};
|
|
1223
|
-
source.emit._isPiped = true;
|
|
1224
|
-
}
|
|
1225
|
-
|
|
1226
|
-
// src/utils/internal/toReadonlyArray.ts
|
|
1227
|
-
function toReadonlyArray(source) {
|
|
1228
|
-
const clone = [...source];
|
|
1229
|
-
Object.freeze(clone);
|
|
1230
|
-
return clone;
|
|
1231
|
-
}
|
|
1232
|
-
|
|
1233
|
-
// src/node/createSetupServer.ts
|
|
1280
|
+
// src/node/SetupServerApi.ts
|
|
1281
|
+
var { bold } = chalk;
|
|
1234
1282
|
var DEFAULT_LISTEN_OPTIONS = {
|
|
1235
1283
|
onUnhandledRequest: "warn"
|
|
1236
1284
|
};
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
return function setupServer2(...requestHandlers) {
|
|
1242
|
-
requestHandlers.forEach((handler) => {
|
|
1243
|
-
if (Array.isArray(handler))
|
|
1244
|
-
throw new Error(devUtils.formatMessage('Failed to call "setupServer" given an Array of request handlers (setupServer([a, b])), expected to receive each handler individually: setupServer(a, b).'));
|
|
1245
|
-
});
|
|
1246
|
-
let currentHandlers = [...requestHandlers];
|
|
1247
|
-
if (!isNodeProcess3()) {
|
|
1248
|
-
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."));
|
|
1249
|
-
}
|
|
1250
|
-
let resolvedOptions = {};
|
|
1251
|
-
const interceptor = new BatchInterceptor({
|
|
1285
|
+
var SetupServerApi = class extends SetupApi {
|
|
1286
|
+
constructor(interceptors, handlers) {
|
|
1287
|
+
super(handlers);
|
|
1288
|
+
this.interceptor = new BatchInterceptor({
|
|
1252
1289
|
name: "setup-server",
|
|
1253
1290
|
interceptors: interceptors.map((Interceptor2) => new Interceptor2())
|
|
1254
1291
|
});
|
|
1255
|
-
|
|
1292
|
+
this.resolvedOptions = {};
|
|
1293
|
+
this.init();
|
|
1294
|
+
}
|
|
1295
|
+
init() {
|
|
1296
|
+
this.interceptor.on("request", async (request) => {
|
|
1256
1297
|
const mockedRequest = new MockedRequest(request.url, __spreadProps(__spreadValues({}, request), {
|
|
1257
1298
|
body: await request.arrayBuffer()
|
|
1258
1299
|
}));
|
|
1259
|
-
const response2 = await handleRequest(mockedRequest, currentHandlers, resolvedOptions, emitter, {
|
|
1300
|
+
const response2 = await handleRequest(mockedRequest, this.currentHandlers, this.resolvedOptions, this.emitter, {
|
|
1260
1301
|
transformResponse(response3) {
|
|
1261
1302
|
return {
|
|
1262
1303
|
status: response3.status,
|
|
@@ -1277,65 +1318,44 @@ function createSetupServer(...interceptors) {
|
|
|
1277
1318
|
}
|
|
1278
1319
|
return;
|
|
1279
1320
|
});
|
|
1280
|
-
interceptor.on("response", (request, response2) => {
|
|
1321
|
+
this.interceptor.on("response", (request, response2) => {
|
|
1281
1322
|
if (!request.id) {
|
|
1282
1323
|
return;
|
|
1283
1324
|
}
|
|
1284
1325
|
if (response2.headers.get("x-powered-by") === "msw") {
|
|
1285
|
-
emitter.emit("response:mocked", response2, request.id);
|
|
1326
|
+
this.emitter.emit("response:mocked", response2, request.id);
|
|
1286
1327
|
} else {
|
|
1287
|
-
emitter.emit("response:bypass", response2, request.id);
|
|
1328
|
+
this.emitter.emit("response:bypass", response2, request.id);
|
|
1288
1329
|
}
|
|
1289
1330
|
});
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
currentHandlers = resetHandlers(requestHandlers, ...nextHandlers);
|
|
1303
|
-
},
|
|
1304
|
-
listHandlers() {
|
|
1305
|
-
return toReadonlyArray(currentHandlers);
|
|
1306
|
-
},
|
|
1307
|
-
printHandlers() {
|
|
1308
|
-
const handlers = this.listHandlers();
|
|
1309
|
-
handlers.forEach((handler) => {
|
|
1310
|
-
const { header, callFrame } = handler.info;
|
|
1311
|
-
const pragma = handler.info.hasOwnProperty("operationType") ? "[graphql]" : "[rest]";
|
|
1312
|
-
console.log(`${bold(`${pragma} ${header}`)}
|
|
1331
|
+
}
|
|
1332
|
+
listen(options = {}) {
|
|
1333
|
+
this.resolvedOptions = mergeRight(DEFAULT_LISTEN_OPTIONS, options);
|
|
1334
|
+
this.interceptor.apply();
|
|
1335
|
+
invariant3([InterceptorReadyState.APPLYING, InterceptorReadyState.APPLIED].includes(this.interceptor.readyState), devUtils.formatMessage('Failed to start "setupServer": the interceptor failed to apply. This is likely an issue with the library and you should report it at "%s".'), "https://github.com/mswjs/msw/issues/new/choose");
|
|
1336
|
+
}
|
|
1337
|
+
printHandlers() {
|
|
1338
|
+
const handlers = this.listHandlers();
|
|
1339
|
+
handlers.forEach((handler) => {
|
|
1340
|
+
const { header, callFrame } = handler.info;
|
|
1341
|
+
const pragma = handler.info.hasOwnProperty("operationType") ? "[graphql]" : "[rest]";
|
|
1342
|
+
console.log(`${bold(`${pragma} ${header}`)}
|
|
1313
1343
|
Declaration: ${callFrame}
|
|
1314
1344
|
`);
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
return publicEmitter.removeListener(...args);
|
|
1323
|
-
},
|
|
1324
|
-
removeAllListeners(...args) {
|
|
1325
|
-
return publicEmitter.removeAllListeners(...args);
|
|
1326
|
-
}
|
|
1327
|
-
},
|
|
1328
|
-
close() {
|
|
1329
|
-
emitter.removeAllListeners();
|
|
1330
|
-
publicEmitter.removeAllListeners();
|
|
1331
|
-
interceptor.dispose();
|
|
1332
|
-
}
|
|
1333
|
-
};
|
|
1334
|
-
};
|
|
1335
|
-
}
|
|
1345
|
+
});
|
|
1346
|
+
}
|
|
1347
|
+
close() {
|
|
1348
|
+
super.dispose();
|
|
1349
|
+
this.interceptor.dispose();
|
|
1350
|
+
}
|
|
1351
|
+
};
|
|
1336
1352
|
|
|
1337
1353
|
// src/node/setupServer.ts
|
|
1338
|
-
|
|
1354
|
+
import { ClientRequestInterceptor } from "@mswjs/interceptors/lib/interceptors/ClientRequest/index.js";
|
|
1355
|
+
import { XMLHttpRequestInterceptor } from "@mswjs/interceptors/lib/interceptors/XMLHttpRequest/index.js";
|
|
1356
|
+
var setupServer = (...handlers) => {
|
|
1357
|
+
return new SetupServerApi([ClientRequestInterceptor, XMLHttpRequestInterceptor], handlers);
|
|
1358
|
+
};
|
|
1339
1359
|
export {
|
|
1340
1360
|
setupServer
|
|
1341
1361
|
};
|