msw 0.41.0 → 0.42.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.
@@ -1,11 +1,7 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
2
  var __defProps = Object.defineProperties;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
3
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
4
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
- var __getProtoOf = Object.getPrototypeOf;
9
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
10
6
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
7
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -40,195 +36,19 @@ var __objRest = (source, exclude) => {
40
36
  }
41
37
  return target;
42
38
  };
43
- var __esm = (fn, res) => function __init() {
44
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
45
- };
46
- var __commonJS = (cb, mod) => function __require2() {
47
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
48
- };
49
- var __copyProps = (to, from, except, desc) => {
50
- if (from && typeof from === "object" || typeof from === "function") {
51
- for (let key of __getOwnPropNames(from))
52
- if (!__hasOwnProp.call(to, key) && key !== except)
53
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
54
- }
55
- return to;
56
- };
57
- 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));
58
-
59
- // node_modules/tsup/assets/esm_shims.js
60
- var init_esm_shims = __esm({
61
- "node_modules/tsup/assets/esm_shims.js"() {
62
- }
63
- });
64
-
65
- // node_modules/outvariant/lib/format.js
66
- var require_format = __commonJS({
67
- "node_modules/outvariant/lib/format.js"(exports) {
68
- "use strict";
69
- init_esm_shims();
70
- Object.defineProperty(exports, "__esModule", { value: true });
71
- exports.format = void 0;
72
- var POSITIONALS_EXP = /(%?)(%([sdjo]))/g;
73
- function serializePositional(positional, flag) {
74
- switch (flag) {
75
- case "s":
76
- return positional;
77
- case "d":
78
- case "i":
79
- return Number(positional);
80
- case "j":
81
- return JSON.stringify(positional);
82
- case "o": {
83
- if (typeof positional === "string") {
84
- return positional;
85
- }
86
- var json2 = JSON.stringify(positional);
87
- if (json2 === "{}" || json2 === "[]" || /^\[object .+?\]$/.test(json2)) {
88
- return positional;
89
- }
90
- return json2;
91
- }
92
- }
93
- }
94
- function format2(message) {
95
- var positionals = [];
96
- for (var _i = 1; _i < arguments.length; _i++) {
97
- positionals[_i - 1] = arguments[_i];
98
- }
99
- if (positionals.length === 0) {
100
- return message;
101
- }
102
- var positionalIndex = 0;
103
- var formattedMessage = message.replace(POSITIONALS_EXP, function(match2, isEscaped, _, flag) {
104
- var positional = positionals[positionalIndex];
105
- var value = serializePositional(positional, flag);
106
- if (!isEscaped) {
107
- positionalIndex++;
108
- return value;
109
- }
110
- return match2;
111
- });
112
- if (positionalIndex < positionals.length) {
113
- formattedMessage += " " + positionals.slice(positionalIndex).join(" ");
114
- }
115
- formattedMessage = formattedMessage.replace(/%{2,2}/g, "%");
116
- return formattedMessage;
117
- }
118
- exports.format = format2;
119
- }
120
- });
121
-
122
- // node_modules/outvariant/lib/invariant.js
123
- var require_invariant = __commonJS({
124
- "node_modules/outvariant/lib/invariant.js"(exports) {
125
- "use strict";
126
- init_esm_shims();
127
- var __extends = exports && exports.__extends || function() {
128
- var extendStatics = function(d, b) {
129
- extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
130
- d2.__proto__ = b2;
131
- } || function(d2, b2) {
132
- for (var p in b2)
133
- if (Object.prototype.hasOwnProperty.call(b2, p))
134
- d2[p] = b2[p];
135
- };
136
- return extendStatics(d, b);
137
- };
138
- return function(d, b) {
139
- if (typeof b !== "function" && b !== null)
140
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
141
- extendStatics(d, b);
142
- function __() {
143
- this.constructor = d;
144
- }
145
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
146
- };
147
- }();
148
- var __spreadArray = exports && exports.__spreadArray || function(to, from) {
149
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
150
- to[j] = from[i];
151
- return to;
152
- };
153
- Object.defineProperty(exports, "__esModule", { value: true });
154
- exports.invariant = exports.InvariantError = void 0;
155
- var format_1 = require_format();
156
- var STACK_FRAMES_TO_IGNORE = 2;
157
- var InvariantError = function(_super) {
158
- __extends(InvariantError2, _super);
159
- function InvariantError2(message) {
160
- var positionals = [];
161
- for (var _i = 1; _i < arguments.length; _i++) {
162
- positionals[_i - 1] = arguments[_i];
163
- }
164
- var _this = _super.call(this, message) || this;
165
- _this.name = "Invariant Violation";
166
- _this.message = format_1.format.apply(void 0, __spreadArray([message], positionals));
167
- if (_this.stack) {
168
- var nextStack = _this.stack.split("\n");
169
- nextStack.splice(1, STACK_FRAMES_TO_IGNORE);
170
- _this.stack = nextStack.join("\n");
171
- }
172
- return _this;
173
- }
174
- return InvariantError2;
175
- }(Error);
176
- exports.InvariantError = InvariantError;
177
- function invariant(predicate, message) {
178
- var positionals = [];
179
- for (var _i = 2; _i < arguments.length; _i++) {
180
- positionals[_i - 2] = arguments[_i];
181
- }
182
- if (!predicate) {
183
- throw new (InvariantError.bind.apply(InvariantError, __spreadArray([void 0, message], positionals)))();
184
- }
185
- }
186
- exports.invariant = invariant;
187
- }
188
- });
189
-
190
- // node_modules/outvariant/lib/index.js
191
- var require_lib = __commonJS({
192
- "node_modules/outvariant/lib/index.js"(exports) {
193
- "use strict";
194
- init_esm_shims();
195
- var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
196
- if (k2 === void 0)
197
- k2 = k;
198
- Object.defineProperty(o, k2, { enumerable: true, get: function() {
199
- return m[k];
200
- } });
201
- } : function(o, m, k, k2) {
202
- if (k2 === void 0)
203
- k2 = k;
204
- o[k2] = m[k];
205
- });
206
- var __exportStar = exports && exports.__exportStar || function(m, exports2) {
207
- for (var p in m)
208
- if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p))
209
- __createBinding(exports2, m, p);
210
- };
211
- Object.defineProperty(exports, "__esModule", { value: true });
212
- __exportStar(require_invariant(), exports);
213
- __exportStar(require_format(), exports);
214
- }
215
- });
216
39
 
