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.
Files changed (59) hide show
  1. package/lib/core/{HttpResponse-BpT5A_2L.d.ts → HttpResponse-DC89RDb7.d.ts} +1 -1
  2. package/lib/core/{HttpResponse-DGUjNQHG.d.mts → HttpResponse-U6SfxBlj.d.mts} +1 -1
  3. package/lib/core/HttpResponse.d.mts +1 -1
  4. package/lib/core/HttpResponse.d.ts +1 -1
  5. package/lib/core/SetupApi.d.mts +1 -1
  6. package/lib/core/SetupApi.d.ts +1 -1
  7. package/lib/core/getResponse.d.mts +1 -1
  8. package/lib/core/getResponse.d.ts +1 -1
  9. package/lib/core/graphql.d.mts +1 -1
  10. package/lib/core/graphql.d.ts +1 -1
  11. package/lib/core/handlers/GraphQLHandler.d.mts +1 -1
  12. package/lib/core/handlers/GraphQLHandler.d.ts +1 -1
  13. package/lib/core/handlers/HttpHandler.d.mts +2 -2
  14. package/lib/core/handlers/HttpHandler.d.ts +2 -2
  15. package/lib/core/handlers/HttpHandler.js.map +1 -1
  16. package/lib/core/handlers/HttpHandler.mjs.map +1 -1
  17. package/lib/core/handlers/RequestHandler.d.mts +1 -1
  18. package/lib/core/handlers/RequestHandler.d.ts +1 -1
  19. package/lib/core/http.d.mts +1 -1
  20. package/lib/core/http.d.ts +1 -1
  21. package/lib/core/index.d.mts +2 -2
  22. package/lib/core/index.d.ts +2 -2
  23. package/lib/core/index.js.map +1 -1
  24. package/lib/core/index.mjs.map +1 -1
  25. package/lib/core/passthrough.d.mts +1 -1
  26. package/lib/core/passthrough.d.ts +1 -1
  27. package/lib/core/sse.d.mts +1 -1
  28. package/lib/core/sse.d.ts +1 -1
  29. package/lib/core/utils/HttpResponse/decorators.d.mts +1 -1
  30. package/lib/core/utils/HttpResponse/decorators.d.ts +1 -1
  31. package/lib/core/utils/executeHandlers.d.mts +1 -1
  32. package/lib/core/utils/executeHandlers.d.ts +1 -1
  33. package/lib/core/utils/handleRequest.d.mts +1 -1
  34. package/lib/core/utils/handleRequest.d.ts +1 -1
  35. package/lib/core/utils/internal/isHandlerKind.d.mts +1 -1
  36. package/lib/core/utils/internal/isHandlerKind.d.ts +1 -1
  37. package/lib/core/utils/internal/parseGraphQLRequest.d.mts +1 -1
  38. package/lib/core/utils/internal/parseGraphQLRequest.d.ts +1 -1
  39. package/lib/core/utils/internal/parseMultipartData.d.mts +1 -1
  40. package/lib/core/utils/internal/parseMultipartData.d.ts +1 -1
  41. package/lib/core/utils/internal/requestHandlerUtils.d.mts +1 -1
  42. package/lib/core/utils/internal/requestHandlerUtils.d.ts +1 -1
  43. package/lib/core/utils/request/toPublicUrl.js +4 -4
  44. package/lib/core/utils/request/toPublicUrl.js.map +1 -1
  45. package/lib/core/utils/request/toPublicUrl.mjs +4 -4
  46. package/lib/core/utils/request/toPublicUrl.mjs.map +1 -1
  47. package/lib/core/ws/handleWebSocketEvent.d.mts +1 -1
  48. package/lib/core/ws/handleWebSocketEvent.d.ts +1 -1
  49. package/lib/iife/index.js +985 -337
  50. package/lib/iife/index.js.map +1 -1
  51. package/lib/mockServiceWorker.js +1 -1
  52. package/lib/node/index.mjs +1 -1
  53. package/package.json +36 -39
  54. package/src/core/handlers/HttpHandler.ts +1 -1
  55. package/src/core/index.ts +5 -0
  56. package/src/core/utils/request/onUnhandledRequest.node.test.ts +62 -0
  57. package/src/core/utils/request/toPublicUrl.node.test.ts +17 -0
  58. package/src/core/utils/request/toPublicUrl.test.ts +1 -3
  59. package/src/core/utils/request/toPublicUrl.ts +8 -7
@@ -7,7 +7,7 @@
7
7
  * - Please do NOT modify this file.
8
8
  */
9
9
 
10
- const PACKAGE_VERSION = '2.12.1'
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()
@@ -1,5 +1,5 @@
1
1
  // src/node/SetupServerApi.ts
2
- import { AsyncLocalStorage } from "node:async_hooks";
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.1",
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.4",
220
+ "@types/statuses": "^2.0.6",
221
221
  "cookie": "^1.0.2",
222
- "graphql": "^16.8.1",
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": "^4.26.1",
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": "^18.4.4",
238
- "@commitlint/config-conventional": "^18.4.4",
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.34.0",
242
- "@fastify/websocket": "^8.3.1",
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
- "@swc/core": "^1.13.5",
248
- "@types/eslint__js": "^8.42.3",
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": "18.x",
252
- "@types/serviceworker": "^0.0.158",
253
- "@typescript-eslint/eslint-plugin": "^8.42.0",
254
- "@typescript-eslint/parser": "^8.42.0",
255
- "@web/dev-server": "^0.1.38",
256
- "axios": "^1.6.5",
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": "^7.0.3",
260
- "cross-fetch": "^4.0.0",
257
+ "cross-env": "^10.1.0",
258
+ "cross-fetch": "^4.1.0",
261
259
  "cz-conventional-changelog": "3.3.0",
262
- "esbuild": "^0.25.3",
263
- "esbuild-loader": "^4.2.2",
264
- "eslint": "^9.34.0",
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.0.0",
268
- "fastify": "^4.26.0",
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": "^11.0.0",
268
+ "glob": "^13.0.0",
272
269
  "jsdom": "^25.0.1",
273
270
  "json-bigint": "^1.0.0",
274
- "knip": "^5.51.1",
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.12",
275
+ "publint": "^0.3.15",
279
276
  "regenerator-runtime": "^0.14.1",
280
- "rimraf": "^6.0.1",
281
- "simple-git-hooks": "^2.9.0",
282
- "tsup": "^8.4.0",
283
- "typescript": "^5.9.2",
284
- "typescript-eslint": "^8.42.0",
285
- "undici": "^6.20.0",
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": "^3.2.4",
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.1"
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
+ })
@@ -1,6 +1,4 @@
1
- /**
2
- * @vitest-environment jsdom
3
- */
1
+ // @vitest-environment jsdom
4
2
  import { toPublicUrl } from './toPublicUrl'
5
3
 
6
4
  test('returns an absolute request URL without search params', () => {
@@ -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
- return urlInstance.origin === location.origin
13
- ? urlInstance.pathname
14
- : urlInstance.origin + urlInstance.pathname
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
  }