msw 2.12.1 → 2.12.3
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/core/{HttpResponse-BpT5A_2L.d.ts → HttpResponse-DC89RDb7.d.ts} +1 -1
- package/lib/core/{HttpResponse-DGUjNQHG.d.mts → HttpResponse-U6SfxBlj.d.mts} +1 -1
- package/lib/core/HttpResponse.d.mts +1 -1
- package/lib/core/HttpResponse.d.ts +1 -1
- package/lib/core/SetupApi.d.mts +1 -1
- package/lib/core/SetupApi.d.ts +1 -1
- package/lib/core/getResponse.d.mts +1 -1
- package/lib/core/getResponse.d.ts +1 -1
- package/lib/core/graphql.d.mts +1 -1
- package/lib/core/graphql.d.ts +1 -1
- package/lib/core/handlers/GraphQLHandler.d.mts +1 -1
- package/lib/core/handlers/GraphQLHandler.d.ts +1 -1
- package/lib/core/handlers/HttpHandler.d.mts +2 -2
- package/lib/core/handlers/HttpHandler.d.ts +2 -2
- package/lib/core/handlers/HttpHandler.js.map +1 -1
- package/lib/core/handlers/HttpHandler.mjs.map +1 -1
- package/lib/core/handlers/RequestHandler.d.mts +1 -1
- package/lib/core/handlers/RequestHandler.d.ts +1 -1
- package/lib/core/http.d.mts +1 -1
- package/lib/core/http.d.ts +1 -1
- package/lib/core/index.d.mts +2 -2
- package/lib/core/index.d.ts +2 -2
- package/lib/core/index.js.map +1 -1
- package/lib/core/index.mjs.map +1 -1
- package/lib/core/passthrough.d.mts +1 -1
- package/lib/core/passthrough.d.ts +1 -1
- package/lib/core/sse.d.mts +1 -1
- package/lib/core/sse.d.ts +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/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/internal/isHandlerKind.d.mts +1 -1
- package/lib/core/utils/internal/isHandlerKind.d.ts +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.d.mts +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +1 -1
- 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/request/toPublicUrl.js +4 -4
- package/lib/core/utils/request/toPublicUrl.js.map +1 -1
- package/lib/core/utils/request/toPublicUrl.mjs +4 -4
- package/lib/core/utils/request/toPublicUrl.mjs.map +1 -1
- package/lib/core/ws/handleWebSocketEvent.d.mts +1 -1
- package/lib/core/ws/handleWebSocketEvent.d.ts +1 -1
- package/lib/iife/index.js +985 -337
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/lib/node/index.mjs +1 -1
- package/package.json +36 -39
- package/src/core/handlers/HttpHandler.ts +1 -1
- package/src/core/index.ts +5 -0
- package/src/core/utils/request/onUnhandledRequest.node.test.ts +62 -0
- package/src/core/utils/request/toPublicUrl.node.test.ts +17 -0
- package/src/core/utils/request/toPublicUrl.test.ts +1 -3
- package/src/core/utils/request/toPublicUrl.ts +8 -7
package/lib/mockServiceWorker.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* - Please do NOT modify this file.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
const PACKAGE_VERSION = '2.12.
|
|
10
|
+
const PACKAGE_VERSION = '2.12.3'
|
|
11
11
|
const INTEGRITY_CHECKSUM = '4db4a41e972cec1b64cc569c66952d82'
|
|
12
12
|
const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
|
|
13
13
|
const activeClientIds = new Set()
|
package/lib/node/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/node/SetupServerApi.ts
|
|
2
|
-
import { AsyncLocalStorage } from "
|
|
2
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
3
3
|
import { ClientRequestInterceptor } from "@mswjs/interceptors/ClientRequest";
|
|
4
4
|
import { XMLHttpRequestInterceptor } from "@mswjs/interceptors/XMLHttpRequest";
|
|
5
5
|
import { FetchInterceptor } from "@mswjs/interceptors/fetch";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "msw",
|
|
3
|
-
"version": "2.12.
|
|
3
|
+
"version": "2.12.3",
|
|
4
4
|
"description": "Seamless REST/GraphQL API mocking library for browser and Node.js.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./lib/core/index.js",
|
|
@@ -60,8 +60,6 @@
|
|
|
60
60
|
}
|
|
61
61
|
},
|
|
62
62
|
"./node": {
|
|
63
|
-
"browser": null,
|
|
64
|
-
"react-native": null,
|
|
65
63
|
"module-sync": {
|
|
66
64
|
"types": "./lib/node/index.d.mts",
|
|
67
65
|
"default": "./lib/node/index.mjs"
|
|
@@ -78,6 +76,8 @@
|
|
|
78
76
|
"types": "./lib/node/index.d.mts",
|
|
79
77
|
"default": "./lib/node/index.mjs"
|
|
80
78
|
},
|
|
79
|
+
"browser": null,
|
|
80
|
+
"react-native": null,
|
|
81
81
|
"default": {
|
|
82
82
|
"types": "./lib/node/index.d.ts",
|
|
83
83
|
"default": "./lib/node/index.js"
|
|
@@ -217,9 +217,9 @@
|
|
|
217
217
|
"@inquirer/confirm": "^5.0.0",
|
|
218
218
|
"@mswjs/interceptors": "^0.40.0",
|
|
219
219
|
"@open-draft/deferred-promise": "^2.2.0",
|
|
220
|
-
"@types/statuses": "^2.0.
|
|
220
|
+
"@types/statuses": "^2.0.6",
|
|
221
221
|
"cookie": "^1.0.2",
|
|
222
|
-
"graphql": "^16.
|
|
222
|
+
"graphql": "^16.12.0",
|
|
223
223
|
"headers-polyfill": "^4.0.2",
|
|
224
224
|
"is-node-process": "^1.2.0",
|
|
225
225
|
"outvariant": "^1.4.3",
|
|
@@ -229,66 +229,63 @@
|
|
|
229
229
|
"statuses": "^2.0.2",
|
|
230
230
|
"strict-event-emitter": "^0.5.1",
|
|
231
231
|
"tough-cookie": "^6.0.0",
|
|
232
|
-
"type-fest": "^
|
|
232
|
+
"type-fest": "^5.2.0",
|
|
233
233
|
"until-async": "^3.0.2",
|
|
234
234
|
"yargs": "^17.7.2"
|
|
235
235
|
},
|
|
236
236
|
"devDependencies": {
|
|
237
|
-
"@commitlint/cli": "^
|
|
238
|
-
"@commitlint/config-conventional": "^
|
|
237
|
+
"@commitlint/cli": "^20.1.0",
|
|
238
|
+
"@commitlint/config-conventional": "^20.0.0",
|
|
239
239
|
"@epic-web/test-server": "^0.1.6",
|
|
240
240
|
"@eslint/eslintrc": "^3.3.1",
|
|
241
|
-
"@eslint/js": "^9.
|
|
242
|
-
"@fastify/websocket": "^
|
|
241
|
+
"@eslint/js": "^9.39.1",
|
|
242
|
+
"@fastify/websocket": "^11.2.0",
|
|
243
243
|
"@graphql-typed-document-node/core": "^3.2.0",
|
|
244
244
|
"@open-draft/test-server": "^0.4.2",
|
|
245
|
-
"@playwright/test": "^1.50.1",
|
|
246
245
|
"@ossjs/release": "^0.10.0",
|
|
247
|
-
"@
|
|
248
|
-
"@types/
|
|
249
|
-
"@types/express": "^4.17.21",
|
|
246
|
+
"@playwright/test": "^1.50.1",
|
|
247
|
+
"@types/express": "^5.0.5",
|
|
250
248
|
"@types/json-bigint": "^1.0.4",
|
|
251
|
-
"@types/node": "
|
|
252
|
-
"@types/serviceworker": "^0.0.
|
|
253
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
254
|
-
"@typescript-eslint/parser": "^8.
|
|
255
|
-
"@web/dev-server": "^0.
|
|
256
|
-
"axios": "^1.
|
|
249
|
+
"@types/node": "~20.19.25",
|
|
250
|
+
"@types/serviceworker": "^0.0.167",
|
|
251
|
+
"@typescript-eslint/eslint-plugin": "^8.47.0",
|
|
252
|
+
"@typescript-eslint/parser": "^8.47.0",
|
|
253
|
+
"@web/dev-server": "^0.4.6",
|
|
254
|
+
"axios": "^1.13.2",
|
|
257
255
|
"babel-minify": "^0.5.1",
|
|
258
256
|
"commitizen": "^4.3.1",
|
|
259
|
-
"cross-env": "^
|
|
260
|
-
"cross-fetch": "^4.
|
|
257
|
+
"cross-env": "^10.1.0",
|
|
258
|
+
"cross-fetch": "^4.1.0",
|
|
261
259
|
"cz-conventional-changelog": "3.3.0",
|
|
262
|
-
"esbuild": "^0.
|
|
263
|
-
"esbuild-loader": "^4.
|
|
264
|
-
"eslint": "^9.
|
|
260
|
+
"esbuild": "^0.27.0",
|
|
261
|
+
"esbuild-loader": "^4.4.0",
|
|
262
|
+
"eslint": "^9.39.1",
|
|
265
263
|
"eslint-config-prettier": "^10.1.8",
|
|
266
264
|
"eslint-plugin-prettier": "^5.5.4",
|
|
267
|
-
"express": "^5.
|
|
268
|
-
"fastify": "^
|
|
269
|
-
"fs-extra": "^11.2.0",
|
|
265
|
+
"express": "^5.1.0",
|
|
266
|
+
"fastify": "^5.6.2",
|
|
270
267
|
"fs-teardown": "^0.3.0",
|
|
271
|
-
"glob": "^
|
|
268
|
+
"glob": "^13.0.0",
|
|
272
269
|
"jsdom": "^25.0.1",
|
|
273
270
|
"json-bigint": "^1.0.0",
|
|
274
|
-
"knip": "^5.
|
|
271
|
+
"knip": "^5.70.1",
|
|
275
272
|
"lint-staged": "^15.2.10",
|
|
276
273
|
"page-with": "^0.6.1",
|
|
277
274
|
"prettier": "^3.6.2",
|
|
278
|
-
"publint": "^0.3.
|
|
275
|
+
"publint": "^0.3.15",
|
|
279
276
|
"regenerator-runtime": "^0.14.1",
|
|
280
|
-
"rimraf": "^6.
|
|
281
|
-
"simple-git-hooks": "^2.
|
|
282
|
-
"tsup": "^8.
|
|
283
|
-
"typescript": "^5.9.
|
|
284
|
-
"typescript-eslint": "^8.
|
|
285
|
-
"undici": "^
|
|
277
|
+
"rimraf": "^6.1.2",
|
|
278
|
+
"simple-git-hooks": "^2.13.1",
|
|
279
|
+
"tsup": "^8.5.1",
|
|
280
|
+
"typescript": "^5.9.3",
|
|
281
|
+
"typescript-eslint": "^8.47.0",
|
|
282
|
+
"undici": "^7.16.0",
|
|
286
283
|
"url-loader": "^4.1.1",
|
|
287
|
-
"vitest": "^
|
|
284
|
+
"vitest": "^4.0.13",
|
|
288
285
|
"vitest-environment-miniflare": "^2.14.4",
|
|
289
286
|
"webpack": "^5.95.0",
|
|
290
287
|
"webpack-http-server": "^0.5.0",
|
|
291
|
-
"msw": "2.12.
|
|
288
|
+
"msw": "2.12.3"
|
|
292
289
|
},
|
|
293
290
|
"peerDependencies": {
|
|
294
291
|
"typescript": ">= 4.8.x"
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
ResponseResolver,
|
|
22
22
|
} from './RequestHandler'
|
|
23
23
|
|
|
24
|
-
type HttpHandlerMethod = string | RegExp
|
|
24
|
+
export type HttpHandlerMethod = string | RegExp
|
|
25
25
|
|
|
26
26
|
export interface HttpHandlerInfo extends RequestHandlerDefaultInfo {
|
|
27
27
|
method: HttpHandlerMethod
|
package/src/core/index.ts
CHANGED
|
@@ -51,11 +51,15 @@ export type {
|
|
|
51
51
|
DefaultBodyType,
|
|
52
52
|
DefaultRequestMultipartBody,
|
|
53
53
|
JsonBodyType,
|
|
54
|
+
ResponseResolverInfo,
|
|
54
55
|
} from './handlers/RequestHandler'
|
|
55
56
|
|
|
56
57
|
export type {
|
|
57
58
|
RequestQuery,
|
|
58
59
|
HttpRequestParsedResult,
|
|
60
|
+
HttpHandlerInfo,
|
|
61
|
+
HttpRequestResolverExtras,
|
|
62
|
+
HttpHandlerMethod,
|
|
59
63
|
HttpCustomPredicate,
|
|
60
64
|
} from './handlers/HttpHandler'
|
|
61
65
|
export type { HttpRequestHandler, HttpResponseResolver } from './http'
|
|
@@ -75,6 +79,7 @@ export type { WebSocketData, WebSocketEventListener } from './ws'
|
|
|
75
79
|
|
|
76
80
|
export type { Path, PathParams, Match } from './utils/matching/matchRequestUrl'
|
|
77
81
|
export type { ParsedGraphQLRequest } from './utils/internal/parseGraphQLRequest'
|
|
82
|
+
export type { ResponseResolutionContext } from './utils/executeHandlers'
|
|
78
83
|
|
|
79
84
|
export * from './HttpResponse'
|
|
80
85
|
export * from './delay'
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// @vitest-environment node
|
|
2
|
+
import { onUnhandledRequest } from './onUnhandledRequest'
|
|
3
|
+
|
|
4
|
+
const fixtures = {
|
|
5
|
+
warningWithoutSuggestions: (url = `/api`) => `\
|
|
6
|
+
[MSW] Warning: intercepted a request without a matching request handler:
|
|
7
|
+
|
|
8
|
+
• GET ${url}
|
|
9
|
+
|
|
10
|
+
If you still wish to intercept this unhandled request, please create a request handler for it.
|
|
11
|
+
Read more: https://mswjs.io/docs/http/intercepting-requests`,
|
|
12
|
+
warningWithResponseBody: (url = `/api`) => `\
|
|
13
|
+
[MSW] Warning: intercepted a request without a matching request handler:
|
|
14
|
+
|
|
15
|
+
• POST ${url}
|
|
16
|
+
|
|
17
|
+
• Request body: {"variables":{"id":"abc-123"},"query":"query UserName($id: String!) { user(id: $id) { name } }"}
|
|
18
|
+
|
|
19
|
+
If you still wish to intercept this unhandled request, please create a request handler for it.
|
|
20
|
+
Read more: https://mswjs.io/docs/http/intercepting-requests`,
|
|
21
|
+
|
|
22
|
+
errorWithoutSuggestions: `\
|
|
23
|
+
[MSW] Error: intercepted a request without a matching request handler:
|
|
24
|
+
|
|
25
|
+
• GET /api
|
|
26
|
+
|
|
27
|
+
If you still wish to intercept this unhandled request, please create a request handler for it.
|
|
28
|
+
Read more: https://mswjs.io/docs/http/intercepting-requests`,
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
beforeAll(() => {
|
|
32
|
+
vi.spyOn(console, 'warn').mockImplementation(() => void 0)
|
|
33
|
+
vi.spyOn(console, 'error').mockImplementation(() => void 0)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
afterEach(() => {
|
|
37
|
+
vi.clearAllMocks()
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
afterAll(() => {
|
|
41
|
+
vi.restoreAllMocks()
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
test('prints with an absolute URL and search params', async () => {
|
|
45
|
+
await onUnhandledRequest(
|
|
46
|
+
new Request(new URL('https://mswjs.io/api?foo=boo')),
|
|
47
|
+
'warn',
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
expect(console.warn).toHaveBeenCalledWith(
|
|
51
|
+
fixtures.warningWithoutSuggestions(`https://mswjs.io/api?foo=boo`),
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
await onUnhandledRequest(
|
|
55
|
+
new Request(new URL('http://localhost/api?foo=boo')),
|
|
56
|
+
'warn',
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
expect(console.warn).toHaveBeenCalledWith(
|
|
60
|
+
fixtures.warningWithoutSuggestions(`http://localhost/api?foo=boo`),
|
|
61
|
+
)
|
|
62
|
+
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// @vitest-environment node
|
|
2
|
+
import { toPublicUrl } from './toPublicUrl'
|
|
3
|
+
|
|
4
|
+
test('returns an absolute request URL without search params', () => {
|
|
5
|
+
expect(toPublicUrl(new URL('https://test.mswjs.io/path'))).toBe(
|
|
6
|
+
'https://test.mswjs.io/path',
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
expect(toPublicUrl(new URL('http://192.168.0.10/path'))).toBe(
|
|
10
|
+
'http://192.168.0.10/path',
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
expect(
|
|
14
|
+
toPublicUrl(new URL('http://localhost/path?foo=bar')),
|
|
15
|
+
'Must not return relative URL in Node.js',
|
|
16
|
+
).toBe('http://localhost/path')
|
|
17
|
+
})
|
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
* to the current origin. Otherwise returns an absolute URL.
|
|
4
4
|
*/
|
|
5
5
|
export function toPublicUrl(url: string | URL): string {
|
|
6
|
-
if (typeof location === 'undefined') {
|
|
7
|
-
return url.toString()
|
|
8
|
-
}
|
|
9
|
-
|
|
10
6
|
const urlInstance = url instanceof URL ? url : new URL(url)
|
|
11
7
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
if (
|
|
9
|
+
typeof location !== 'undefined' &&
|
|
10
|
+
urlInstance.origin === location.origin
|
|
11
|
+
) {
|
|
12
|
+
return urlInstance.pathname
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return urlInstance.origin + urlInstance.pathname
|
|
15
16
|
}
|