217
40
  // src/native/index.ts
218
- init_esm_shims();
219
- import { interceptXMLHttpRequest } from "@mswjs/interceptors/lib/interceptors/XMLHttpRequest";
41
+ import { XMLHttpRequestInterceptor } from "@mswjs/interceptors/lib/interceptors/XMLHttpRequest";
220
42
 
221
43
  // src/node/createSetupServer.ts
222
- init_esm_shims();
223
44
  import { bold } from "chalk";
224
45
  import { isNodeProcess as isNodeProcess3 } from "is-node-process";
225
46
  import { StrictEventEmitter } from "strict-event-emitter";
226
47
  import {
227
- createInterceptor
48
+ BatchInterceptor
228
49
  } from "@mswjs/interceptors";
229
50
 
230
51
  // src/utils/internal/requestHandlerUtils.ts
231
- init_esm_shims();
232
52
  function use(currentHandlers, ...handlers) {
233
53
  currentHandlers.unshift(...handlers);
234
54
  }
@@ -241,19 +61,13 @@ function resetHandlers(initialHandlers, ...nextHandlers) {
241
61
  return nextHandlers.length > 0 ? [...nextHandlers] : [...initialHandlers];
242
62
  }
243
63
 
244
- // src/utils/request/parseIsomorphicRequest.ts
245
- init_esm_shims();
246
-
247
64
  // src/handlers/RequestHandler.ts
248
- init_esm_shims();
249
65
  import { Headers as Headers3 } from "headers-polyfill";
250
66
 
251
67
  // src/response.ts
252
- init_esm_shims();
253
68
  import { Headers } from "headers-polyfill";
254
69
 
255
70
  // src/utils/internal/compose.ts
