msw 2.7.5 → 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.
- package/browser/package.json +28 -3
- package/cli/index.js +5 -3
- package/cli/init.js +13 -8
- package/cli/invariant.js +3 -2
- package/cli/package.json +3 -0
- package/config/constants.js +9 -13
- package/config/package.json +3 -0
- package/config/scripts/postinstall.js +3 -3
- package/lib/browser/index.d.mts +4 -4
- package/lib/browser/index.d.ts +4 -4
- package/lib/browser/index.js +25 -25
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/{GraphQLHandler-D1CSV926.d.ts → GraphQLHandler-DOfinX9J.d.ts} +1 -1
- package/lib/core/{GraphQLHandler-BNMGdWQe.d.mts → GraphQLHandler-GA1kyXQ7.d.mts} +1 -1
- package/lib/core/{HttpResponse-BRDnWbjc.d.mts → HttpResponse-Bls5AXtT.d.mts} +9 -9
- package/lib/core/{HttpResponse-Cy7ytzUn.d.ts → HttpResponse-DQOloMJy.d.ts} +9 -9
- package/lib/core/HttpResponse.d.mts +1 -1
- package/lib/core/HttpResponse.d.ts +1 -1
- package/lib/core/HttpResponse.js +3 -6
- package/lib/core/HttpResponse.js.map +1 -1
- package/lib/core/HttpResponse.mjs +2 -5
- package/lib/core/HttpResponse.mjs.map +1 -1
- package/lib/core/SetupApi.d.mts +1 -1
- package/lib/core/SetupApi.d.ts +1 -1
- package/lib/core/SetupApi.js +4 -4
- package/lib/core/getResponse.d.mts +1 -1
- package/lib/core/getResponse.d.ts +1 -1
- package/lib/core/getResponse.js +1 -1
- package/lib/core/graphql.d.mts +4 -4
- package/lib/core/graphql.d.ts +4 -4
- package/lib/core/graphql.js +2 -2
- package/lib/core/graphql.js.map +1 -1
- package/lib/core/graphql.mjs +1 -1
- package/lib/core/graphql.mjs.map +1 -1
- package/lib/core/handlers/GraphQLHandler.d.mts +2 -2
- package/lib/core/handlers/GraphQLHandler.d.ts +2 -2
- package/lib/core/handlers/GraphQLHandler.js +10 -10
- package/lib/core/handlers/HttpHandler.d.mts +2 -2
- package/lib/core/handlers/HttpHandler.d.ts +2 -2
- package/lib/core/handlers/HttpHandler.js +11 -11
- package/lib/core/handlers/RequestHandler.d.mts +1 -1
- package/lib/core/handlers/RequestHandler.d.ts +1 -1
- package/lib/core/handlers/RequestHandler.js +2 -2
- package/lib/core/handlers/RequestHandler.js.map +1 -1
- package/lib/core/handlers/RequestHandler.mjs.map +1 -1
- package/lib/core/handlers/WebSocketHandler.js +2 -2
- package/lib/core/http.d.mts +2 -2
- package/lib/core/http.d.ts +2 -2
- package/lib/core/http.js +1 -1
- package/lib/core/index.d.mts +2 -2
- package/lib/core/index.d.ts +2 -2
- package/lib/core/index.js +21 -21
- package/lib/core/index.js.map +1 -1
- package/lib/core/passthrough.d.mts +2 -2
- package/lib/core/passthrough.d.ts +2 -2
- package/lib/core/passthrough.js.map +1 -1
- package/lib/core/passthrough.mjs.map +1 -1
- package/lib/core/utils/HttpResponse/decorators.d.mts +1 -1
- package/lib/core/utils/HttpResponse/decorators.d.ts +1 -1
- package/lib/core/utils/HttpResponse/decorators.js +1 -1
- package/lib/core/utils/cookieStore.js +1 -1
- package/lib/core/utils/executeHandlers.d.mts +1 -1
- package/lib/core/utils/executeHandlers.d.ts +1 -1
- package/lib/core/utils/handleRequest.d.mts +1 -1
- package/lib/core/utils/handleRequest.d.ts +1 -1
- package/lib/core/utils/handleRequest.js +3 -3
- package/lib/core/utils/internal/checkGlobals.js +1 -1
- package/lib/core/utils/internal/isHandlerKind.d.mts +1 -1
- package/lib/core/utils/internal/isHandlerKind.d.ts +1 -1
- package/lib/core/utils/internal/mergeRight.js +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.d.mts +2 -2
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +2 -2
- package/lib/core/utils/internal/parseGraphQLRequest.js +4 -4
- package/lib/core/utils/internal/parseMultipartData.d.mts +1 -1
- package/lib/core/utils/internal/parseMultipartData.d.ts +1 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.mts +1 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.ts +1 -1
- package/lib/core/utils/logging/serializeResponse.js +1 -1
- package/lib/core/utils/matching/matchRequestUrl.js +1 -1
- package/lib/core/utils/matching/normalizePath.js +2 -2
- package/lib/core/utils/request/getRequestCookies.js +2 -2
- package/lib/core/utils/request/onUnhandledRequest.js +3 -3
- package/lib/core/utils/request/storeResponseCookies.js +2 -2
- package/lib/core/utils/url/getAbsoluteUrl.js +1 -1
- package/lib/core/ws/WebSocketClientManager.js +2 -2
- package/lib/core/ws/handleWebSocketEvent.d.mts +1 -1
- package/lib/core/ws/handleWebSocketEvent.d.ts +1 -1
- package/lib/core/ws/handleWebSocketEvent.js +4 -4
- package/lib/core/ws/utils/attachWebSocketLogger.js +5 -5
- package/lib/core/ws/utils/getPublicData.js +1 -1
- package/lib/core/ws.js +3 -3
- package/lib/iife/index.js +6 -9
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/lib/native/index.d.mts +5 -12
- package/lib/native/index.d.ts +5 -12
- package/lib/native/index.js +12 -12
- package/lib/native/index.js.map +1 -1
- package/lib/native/index.mjs +2 -2
- package/lib/native/index.mjs.map +1 -1
- package/lib/node/index.d.mts +6 -13
- package/lib/node/index.d.ts +6 -13
- package/lib/node/index.js +17 -16
- package/lib/node/index.js.map +1 -1
- package/lib/node/index.mjs +7 -6
- package/lib/node/index.mjs.map +1 -1
- package/native/package.json +25 -1
- package/node/package.json +28 -1
- package/package.json +148 -52
- package/src/browser/setupWorker/glossary.ts +3 -6
- package/src/browser/setupWorker/start/utils/printStartMessage.ts +2 -2
- package/src/core/HttpResponse.ts +16 -18
- package/src/core/graphql.ts +1 -1
- package/src/core/handlers/RequestHandler.ts +5 -3
- package/src/core/passthrough.ts +3 -3
- package/src/native/index.ts +1 -1
- package/src/node/SetupServerApi.ts +10 -6
- package/src/node/SetupServerCommonApi.ts +3 -3
- package/src/package.json +3 -0
- package/src/node/utils/isNodeExceptionLike.ts +0 -14
package/package.json
CHANGED
|
@@ -1,67 +1,162 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "msw",
|
|
3
|
-
"version": "2.
|
|
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
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
"
|
|
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
|
-
"
|
|
19
|
-
"
|
|
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
|
-
"
|
|
23
|
-
"
|
|
24
|
-
|
|
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
|
-
"
|
|
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
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
"
|
|
87
|
+
"browser": null,
|
|
39
88
|
"react-native": {
|
|
40
|
-
"
|
|
41
|
-
|
|
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
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
"
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
"
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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",
|
|
@@ -145,10 +241,8 @@
|
|
|
145
241
|
"@ossjs/release": "^0.8.1",
|
|
146
242
|
"@playwright/test": "^1.48.0",
|
|
147
243
|
"@types/express": "^4.17.21",
|
|
148
|
-
"@types/fs-extra": "^11.0.4",
|
|
149
|
-
"@types/glob": "^8.1.0",
|
|
150
244
|
"@types/json-bigint": "^1.0.4",
|
|
151
|
-
"@types/node": "18.
|
|
245
|
+
"@types/node": "~18.19.28",
|
|
152
246
|
"@typescript-eslint/eslint-plugin": "^8.8.1",
|
|
153
247
|
"@typescript-eslint/parser": "^8.8.1",
|
|
154
248
|
"@web/dev-server": "^0.4.6",
|
|
@@ -158,33 +252,34 @@
|
|
|
158
252
|
"cross-env": "^7.0.3",
|
|
159
253
|
"cross-fetch": "^4.0.0",
|
|
160
254
|
"cz-conventional-changelog": "3.3.0",
|
|
161
|
-
"esbuild": "^0.
|
|
255
|
+
"esbuild": "^0.25.3",
|
|
162
256
|
"esbuild-loader": "^4.2.2",
|
|
163
257
|
"eslint": "^8.57.0",
|
|
164
258
|
"eslint-config-prettier": "^9.1.0",
|
|
165
259
|
"eslint-plugin-prettier": "^5.2.1",
|
|
166
260
|
"express": "^5.0.0",
|
|
167
261
|
"fastify": "^4.26.0",
|
|
168
|
-
"fs-extra": "^11.2.0",
|
|
169
262
|
"fs-teardown": "^0.3.0",
|
|
170
263
|
"glob": "^11.0.0",
|
|
171
264
|
"jsdom": "^25.0.1",
|
|
172
265
|
"json-bigint": "^1.0.0",
|
|
266
|
+
"knip": "^5.51.1",
|
|
173
267
|
"lint-staged": "^15.2.10",
|
|
174
268
|
"page-with": "^0.6.1",
|
|
175
269
|
"prettier": "^3.4.2",
|
|
270
|
+
"publint": "^0.3.12",
|
|
176
271
|
"regenerator-runtime": "^0.14.1",
|
|
177
272
|
"rimraf": "^6.0.1",
|
|
178
273
|
"simple-git-hooks": "^2.9.0",
|
|
179
|
-
"
|
|
180
|
-
"tsup": "^8.3.0",
|
|
274
|
+
"tsup": "^8.4.0",
|
|
181
275
|
"typescript": "^5.5.2",
|
|
182
276
|
"undici": "^6.20.0",
|
|
183
277
|
"url-loader": "^4.1.1",
|
|
184
|
-
"vitest": "^
|
|
278
|
+
"vitest": "^3.1.3",
|
|
185
279
|
"vitest-environment-miniflare": "^2.14.4",
|
|
186
280
|
"webpack": "^5.95.0",
|
|
187
|
-
"webpack-http-server": "^0.5.0"
|
|
281
|
+
"webpack-http-server": "^0.5.0",
|
|
282
|
+
"msw": "2.8.0"
|
|
188
283
|
},
|
|
189
284
|
"peerDependencies": {
|
|
190
285
|
"typescript": ">= 4.8.x"
|
|
@@ -210,17 +305,18 @@
|
|
|
210
305
|
"lint": "eslint \"{cli,src}/**/*.ts\"",
|
|
211
306
|
"build": "pnpm clean && cross-env NODE_ENV=production tsup && pnpm patch:dts",
|
|
212
307
|
"patch:dts": "node \"./config/scripts/patch-ts.js\"",
|
|
213
|
-
"
|
|
308
|
+
"publint": "publint",
|
|
214
309
|
"test": "pnpm test:unit && pnpm test:node && pnpm test:browser && pnpm test:native",
|
|
215
310
|
"test:unit": "vitest",
|
|
216
|
-
"test:node": "vitest --config=./test/node/vitest.config.
|
|
217
|
-
"test:native": "vitest --config=./test/native/vitest.config.
|
|
311
|
+
"test:node": "vitest --config=./test/node/vitest.config.ts",
|
|
312
|
+
"test:native": "vitest --config=./test/native/vitest.config.ts",
|
|
218
313
|
"test:browser": "playwright test -c ./test/browser/playwright.config.ts",
|
|
219
|
-
"test:modules:node": "vitest --config=./test/modules/node/vitest.config.
|
|
314
|
+
"test:modules:node": "vitest run --config=./test/modules/node/vitest.config.ts",
|
|
220
315
|
"test:modules:browser": "playwright test -c ./test/modules/browser/playwright.config.ts",
|
|
221
|
-
"test:e2e": "vitest run --config=./test/e2e/vitest.config.
|
|
222
|
-
"test:ts": "vitest --
|
|
316
|
+
"test:e2e": "vitest run --config=./test/e2e/vitest.config.ts",
|
|
317
|
+
"test:ts": "vitest --config=./test/typings/vitest.config.ts",
|
|
223
318
|
"release": "release publish",
|
|
224
|
-
"postinstall": "node -e \"try{
|
|
319
|
+
"postinstall": "node -e \"try{import('./config/scripts/postinstall.js')}catch(e){}\"",
|
|
320
|
+
"knip": "knip"
|
|
225
321
|
}
|
|
226
322
|
}
|
|
@@ -7,12 +7,9 @@ import {
|
|
|
7
7
|
import { ServiceWorkerMessage } from './start/utils/createMessageChannel'
|
|
8
8
|
import { RequestHandler } from '~/core/handlers/RequestHandler'
|
|
9
9
|
import type { HttpRequestEventMap, Interceptor } from '@mswjs/interceptors'
|
|
10
|
-
import type { Path } from '~/core/utils/matching/matchRequestUrl'
|
|
11
10
|
import type { RequiredDeep } from '~/core/typeUtils'
|
|
12
11
|
import type { WebSocketHandler } from '~/core/handlers/WebSocketHandler'
|
|
13
12
|
|
|
14
|
-
export type ResolvedPath = Path | URL
|
|
15
|
-
|
|
16
13
|
type RequestWithoutMethods = Omit<
|
|
17
14
|
Request,
|
|
18
15
|
| 'text'
|
|
@@ -39,7 +36,7 @@ export interface ServiceWorkerIncomingRequest extends RequestWithoutMethods {
|
|
|
39
36
|
body?: ArrayBuffer | null
|
|
40
37
|
}
|
|
41
38
|
|
|
42
|
-
|
|
39
|
+
type ServiceWorkerIncomingResponse = Pick<
|
|
43
40
|
Response,
|
|
44
41
|
'type' | 'ok' | 'status' | 'statusText' | 'body' | 'headers' | 'redirected'
|
|
45
42
|
> & {
|
|
@@ -70,7 +67,7 @@ export interface ServiceWorkerIncomingEventsMap {
|
|
|
70
67
|
* Map of the events that can be sent to the Service Worker
|
|
71
68
|
* from any execution context.
|
|
72
69
|
*/
|
|
73
|
-
|
|
70
|
+
type ServiceWorkerOutgoingEventTypes =
|
|
74
71
|
| 'MOCK_ACTIVATE'
|
|
75
72
|
| 'MOCK_DEACTIVATE'
|
|
76
73
|
| 'INTEGRITY_CHECK_REQUEST'
|
|
@@ -81,7 +78,7 @@ export interface StringifiedResponse extends ResponseInit {
|
|
|
81
78
|
body: string | ArrayBuffer | ReadableStream<Uint8Array> | null
|
|
82
79
|
}
|
|
83
80
|
|
|
84
|
-
|
|
81
|
+
interface StrictEventListener<EventType extends Event> {
|
|
85
82
|
(event: EventType): void
|
|
86
83
|
}
|
|
87
84
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { ServiceWorkerIncomingEventsMap } from '
|
|
1
|
+
import type { ServiceWorkerIncomingEventsMap } from '../../glossary'
|
|
2
2
|
import { devUtils } from '~/core/utils/internal/devUtils'
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
interface PrintStartMessageArgs {
|
|
5
5
|
quiet?: boolean
|
|
6
6
|
message?: string
|
|
7
7
|
workerUrl?: string
|
package/src/core/HttpResponse.ts
CHANGED
|
@@ -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
|
-
|
|
16
|
-
|
|
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
|
-
|
|
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
|
|
40
|
-
|
|
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?:
|
|
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
|
-
):
|
|
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)
|
|
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
|
-
):
|
|
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
|
/**
|
package/src/core/graphql.ts
CHANGED
|
@@ -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#
|
|
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 {
|
|
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
|
-
:
|
|
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 |
|
|
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]()
|
package/src/core/passthrough.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
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():
|
|
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
|
|
24
|
+
}) as HttpResponse<any>
|
|
25
25
|
}
|
package/src/native/index.ts
CHANGED
|
@@ -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(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
}
|
|
@@ -22,7 +22,7 @@ import { handleWebSocketEvent } from '~/core/ws/handleWebSocketEvent'
|
|
|
22
22
|
import { webSocketInterceptor } from '~/core/ws/webSocketInterceptor'
|
|
23
23
|
import { isHandlerKind } from '~/core/utils/internal/isHandlerKind'
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
const DEFAULT_LISTEN_OPTIONS: RequiredDeep<SharedOptions> = {
|
|
26
26
|
onUnhandledRequest: 'warn',
|
|
27
27
|
}
|
|
28
28
|
|
|
@@ -37,14 +37,14 @@ export class SetupServerCommonApi
|
|
|
37
37
|
private resolvedOptions: RequiredDeep<SharedOptions>
|
|
38
38
|
|
|
39
39
|
constructor(
|
|
40
|
-
interceptors: Array<
|
|
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
|
|
47
|
+
interceptors,
|
|
48
48
|
})
|
|
49
49
|
|
|
50
50
|
this.resolvedOptions = {} as RequiredDeep<SharedOptions>
|
package/src/package.json
ADDED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Determines if the given value is shaped like a Node.js exception.
|
|
3
|
-
* Node.js exceptions have additional information, like
|
|
4
|
-
* the `code` and `errno` properties.
|
|
5
|
-
*
|
|
6
|
-
* In some environments, particularly jsdom/jest these may not
|
|
7
|
-
* instances of `Error` or its subclasses, despite being similar
|
|
8
|
-
* to them.
|
|
9
|
-
*/
|
|
10
|
-
export function isNodeExceptionLike(
|
|
11
|
-
error: unknown,
|
|
12
|
-
): error is NodeJS.ErrnoException {
|
|
13
|
-
return !!error && typeof error === 'object' && 'code' in error
|
|
14
|
-
}
|