msw 2.7.6 → 2.8.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.
Files changed (116) hide show
  1. package/browser/package.json +28 -3
  2. package/cli/index.js +5 -3
  3. package/cli/init.js +13 -8
  4. package/cli/invariant.js +3 -2
  5. package/cli/package.json +3 -0
  6. package/config/constants.js +9 -13
  7. package/config/package.json +3 -0
  8. package/config/scripts/postinstall.js +3 -3
  9. package/lib/browser/index.d.mts +4 -4
  10. package/lib/browser/index.d.ts +4 -4
  11. package/lib/browser/index.js +25 -25
  12. package/lib/core/{GraphQLHandler-D1CSV926.d.ts → GraphQLHandler-DOfinX9J.d.ts} +1 -1
  13. package/lib/core/{GraphQLHandler-BNMGdWQe.d.mts → GraphQLHandler-GA1kyXQ7.d.mts} +1 -1
  14. package/lib/core/{HttpResponse-BRDnWbjc.d.mts → HttpResponse-Bls5AXtT.d.mts} +9 -9
  15. package/lib/core/{HttpResponse-Cy7ytzUn.d.ts → HttpResponse-DQOloMJy.d.ts} +9 -9
  16. package/lib/core/HttpResponse.d.mts +1 -1
  17. package/lib/core/HttpResponse.d.ts +1 -1
  18. package/lib/core/HttpResponse.js +3 -6
  19. package/lib/core/HttpResponse.js.map +1 -1
  20. package/lib/core/HttpResponse.mjs +2 -5
  21. package/lib/core/HttpResponse.mjs.map +1 -1
  22. package/lib/core/SetupApi.d.mts +1 -1
  23. package/lib/core/SetupApi.d.ts +1 -1
  24. package/lib/core/SetupApi.js +4 -4
  25. package/lib/core/getResponse.d.mts +1 -1
  26. package/lib/core/getResponse.d.ts +1 -1
  27. package/lib/core/getResponse.js +1 -1
  28. package/lib/core/graphql.d.mts +4 -4
  29. package/lib/core/graphql.d.ts +4 -4
  30. package/lib/core/graphql.js +2 -2
  31. package/lib/core/graphql.js.map +1 -1
  32. package/lib/core/graphql.mjs +1 -1
  33. package/lib/core/graphql.mjs.map +1 -1
  34. package/lib/core/handlers/GraphQLHandler.d.mts +2 -2
  35. package/lib/core/handlers/GraphQLHandler.d.ts +2 -2
  36. package/lib/core/handlers/GraphQLHandler.js +10 -10
  37. package/lib/core/handlers/HttpHandler.d.mts +2 -2
  38. package/lib/core/handlers/HttpHandler.d.ts +2 -2
  39. package/lib/core/handlers/HttpHandler.js +11 -11
  40. package/lib/core/handlers/RequestHandler.d.mts +1 -1
  41. package/lib/core/handlers/RequestHandler.d.ts +1 -1
  42. package/lib/core/handlers/RequestHandler.js +2 -2
  43. package/lib/core/handlers/RequestHandler.js.map +1 -1
  44. package/lib/core/handlers/RequestHandler.mjs.map +1 -1
  45. package/lib/core/handlers/WebSocketHandler.js +2 -2
  46. package/lib/core/http.d.mts +2 -2
  47. package/lib/core/http.d.ts +2 -2
  48. package/lib/core/http.js +1 -1
  49. package/lib/core/index.d.mts +2 -2
  50. package/lib/core/index.d.ts +2 -2
  51. package/lib/core/index.js +21 -21
  52. package/lib/core/index.js.map +1 -1
  53. package/lib/core/passthrough.d.mts +2 -2
  54. package/lib/core/passthrough.d.ts +2 -2
  55. package/lib/core/passthrough.js.map +1 -1
  56. package/lib/core/passthrough.mjs.map +1 -1
  57. package/lib/core/utils/HttpResponse/decorators.d.mts +1 -1
  58. package/lib/core/utils/HttpResponse/decorators.d.ts +1 -1
  59. package/lib/core/utils/HttpResponse/decorators.js +1 -1
  60. package/lib/core/utils/cookieStore.js +1 -1
  61. package/lib/core/utils/executeHandlers.d.mts +1 -1
  62. package/lib/core/utils/executeHandlers.d.ts +1 -1
  63. package/lib/core/utils/handleRequest.d.mts +1 -1
  64. package/lib/core/utils/handleRequest.d.ts +1 -1
  65. package/lib/core/utils/handleRequest.js +3 -3
  66. package/lib/core/utils/internal/checkGlobals.js +1 -1
  67. package/lib/core/utils/internal/isHandlerKind.d.mts +1 -1
  68. package/lib/core/utils/internal/isHandlerKind.d.ts +1 -1
  69. package/lib/core/utils/internal/mergeRight.js +1 -1
  70. package/lib/core/utils/internal/parseGraphQLRequest.d.mts +2 -2
  71. package/lib/core/utils/internal/parseGraphQLRequest.d.ts +2 -2
  72. package/lib/core/utils/internal/parseGraphQLRequest.js +4 -4
  73. package/lib/core/utils/internal/parseMultipartData.d.mts +1 -1
  74. package/lib/core/utils/internal/parseMultipartData.d.ts +1 -1
  75. package/lib/core/utils/internal/requestHandlerUtils.d.mts +1 -1
  76. package/lib/core/utils/internal/requestHandlerUtils.d.ts +1 -1
  77. package/lib/core/utils/logging/serializeResponse.js +1 -1
  78. package/lib/core/utils/matching/matchRequestUrl.js +1 -1
  79. package/lib/core/utils/matching/normalizePath.js +2 -2
  80. package/lib/core/utils/request/getRequestCookies.js +2 -2
  81. package/lib/core/utils/request/onUnhandledRequest.js +3 -3
  82. package/lib/core/utils/request/storeResponseCookies.js +2 -2
  83. package/lib/core/utils/url/getAbsoluteUrl.js +1 -1
  84. package/lib/core/ws/WebSocketClientManager.js +2 -2
  85. package/lib/core/ws/handleWebSocketEvent.d.mts +1 -1
  86. package/lib/core/ws/handleWebSocketEvent.d.ts +1 -1
  87. package/lib/core/ws/handleWebSocketEvent.js +4 -4
  88. package/lib/core/ws/utils/attachWebSocketLogger.js +5 -5
  89. package/lib/core/ws/utils/getPublicData.js +1 -1
  90. package/lib/core/ws.js +3 -3
  91. package/lib/iife/index.js +6 -9
  92. package/lib/iife/index.js.map +1 -1
  93. package/lib/mockServiceWorker.js +1 -1
  94. package/lib/native/index.d.mts +5 -7
  95. package/lib/native/index.d.ts +5 -7
  96. package/lib/native/index.js +12 -12
  97. package/lib/native/index.js.map +1 -1
  98. package/lib/native/index.mjs +2 -2
  99. package/lib/native/index.mjs.map +1 -1
  100. package/lib/node/index.d.mts +6 -8
  101. package/lib/node/index.d.ts +6 -8
  102. package/lib/node/index.js +17 -16
  103. package/lib/node/index.js.map +1 -1
  104. package/lib/node/index.mjs +7 -6
  105. package/lib/node/index.mjs.map +1 -1
  106. package/native/package.json +25 -1
  107. package/node/package.json +28 -1
  108. package/package.json +145 -47
  109. package/src/core/HttpResponse.ts +16 -18
  110. package/src/core/graphql.ts +1 -1
  111. package/src/core/handlers/RequestHandler.ts +5 -3
  112. package/src/core/passthrough.ts +3 -3
  113. package/src/native/index.ts +1 -1
  114. package/src/node/SetupServerApi.ts +10 -6
  115. package/src/node/SetupServerCommonApi.ts +2 -2
  116. package/src/package.json +3 -0