256
- init_esm_shims();
257
71
  function compose(...fns) {
258
72
  return (...args) => {
259
73
  return fns.reduceRight((leftFn, rightFn) => {
@@ -263,7 +77,6 @@ function compose(...fns) {
263
77
  }
264
78
 
265
79
  // src/utils/NetworkError.ts
266
- init_esm_shims();
267
80
  var NetworkError = class extends Error {
268
81
  constructor(message) {
269
82
  super(message);
@@ -304,7 +117,6 @@ var response = Object.assign(createResponseComposition(), {
304
117
  });
305
118
 
306
119
  // src/utils/internal/getCallFrame.ts
307
- init_esm_shims();
308
120
  var SOURCE_FRAME = /\/msw\/src\/(.+)/;
309
121
  var BUILD_FRAME = /(node_modules)?[\/\\]lib[\/\\](umd|esm|iief|cjs)[\/\\]|^[^\/\\]*$/;
310
122
  function getCallFrame(error2) {
@@ -324,7 +136,6 @@ function getCallFrame(error2) {
324
136
  }
325
137
 
326
138
  // src/utils/internal/isIterable.ts
327
- init_esm_shims();
328
139
  function isIterable(fn) {
329
140
  if (!fn) {
330
141
  return false;
@@ -333,7 +144,6 @@ function isIterable(fn) {
333
144
  }
334
145
 
335
146
  // src/context/status.ts
336
- init_esm_shims();
337
147
  import statuses from "statuses/codes.json";
338
148
  var status = (statusCode, statusText) => {
339
149
  return (res) => {
@@ -344,7 +154,6 @@ var status = (statusCode, statusText) => {
344
154
  };
345
155
 
346
156
  // src/context/set.ts
347
- init_esm_shims();
348
157
  import { objectToHeaders } from "headers-polyfill";
349
158
  function set(...args) {
350
159
  return (res) => {
@@ -362,7 +171,6 @@ function set(...args) {
362
171
  }
363
172
 
364
173
  // src/context/delay.ts
365
- init_esm_shims();
366
174
  import { isNodeProcess } from "is-node-process";
367
175
  var SET_TIMEOUT_MAX_ALLOWED_INT = 2147483647;
368
176
  var MIN_SERVER_RESPONSE_TIME = 100;
@@ -405,7 +213,6 @@ var delay = (durationOrMode) => {
405
213
  };
406
214
 
407
215
  // src/context/fetch.ts
408
- init_esm_shims();
409
216
  import { isNodeProcess as isNodeProcess2 } from "is-node-process";
410
217
  import { Headers as Headers2 } from "headers-polyfill";
411
218
  var useFetch = isNodeProcess2() ? __require("node-fetch") : window.fetch;
@@ -521,11 +328,7 @@ function passthrough() {
521
328
  };
522
329
  }
523
330
 
524
- // src/utils/request/parseBody.ts
525
- init_esm_shims();
526
-
527
331
  // src/utils/internal/jsonParse.ts
528
- init_esm_shims();
529
332
  function jsonParse(value) {
530
333
  try {
531
334
  return JSON.parse(value);
@@ -535,7 +338,6 @@ function jsonParse(value) {
535
338
  }
536
339
 
537
340
  // src/utils/internal/parseMultipartData.ts
538
- init_esm_shims();
539
341
  import { stringToHeaders } from "headers-polyfill";
540
342
  function parseContentHeaders(headersString) {
541
343
  var _a, _b;
@@ -575,8 +377,8 @@ function parseMultipartData(data2, headers) {
575
377
  }
576
378
  const parsedBody = {};
577
379
  try {
578
- for (const field of fields) {
579
- const [contentHeaders, ...rest] = field.split("\r\n\r\n");
380
+ for (const field2 of fields) {
381
+ const [contentHeaders, ...rest] = field2.split("\r\n\r\n");
580
382
  const contentBody = rest.join("\r\n\r\n");
581
383
  const { contentType: contentType2, filename, name } = parseContentHeaders(contentHeaders);
582
384
  const value = filename === void 0 ? contentBody : new File([contentBody], filename, { type: contentType2 });
@@ -614,12 +416,10 @@ function parseBody(body2, headers) {
614
416
  }
615
417
 
616
418
  // src/utils/request/setRequestCookies.ts
617
- init_esm_shims();
618
419
  import * as cookieUtils2 from "cookie";
619
420
  import { store } from "@mswjs/cookies";
620
421
 
621
422
  // src/utils/request/getRequestCookies.ts
622
- init_esm_shims();
623
423
  import * as cookieUtils from "cookie";
624
424
  function getAllCookies() {
625
425
  return cookieUtils.parse(document.cookie);
@@ -684,11 +484,9 @@ function parseIsomorphicRequest(request) {
684
484
  }
685
485
 
686
486
  // src/utils/handleRequest.ts
687
- init_esm_shims();
688
487
  import { until } from "@open-draft/until";
689
488
 
690
489
  // src/utils/getResponse.ts
691
- init_esm_shims();
692
490
  var getResponse = async (request, handlers, resolutionContext) => {
693
491
  const relevantHandlers = handlers.filter((handler) => {
694
492
  return handler.test(request, resolutionContext);
@@ -736,11 +534,10 @@ var getResponse = async (request, handlers, resolutionContext) => {
736
534
  };
737
535
 
738
536
  // src/utils/internal/devUtils.ts
739
- init_esm_shims();
740
- var import_outvariant = __toESM(require_lib());
537
+ import { format } from "outvariant";
741
538
  var LIBRARY_PREFIX = "[MSW]";
742
539
  function formatMessage(message, ...positionals) {
743
- const interpolatedMessage = (0, import_outvariant.format)(message, ...positionals);
540
+ const interpolatedMessage = format(message, ...positionals);
744
541
  return `${LIBRARY_PREFIX} ${interpolatedMessage}`;
745
542
  }
746
543
  function warn(message, ...positionals) {
@@ -756,17 +553,14 @@ var devUtils = {
756
553
  };
757
554
 
758
555
  // src/utils/request/onUnhandledRequest.ts
759
- init_esm_shims();
760
556
  import getStringMatchScore from "js-levenshtein";
761
557
 
762
558
  // src/utils/internal/parseGraphQLRequest.ts
763
- init_esm_shims();
764
559
  import {
765
560
  parse as parse3
766
561
  } from "graphql";
767
562
 
768
563
  // src/utils/request/getPublicUrlFromRequest.ts
769
- init_esm_shims();
770
564
  var getPublicUrlFromRequest = (request) => {
771
565
  return request.referrer.startsWith(request.url.origin) ? request.url.pathname : new URL(request.url.pathname, `${request.url.protocol}//${request.url.host}`).href;
772
566
  };
@@ -867,19 +661,11 @@ function parseGraphQLRequest(request) {
867
661
  }
868
662
 
869
663
  // src/utils/internal/isStringEqual.ts
870
- init_esm_shims();
871
664
  function isStringEqual(actual, expected) {
872
665
  return actual.toLowerCase() === expected.toLowerCase();
873
666
  }
874
667
 
875
- // src/handlers/RestHandler.ts
876
- init_esm_shims();
877
-
878
- // src/context/index.ts
879
- init_esm_shims();
880
-
881
668
  // src/context/cookie.ts
882
- init_esm_shims();
883
669
  import * as cookieUtils3 from "cookie";
884
670
  var cookie = (name, value, options) => {
885
671
  return (res) => {
@@ -893,7 +679,6 @@ var cookie = (name, value, options) => {
893
679
  };
894
680
 
895
681
  // src/context/body.ts
896
- init_esm_shims();
897
682
  var body = (value) => {
898
683
  return (res) => {
899
684
  res.body = value;
@@ -901,14 +686,7 @@ var body = (value) => {
901
686
  };
902
687
  };
903
688
 
904
- // src/context/data.ts
905
- init_esm_shims();
906
-
907
- // src/utils/internal/mergeRight.ts
908
- init_esm_shims();
909
-
910
689
  // src/utils/internal/isObject.ts
911
- init_esm_shims();
912
690
  function isObject(value) {
913
691
  return value != null && typeof value === "object" && !Array.isArray(value);
914
692
  }
@@ -931,7 +709,6 @@ function mergeRight(left, right) {
931
709
  }
932
710
 
933
711
  // src/context/json.ts
934
- init_esm_shims();
935
712
  var json = (body2) => {
936
713
  return (res) => {
937
714
  res.headers.set("Content-Type", "application/json");
@@ -950,7 +727,6 @@ var data = (payload) => {
950
727
  };
951
728
 
952
729
  // src/context/extensions.ts
953
- init_esm_shims();
954
730
  var extensions = (payload) => {
955
731
  return (res) => {
956
732
  const prevBody = jsonParse(res.body) || {};
@@ -960,7 +736,6 @@ var extensions = (payload) => {
960
736
  };
961
737
 
962
738
  // src/context/errors.ts
963
- init_esm_shims();
964
739
  var errors = (errorsList) => {
965
740
  return (res) => {
966
741
  if (errorsList == null) {
@@ -973,7 +748,6 @@ var errors = (errorsList) => {
973
748
  };
974
749
 
975
750
  // src/context/text.ts
976
- init_esm_shims();
977
751
  var text = (body2) => {
978
752
  return (res) => {
979
753
  res.headers.set("Content-Type", "text/plain");
@@ -983,7 +757,6 @@ var text = (body2) => {
983
757
  };
984
758
 
985
759
  // src/context/xml.ts
986
- init_esm_shims();
987
760
  var xml = (body2) => {
988
761
  return (res) => {
989
762
  res.headers.set("Content-Type", "text/xml");
@@ -993,7 +766,6 @@ var xml = (body2) => {
993
766
  };
994
767
 
995
768
  // src/utils/logging/getStatusCodeColor.ts
996
- init_esm_shims();
997
769
  function getStatusCodeColor(status2) {
998
770
  if (status2 < 300) {
999
771
  return "#69AB32" /* Success */;
@@ -1005,14 +777,12 @@ function getStatusCodeColor(status2) {
1005
777
  }
1006
778
 
1007
779
  // src/utils/logging/getTimestamp.ts
1008
- init_esm_shims();
1009
780
  function getTimestamp() {
1010
781
  const now = new Date();
1011
782
  return [now.getHours(), now.getMinutes(), now.getSeconds()].map(String).map((chunk) => chunk.slice(0, 2)).map((chunk) => chunk.padStart(2, "0")).join(":");
1012
783
  }
1013
784
 
1014
785
  // src/utils/logging/prepareRequest.ts
1015
- init_esm_shims();
1016
786
  function prepareRequest(request) {
1017
787
  return __spreadProps(__spreadValues({}, request), {
1018
788
  headers: request.headers.all()
@@ -1020,7 +790,6 @@ function prepareRequest(request) {
1020
790
  }
1021
791
 
1022
792
  // src/utils/logging/prepareResponse.ts
1023
- init_esm_shims();
1024
793
  import { objectToHeaders as objectToHeaders2 } from "headers-polyfill";
1025
794
  function prepareResponse(res) {
1026
795
  const responseHeaders = objectToHeaders2(res.headers);
@@ -1030,15 +799,10 @@ function prepareResponse(res) {
1030
799
  }
1031
800
 
1032
801
  // src/utils/matching/matchRequestUrl.ts
1033
- init_esm_shims();
1034
802
  import { match } from "path-to-regexp";
1035
803
  import { getCleanUrl } from "@mswjs/interceptors/lib/utils/getCleanUrl";
1036
804
 
1037
- // src/utils/matching/normalizePath.ts
1038
- init_esm_shims();
1039
-
1040
805
  // src/utils/url/cleanUrl.ts
1041
- init_esm_shims();
1042
806
  var REDUNDANT_CHARACTERS_EXP = /[\?|#].*$/g;
1043
807
  function getSearchParams(path) {
1044
808
  return new URL(`/${path}`, "http://localhost").searchParams;
@@ -1047,11 +811,7 @@ function cleanUrl(path) {
1047
811
  return path.replace(REDUNDANT_CHARACTERS_EXP, "");
1048
812
  }
1049
813
 
1050
- // src/utils/url/getAbsoluteUrl.ts
1051
- init_esm_shims();
1052
-
1053
814
  // src/utils/url/isAbsoluteUrl.ts
1054
- init_esm_shims();
1055
815
  function isAbsoluteUrl(url) {
1056
816
  return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url);
1057
817
  }
@@ -1164,11 +924,24 @@ var RestHandler = class extends RequestHandler {
1164
924
  }
1165
925
  };
1166
926
 
1167
- // src/handlers/GraphQLHandler.ts
1168
- init_esm_shims();
927
+ // src/context/field.ts
928
+ import { invariant } from "outvariant";
929
+ var field = (fieldName, fieldValue) => {
930
+ return (res) => {
931
+ validateFieldName(fieldName);
932
+ const prevBody = jsonParse(res.body) || {};
933
+ const nextBody = mergeRight(prevBody, { [fieldName]: fieldValue });
934
+ return json(nextBody)(res);
935
+ };
936
+ };
937
+ function validateFieldName(fieldName) {
938
+ invariant(fieldName.trim() !== "", devUtils.formatMessage("Failed to set a custom field on a GraphQL response: field name cannot be empty."));
939
+ invariant(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));
940
+ invariant(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));
941
+ invariant(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));
942
+ }
1169
943
 
1170
944
  // src/utils/internal/tryCatch.ts
1171
- init_esm_shims();
1172
945
  function tryCatch(fn, onException) {
1173
946
  try {
1174
947
  const result = fn();
@@ -1183,7 +956,8 @@ var graphqlContext = __spreadProps(__spreadValues({}, defaultContext), {
1183
956
  data,
1184
957
  extensions,
1185
958
  errors,
1186
- cookie
959
+ cookie,
960
+ field
1187
961
  });
1188
962
  function isDocumentNode(value) {
1189
963
  if (value == null) {
@@ -1363,7 +1137,6 @@ Read more: https://mswjs.io/docs/getting-started/mocks`
1363
1137
  }
1364
1138
 
1365
1139
  // src/utils/request/readResponseCookies.ts
1366
- init_esm_shims();
1367
1140
  import { store as store2 } from "@mswjs/cookies";
1368
1141
  function readResponseCookies(request, response2) {
1369
1142
  store2.add(__spreadProps(__spreadValues({}, request), { url: request.url.toString() }), response2);
@@ -1425,7 +1198,6 @@ async function handleRequest(request, handlers, options, emitter, handleRequestO
1425
1198
  }
1426
1199
 
1427
1200
  // src/utils/internal/pipeEvents.ts
1428
- init_esm_shims();
1429
1201
  function pipeEvents(source, destination) {
1430
1202
  const rawEmit = source.emit;
1431
1203
  if (rawEmit._isPiped) {
@@ -1456,21 +1228,26 @@ function createSetupServer(...interceptors) {
1456
1228
  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."));
1457
1229
  }
1458
1230
  let resolvedOptions = {};
1459
- const interceptor = createInterceptor({
1460
- modules: interceptors,
1461
- async resolver(request) {
1462
- const mockedRequest = parseIsomorphicRequest(request);
1463
- return handleRequest(mockedRequest, currentHandlers, resolvedOptions, emitter, {
1464
- transformResponse(response2) {
1465
- return {
1466
- status: response2.status,
1467
- statusText: response2.statusText,
1468
- headers: response2.headers.all(),
1469
- body: response2.body
1470
- };
1471
- }
1472
- });
1231
+ const interceptor = new BatchInterceptor({
1232
+ name: "setup-server",
1233
+ interceptors
1234
+ });
1235
+ interceptor.on("request", async function setupServerListener(request) {
1236
+ const mockedRequest = parseIsomorphicRequest(request);
1237
+ const response2 = await handleRequest(mockedRequest, currentHandlers, resolvedOptions, emitter, {
1238
+ transformResponse(response3) {
1239
+ return {
1240
+ status: response3.status,
1241
+ statusText: response3.statusText,
1242
+ headers: response3.headers.all(),
1243
+ body: response3.body
1244
+ };
1245
+ }
1246
+ });
1247
+ if (response2) {
1248
+ request.respondWith(response2);
1473
1249
  }
1250
+ return;
1474
1251
  });
1475
1252
  interceptor.on("response", (request, response2) => {
1476
1253
  if (!request.id) {
@@ -1519,14 +1296,14 @@ function createSetupServer(...interceptors) {
1519
1296
  close() {
1520
1297
  emitter.removeAllListeners();
1521
1298
  publicEmitter.removeAllListeners();
1522
- interceptor.restore();
1299
+ interceptor.dispose();
1523
1300
  }
1524
1301
  };
1525
1302
  };
1526
1303
  }
1527
1304
 
1528
1305
  // src/native/index.ts
1529
- var setupServer = createSetupServer(interceptXMLHttpRequest);
1306
+ var setupServer = createSetupServer(new XMLHttpRequestInterceptor());
1530
1307
  export {
1531
1308
  setupServer
1532
1309
  };
@@ -1,5 +1,5 @@
1
- import { b as RequestHandler, i as RequestHandlerDefaultInfo, M as MockedRequest, c as DefaultBodyType, z as SetupServerApi } from '../glossary-36cf4e2d.js';
2
- export { z as SetupServerApi } from '../glossary-36cf4e2d.js';
1
+ import { b as RequestHandler, i as RequestHandlerDefaultInfo, M as MockedRequest, c as DefaultBodyType, z as SetupServerApi } from '../glossary-58eca5a8.js';
2
+ export { z as SetupServerApi } from '../glossary-58eca5a8.js';
3
3
  import 'type-fest';
4
4
  import '@mswjs/interceptors';
5
5
  import 'headers-polyfill';