package/package.json CHANGED
@@ -1,67 +1,162 @@
1
1
  {
2
2
  "name": "msw",
3
- "version": "2.7.6",
3
+ "version": "2.8.0",
4
4
  "description": "Seamless REST/GraphQL API mocking library for browser and Node.js.",
5
+ "type": "commonjs",
5
6
  "main": "./lib/core/index.js",
6
7
  "module": "./lib/core/index.mjs",
7
8
  "types": "./lib/core/index.d.ts",
8
9
  "exports": {
9
10
  ".": {
10
- "types": "./lib/core/index.d.ts",
11
- "require": "./lib/core/index.js",
12
- "import": "./lib/core/index.mjs",
13
- "default": "./lib/core/index.js"
11
+ "module-sync": {
12
+ "types": "./lib/core/index.d.mts",
13
+ "default": "./lib/core/index.mjs"
14
+ },
15
+ "module": {
16
+ "types": "./lib/core/index.d.mts",
17
+ "default": "./lib/core/index.mjs"
18
+ },
19
+ "react-native": {
20
+ "import": {
21
+ "types": "./lib/core/index.d.mts",
22
+ "default": "./lib/core/index.mjs"
23
+ },
24
+ "default": {
25
+ "types": "./lib/core/index.d.ts",
26
+ "default": "./lib/core/index.js"
27
+ }
28
+ },
29
+ "import": {
30
+ "types": "./lib/core/index.d.mts",
31
+ "default": "./lib/core/index.mjs"
32
+ },
33
+ "default": {
34
+ "types": "./lib/core/index.d.ts",
35
+ "default": "./lib/core/index.js"
36
+ }
14
37
  },
15
38
  "./browser": {
16
- "types": "./lib/browser/index.d.ts",
39
+ "module-sync": {
40
+ "types": "./lib/browser/index.d.mts",
41
+ "default": "./lib/browser/index.mjs"
42
+ },
43
+ "module": {
44
+ "types": "./lib/browser/index.d.mts",
45
+ "default": "./lib/browser/index.mjs"
46
+ },
17
47
  "browser": {
18
- "require": "./lib/browser/index.js",
19
- "import": "./lib/browser/index.mjs"
48
+ "types": "./lib/browser/index.d.mts",
49
+ "default": "./lib/browser/index.mjs"
50
+ },
51
+ "import": {
52
+ "types": "./lib/browser/index.d.mts",
53
+ "default": "./lib/browser/index.mjs"
20
54
  },
21
55
  "node": null,
22
- "require": "./lib/browser/index.js",
23
- "import": "./lib/browser/index.mjs",
24
- "default": "./lib/browser/index.js"
56
+ "react-native": null,
57
+ "default": {
58
+ "types": "./lib/browser/index.d.ts",
59
+ "default": "./lib/browser/index.js"
60
+ }
25
61
  },
26
62
  "./node": {
27
- "types": "./lib/node/index.d.ts",
63
+ "browser": null,
64
+ "react-native": null,
65
+ "module-sync": {
66
+ "types": "./lib/node/index.d.mts",
67
+ "default": "./lib/node/index.mjs"
68
+ },
69
+ "module": {
70
+ "types": "./lib/node/index.d.mts",
71
+ "default": "./lib/node/index.mjs"
72
+ },
28
73
  "node": {
29
74
  "require": "./lib/node/index.js",
30
75
  "import": "./lib/node/index.mjs"
31
76
  },
32
- "browser": null,
33
- "require": "./lib/node/index.js",
34
- "import": "./lib/node/index.mjs",
35
- "default": "./lib/node/index.mjs"
77
+ "import": {
78
+ "types": "./lib/node/index.d.mts",
79
+ "default": "./lib/node/index.mjs"
80
+ },
81
+ "default": {
82
+ "types": "./lib/node/index.d.ts",
83
+ "default": "./lib/node/index.js"
84
+ }
36
85
  },
37
86
  "./native": {
38
- "types": "./lib/native/index.d.ts",
87
+ "browser": null,
39
88
  "react-native": {
40
- "require": "./lib/native/index.js",
41
- "import": "./lib/native/index.mjs"
89
+ "import": {
90
+ "types": "./lib/native/index.d.mts",
91
+ "default": "./lib/native/index.mjs"
92
+ },
93
+ "default": {
94
+ "types": "./lib/native/index.d.ts",
95
+ "default": "./lib/native/index.js"
96
+ }
42
97
  },
43
- "browser": null,
44
- "require": "./lib/native/index.js",
45
- "import": "./lib/native/index.mjs",
46
- "default": "./lib/native/index.js"
98
+ "import": {
99
+ "types": "./lib/native/index.d.mts",
100
+ "default": "./lib/native/index.mjs"
101
+ },
102
+ "default": {
103
+ "types": "./lib/native/index.d.ts",
104
+ "default": "./lib/native/index.js"
105
+ }
47
106
  },
48
107
  "./core/http": {
49
- "types": "./lib/core/http.d.ts",
50
- "require": "./lib/core/http.js",
51
- "import": "./lib/core/http.mjs",
52
- "default": "./lib/core/http.js"
108
+ "module-sync": {
109
+ "types": "./lib/core/http.d.mts",
110
+ "default": "./lib/core/http.mjs"
111
+ },
112
+ "module": {
113
+ "types": "./lib/core/http.d.mts",
114
+ "default": "./lib/core/http.mjs"
115
+ },
116
+ "import": {
117
+ "types": "./lib/core/http.d.mts",
118
+ "default": "./lib/core/http.mjs"
119
+ },
120
+ "default": {
121
+ "types": "./lib/core/http.d.ts",
122
+ "default": "./lib/core/http.js"
123
+ }
53
124
  },
54
125
  "./core/graphql": {
55
- "types": "./lib/core/graphql.d.ts",
56
- "require": "./lib/core/graphql.js",
57
- "import": "./lib/core/graphql.mjs",
58
- "default": "./lib/core/graphql.js"
126
+ "module-sync": {
127
+ "types": "./lib/core/graphql.d.mts",
128
+ "default": "./lib/core/graphql.mjs"
129
+ },
130
+ "module": {
131
+ "types": "./lib/core/graphql.d.mts",
132
+ "default": "./lib/core/graphql.mjs"
133
+ },
134
+ "import": {
135
+ "types": "./lib/core/graphql.d.mts",
136
+ "default": "./lib/core/graphql.mjs"
137
+ },
138
+ "default": {
139
+ "types": "./lib/core/graphql.d.ts",
140
+ "default": "./lib/core/graphql.js"
141
+ }
59
142
  },
60
143
  "./core/ws": {
61
- "types": "./lib/core/ws.d.ts",
62
- "require": "./lib/core/ws.js",
63
- "import": "./lib/core/ws.mjs",
64
- "default": "./lib/core/ws.js"
144
+ "module-sync": {
145
+ "types": "./lib/core/ws.d.mts",
146
+ "default": "./lib/core/ws.mjs"
147
+ },
148
+ "module": {
149
+ "types": "./lib/core/ws.d.mts",
150
+ "default": "./lib/core/ws.mjs"
151
+ },
152
+ "import": {
153
+ "types": "./lib/core/ws.d.mts",
154
+ "default": "./lib/core/ws.mjs"
155
+ },
156
+ "default": {
157
+ "types": "./lib/core/ws.d.ts",
158
+ "default": "./lib/core/ws.js"
159
+ }
65
160
  },
66
161
  "./mockServiceWorker.js": "./lib/mockServiceWorker.js",
67
162
  "./package.json": "./package.json"
@@ -83,7 +178,7 @@
83
178
  "homepage": "https://mswjs.io",
84
179
  "repository": {
85
180
  "type": "git",
86
- "url": "https://github.com/mswjs/msw"
181
+ "url": "git+https://github.com/mswjs/msw.git"
87
182
  },
88
183
  "author": {
89
184
  "name": "Artem Zakharchenko",
@@ -92,6 +187,7 @@
92
187
  "license": "MIT",
93
188
  "funding": "https://github.com/sponsors/mswjs",
94
189
  "files": [
190
+ "config/package.json",
95
191
  "config/constants.js",
96
192
  "config/scripts/postinstall.js",
97
193
  "cli",
@@ -156,7 +252,7 @@
156
252
  "cross-env": "^7.0.3",
157
253
  "cross-fetch": "^4.0.0",
158
254
  "cz-conventional-changelog": "3.3.0",
159
- "esbuild": "^0.24.0",
255
+ "esbuild": "^0.25.3",
160
256
  "esbuild-loader": "^4.2.2",
161
257
  "eslint": "^8.57.0",
162
258
  "eslint-config-prettier": "^9.1.0",
@@ -171,17 +267,19 @@
171
267
  "lint-staged": "^15.2.10",
172
268
  "page-with": "^0.6.1",
173
269
  "prettier": "^3.4.2",
270
+ "publint": "^0.3.12",
174
271
  "regenerator-runtime": "^0.14.1",
175
272
  "rimraf": "^6.0.1",
176
273
  "simple-git-hooks": "^2.9.0",
177
- "tsup": "^8.3.0",
274
+ "tsup": "^8.4.0",
178
275
  "typescript": "^5.5.2",
179
276
  "undici": "^6.20.0",
180
277
  "url-loader": "^4.1.1",
181
- "vitest": "^2.1.8",
278
+ "vitest": "^3.1.3",
182
279
  "vitest-environment-miniflare": "^2.14.4",
183
280
  "webpack": "^5.95.0",
184
- "webpack-http-server": "^0.5.0"
281
+ "webpack-http-server": "^0.5.0",
282
+ "msw": "2.8.0"
185
283
  },
186
284
  "peerDependencies": {
187
285
  "typescript": ">= 4.8.x"
@@ -207,18 +305,18 @@
207
305
  "lint": "eslint \"{cli,src}/**/*.ts\"",
208
306
  "build": "pnpm clean && cross-env NODE_ENV=production tsup && pnpm patch:dts",
209
307
  "patch:dts": "node \"./config/scripts/patch-ts.js\"",
210
- "check:exports": "node \"./config/scripts/validate-esm.js\"",
308
+ "publint": "publint",
211
309
  "test": "pnpm test:unit && pnpm test:node && pnpm test:browser && pnpm test:native",
212
310
  "test:unit": "vitest",
213
- "test:node": "vitest --config=./test/node/vitest.config.mts",
214
- "test:native": "vitest --config=./test/native/vitest.config.mts",
311
+ "test:node": "vitest --config=./test/node/vitest.config.ts",
312
+ "test:native": "vitest --config=./test/native/vitest.config.ts",
215
313
  "test:browser": "playwright test -c ./test/browser/playwright.config.ts",
216
- "test:modules:node": "vitest --config=./test/modules/node/vitest.config.mts",
314
+ "test:modules:node": "vitest run --config=./test/modules/node/vitest.config.ts",
217
315
  "test:modules:browser": "playwright test -c ./test/modules/browser/playwright.config.ts",
218
- "test:e2e": "vitest run --config=./test/e2e/vitest.config.mts",
219
- "test:ts": "vitest --typecheck --config=./test/typings/vitest.config.mts",
316
+ "test:e2e": "vitest run --config=./test/e2e/vitest.config.ts",
317
+ "test:ts": "vitest --config=./test/typings/vitest.config.ts",
220
318
  "release": "release publish",
221
- "postinstall": "node -e \"try{require('./config/scripts/postinstall')}catch(e){}\"",
319
+ "postinstall": "node -e \"try{import('./config/scripts/postinstall.js')}catch(e){}\"",
222
320
  "knip": "knip"
223
321
  }
224
322
  }
@@ -6,22 +6,20 @@ import {
6
6
  normalizeResponseInit,
7
7
  } from './utils/HttpResponse/decorators'
8
8
 
9
- const bodyType = Symbol('bodyType')
10
-
11
9
  export interface HttpResponseInit extends ResponseInit {
12
10
  type?: ResponseType
13
11
  }
14
12
 
15
- export interface StrictRequest<BodyType extends DefaultBodyType>
16
- extends Request {
13
+ const bodyType: unique symbol = Symbol('bodyType')
14
+
15
+ export interface StrictRequest<BodyType extends JsonBodyType> extends Request {
17
16
  json(): Promise<BodyType>
18
17
  }
19
18
 
20
19
  /**
21
20
  * Opaque `Response` type that supports strict body type.
22
21
  */
23
- export interface StrictResponse<BodyType extends DefaultBodyType>
24
- extends Response {
22
+ interface StrictResponse<BodyType extends DefaultBodyType> extends Response {
25
23
  readonly [bodyType]: BodyType
26
24
  }
27
25
 
@@ -36,12 +34,15 @@ export interface StrictResponse<BodyType extends DefaultBodyType>
36
34
  *
37
35
  * @see {@link https://mswjs.io/docs/api/http-response `HttpResponse` API reference}
38
36
  */
39
- export class HttpResponse extends FetchResponse {
40
- readonly [bodyType]: any
37
+ export class HttpResponse<BodyType extends DefaultBodyType>
38
+ extends FetchResponse
39
+ implements StrictResponse<BodyType>
40
+ {
41
+ [bodyType]: BodyType = null as any
41
42
 
42
- constructor(body?: BodyInit | null, init?: HttpResponseInit) {
43
+ constructor(body?: NoInfer<BodyType> | null, init?: HttpResponseInit) {
43
44
  const responseInit = normalizeResponseInit(init)
44
- super(body, responseInit)
45
+ super(body as BodyInit, responseInit)
45
46
  decorateResponse(this, responseInit)
46
47
  }
47
48
 
@@ -54,7 +55,7 @@ export class HttpResponse extends FetchResponse {
54
55
  static text<BodyType extends string>(
55
56
  body?: NoInfer<BodyType> | null,
56
57
  init?: HttpResponseInit,
57
- ): StrictResponse<BodyType> {
58
+ ): HttpResponse<BodyType> {
58
59
  const responseInit = normalizeResponseInit(init)
59
60
 
60
61
  if (!responseInit.headers.has('Content-Type')) {
@@ -71,7 +72,7 @@ export class HttpResponse extends FetchResponse {
71
72
  )
72
73
  }
73
74
 
74
- return new HttpResponse(body, responseInit) as StrictResponse<BodyType>
75
+ return new HttpResponse(body, responseInit)
75
76
  }
76
77
 
77
78
  /**
@@ -81,9 +82,9 @@ export class HttpResponse extends FetchResponse {
81
82
  * HttpResponse.json({ error: 'Not Authorized' }, { status: 401 })
82
83
  */
83
84
  static json<BodyType extends JsonBodyType>(
84
- body?: NoInfer<BodyType> | null,
85
+ body?: NoInfer<BodyType> | null | undefined,
85
86
  init?: HttpResponseInit,
86
- ): StrictResponse<BodyType> {
87
+ ): HttpResponse<BodyType> {
87
88
  const responseInit = normalizeResponseInit(init)
88
89
 
89
90
  if (!responseInit.headers.has('Content-Type')) {
@@ -103,10 +104,7 @@ export class HttpResponse extends FetchResponse {
103
104
  )
104
105
  }
105
106
 
106
- return new HttpResponse(
107
- responseText,
108
- responseInit,
109
- ) as StrictResponse<BodyType>
107
+ return new HttpResponse(responseText as BodyType, responseInit)
110
108
  }
111
109
 
112
110
  /**
@@ -111,7 +111,7 @@ const standardGraphQLHandlers = {
111
111
  * return HttpResponse.json({ data: { name: 'John' } })
112
112
  * })
113
113
  *
114
- * @see {@link https://mswjs.io/docs/api/graphql#graphloperationresolver `graphql.operation()` API reference}
114
+ * @see {@link https://mswjs.io/docs/api/graphql#graphqloperationresolver `graphql.operation()` API reference}
115
115
  */
116
116
  operation: createGraphQLOperationHandler('*'),
117
117
  }
@@ -6,7 +6,7 @@ import {
6
6
  } from '../utils/internal/isIterable'
7
7
  import type { ResponseResolutionContext } from '../utils/executeHandlers'
8
8
  import type { MaybePromise } from '../typeUtils'
9
- import { StrictRequest, StrictResponse } from '..//HttpResponse'
9
+ import type { HttpResponse, StrictRequest } from '..//HttpResponse'
10
10
  import type { HandlerKind } from './common'
11
11
 
12
12
  export type DefaultRequestMultipartBody = Record<
@@ -44,7 +44,7 @@ export type ResponseResolverReturnType<
44
44
  > =
45
45
  | ([ResponseBodyType] extends [undefined]
46
46
  ? Response
47
- : StrictResponse<ResponseBodyType>)
47
+ : HttpResponse<ResponseBodyType>)
48
48
  | undefined
49
49
  | void
50
50
 
@@ -139,7 +139,7 @@ export abstract class RequestHandler<
139
139
  MaybeAsyncResponseResolverReturnType<any>,
140
140
  MaybeAsyncResponseResolverReturnType<any>
141
141
  >
142
- private resolverIteratorResult?: Response | StrictResponse<any>
142
+ private resolverIteratorResult?: Response | HttpResponse<any>
143
143
  private options?: HandlerOptions
144
144
 
145
145
  constructor(args: RequestHandlerArgs<HandlerInfo, HandlerOptions>) {
@@ -324,9 +324,11 @@ export abstract class RequestHandler<
324
324
  return async (info): Promise<ResponseResolverReturnType<any>> => {
325
325
  if (!this.resolverIterator) {
326
326
  const result = await resolver(info)
327
+
327
328
  if (!isIterable(result)) {
328
329
  return result
329
330
  }
331
+
330
332
  this.resolverIterator =
331
333
  Symbol.iterator in result
332
334
  ? result[Symbol.iterator]()
@@ -1,4 +1,4 @@
1
- import type { StrictResponse } from './HttpResponse'
1
+ import type { HttpResponse } from './HttpResponse'
2
2
 
3
3
  /**
4
4
  * Performs the intercepted request as-is.
@@ -14,12 +14,12 @@ import type { StrictResponse } from './HttpResponse'
14
14
  *
15
15
  * @see {@link https://mswjs.io/docs/api/passthrough `passthrough()` API reference}
16
16
  */
17
- export function passthrough(): StrictResponse<any> {
17
+ export function passthrough(): HttpResponse<any> {
18
18
  return new Response(null, {
19
19
  status: 302,
20
20
  statusText: 'Passthrough',
21
21
  headers: {
22
22
  'x-msw-intention': 'passthrough',
23
23
  },
24
- }) as StrictResponse<any>
24
+ }) as HttpResponse<any>
25
25
  }
@@ -15,7 +15,7 @@ export function setupServer(
15
15
  // Provision request interception via patching the `XMLHttpRequest` class only
16
16
  // in React Native. There is no `http`/`https` modules in that environment.
17
17
  return new SetupServerCommonApi(
18
- [FetchInterceptor, XMLHttpRequestInterceptor],
18
+ [new FetchInterceptor(), new XMLHttpRequestInterceptor()],
19
19
  handlers,
20
20
  )
21
21
  }
@@ -1,4 +1,5 @@
1
1
  import { AsyncLocalStorage } from 'node:async_hooks'
2
+ import type { HttpRequestEventMap, Interceptor } from '@mswjs/interceptors'
2
3
  import { ClientRequestInterceptor } from '@mswjs/interceptors/ClientRequest'
3
4
  import { XMLHttpRequestInterceptor } from '@mswjs/interceptors/XMLHttpRequest'
4
5
  import { FetchInterceptor } from '@mswjs/interceptors/fetch'
@@ -47,16 +48,19 @@ class AsyncHandlersController implements HandlersController {
47
48
  return handlers.concat(initialHandlers)
48
49
  }
49
50
  }
50
-
51
51
  export class SetupServerApi
52
52
  extends SetupServerCommonApi
53
53
  implements SetupServer
54
54
  {
55
- constructor(handlers: Array<RequestHandler | WebSocketHandler>) {
56
- super(
57
- [ClientRequestInterceptor, XMLHttpRequestInterceptor, FetchInterceptor],
58
- handlers,
59
- )
55
+ constructor(
56
+ handlers: Array<RequestHandler | WebSocketHandler>,
57
+ interceptors: Array<Interceptor<HttpRequestEventMap>> = [
58
+ new ClientRequestInterceptor(),
59
+ new XMLHttpRequestInterceptor(),
60
+ new FetchInterceptor(),
61
+ ],
62
+ ) {
63
+ super(interceptors, handlers)
60
64
 
61
65
  this.handlersController = new AsyncHandlersController(handlers)
62
66
  }
@@ -37,14 +37,14 @@ export class SetupServerCommonApi
37
37
  private resolvedOptions: RequiredDeep<SharedOptions>
38
38
 
39
39
  constructor(
40
- interceptors: Array<{ new (): Interceptor<HttpRequestEventMap> }>,
40
+ interceptors: Array<Interceptor<HttpRequestEventMap>>,
41
41
  handlers: Array<RequestHandler | WebSocketHandler>,
42
42
  ) {
43
43
  super(...handlers)
44
44
 
45
45
  this.interceptor = new BatchInterceptor({
46
46
  name: 'setup-server',
47
- interceptors: interceptors.map((Interceptor) => new Interceptor()),
47
+ interceptors,
48
48
  })
49
49
 
50
50
  this.resolvedOptions = {} as RequiredDeep<SharedOptions>
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }