msw 2.12.10 → 2.12.12

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 (91) hide show
  1. package/config/scripts/postinstall.js +2 -2
  2. package/lib/core/{HttpResponse-Cw4ELwIN.d.mts → HttpResponse-B9rGc56D.d.mts} +1 -1
  3. package/lib/core/{HttpResponse-CVs3ngx3.d.ts → HttpResponse-Dz84tqeA.d.ts} +1 -1
  4. package/lib/core/HttpResponse.d.mts +1 -1
  5. package/lib/core/HttpResponse.d.ts +1 -1
  6. package/lib/core/SetupApi.d.mts +1 -1
  7. package/lib/core/SetupApi.d.ts +1 -1
  8. package/lib/core/delay.js +7 -1
  9. package/lib/core/delay.js.map +1 -1
  10. package/lib/core/delay.mjs +7 -1
  11. package/lib/core/delay.mjs.map +1 -1
  12. package/lib/core/getResponse.d.mts +1 -1
  13. package/lib/core/getResponse.d.ts +1 -1
  14. package/lib/core/graphql.d.mts +1 -1
  15. package/lib/core/graphql.d.ts +1 -1
  16. package/lib/core/handlers/GraphQLHandler.d.mts +1 -1
  17. package/lib/core/handlers/GraphQLHandler.d.ts +1 -1
  18. package/lib/core/handlers/GraphQLHandler.js.map +1 -1
  19. package/lib/core/handlers/GraphQLHandler.mjs.map +1 -1
  20. package/lib/core/handlers/HttpHandler.d.mts +1 -1
  21. package/lib/core/handlers/HttpHandler.d.ts +1 -1
  22. package/lib/core/handlers/RequestHandler.d.mts +1 -1
  23. package/lib/core/handlers/RequestHandler.d.ts +1 -1
  24. package/lib/core/http.d.mts +1 -1
  25. package/lib/core/http.d.ts +1 -1
  26. package/lib/core/index.d.mts +3 -3
  27. package/lib/core/index.d.ts +3 -3
  28. package/lib/core/index.js +6 -4
  29. package/lib/core/index.js.map +1 -1
  30. package/lib/core/index.mjs +8 -3
  31. package/lib/core/index.mjs.map +1 -1
  32. package/lib/core/passthrough.d.mts +1 -1
  33. package/lib/core/passthrough.d.ts +1 -1
  34. package/lib/core/sse.d.mts +1 -1
  35. package/lib/core/sse.d.ts +1 -1
  36. package/lib/core/sse.js +1 -1
  37. package/lib/core/sse.js.map +1 -1
  38. package/lib/core/sse.mjs +1 -1
  39. package/lib/core/sse.mjs.map +1 -1
  40. package/lib/core/utils/HttpResponse/decorators.d.mts +1 -1
  41. package/lib/core/utils/HttpResponse/decorators.d.ts +1 -1
  42. package/lib/core/utils/executeHandlers.d.mts +1 -1
  43. package/lib/core/utils/executeHandlers.d.ts +1 -1
  44. package/lib/core/utils/handleRequest.d.mts +1 -1
  45. package/lib/core/utils/handleRequest.d.ts +1 -1
  46. package/lib/core/utils/internal/hasRefCounted.d.mts +3 -0
  47. package/lib/core/utils/internal/hasRefCounted.d.ts +3 -0
  48. package/lib/core/utils/internal/hasRefCounted.js +27 -0
  49. package/lib/core/utils/internal/hasRefCounted.js.map +1 -0
  50. package/lib/core/utils/internal/hasRefCounted.mjs +7 -0
  51. package/lib/core/utils/internal/hasRefCounted.mjs.map +1 -0
  52. package/lib/core/utils/internal/isHandlerKind.d.mts +1 -1
  53. package/lib/core/utils/internal/isHandlerKind.d.ts +1 -1
  54. package/lib/core/utils/internal/parseGraphQLRequest.d.mts +1 -1
  55. package/lib/core/utils/internal/parseGraphQLRequest.d.ts +1 -1
  56. package/lib/core/utils/internal/parseGraphQLRequest.js +1 -1
  57. package/lib/core/utils/internal/parseGraphQLRequest.js.map +1 -1
  58. package/lib/core/utils/internal/parseGraphQLRequest.mjs +1 -1
  59. package/lib/core/utils/internal/parseGraphQLRequest.mjs.map +1 -1
  60. package/lib/core/utils/internal/parseMultipartData.d.mts +1 -1
  61. package/lib/core/utils/internal/parseMultipartData.d.ts +1 -1
  62. package/lib/core/utils/internal/parseMultipartData.js +3 -1
  63. package/lib/core/utils/internal/parseMultipartData.js.map +1 -1
  64. package/lib/core/utils/internal/parseMultipartData.mjs +3 -1
  65. package/lib/core/utils/internal/parseMultipartData.mjs.map +1 -1
  66. package/lib/core/utils/internal/requestHandlerUtils.d.mts +1 -1
  67. package/lib/core/utils/internal/requestHandlerUtils.d.ts +1 -1
  68. package/lib/core/ws/WebSocketIndexedDBClientStore.js +1 -1
  69. package/lib/core/ws/WebSocketIndexedDBClientStore.js.map +1 -1
  70. package/lib/core/ws/WebSocketIndexedDBClientStore.mjs +1 -1
  71. package/lib/core/ws/WebSocketIndexedDBClientStore.mjs.map +1 -1
  72. package/lib/core/ws/handleWebSocketEvent.d.mts +1 -1
  73. package/lib/core/ws/handleWebSocketEvent.d.ts +1 -1
  74. package/lib/core/ws.js +2 -4
  75. package/lib/core/ws.js.map +1 -1
  76. package/lib/core/ws.mjs +2 -4
  77. package/lib/core/ws.mjs.map +1 -1
  78. package/lib/iife/index.js +18 -14
  79. package/lib/iife/index.js.map +1 -1
  80. package/lib/mockServiceWorker.js +1 -1
  81. package/package.json +3 -3
  82. package/src/core/delay.ts +13 -1
  83. package/src/core/handlers/GraphQLHandler.ts +1 -1
  84. package/src/core/index.ts +8 -3
  85. package/src/core/sse.ts +1 -1
  86. package/src/core/utils/internal/hasRefCounted.test.ts +16 -0
  87. package/src/core/utils/internal/hasRefCounted.ts +8 -0
  88. package/src/core/utils/internal/parseGraphQLRequest.ts +1 -1
  89. package/src/core/utils/internal/parseMultipartData.ts +3 -1
  90. package/src/core/ws/WebSocketIndexedDBClientStore.ts +1 -2
  91. package/src/core/ws.ts +2 -7
@@ -7,7 +7,7 @@
7
7
  * - Please do NOT modify this file.
8
8
  */
9
9
 
10
- const PACKAGE_VERSION = '2.12.10'
10
+ const PACKAGE_VERSION = '2.12.12'
11
11
  const INTEGRITY_CHECKSUM = '4db4a41e972cec1b64cc569c66952d82'
12
12
  const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
13
13
  const activeClientIds = new Set()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "msw",
3
- "version": "2.12.10",
3
+ "version": "2.12.12",
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",
@@ -251,7 +251,7 @@
251
251
  "@typescript-eslint/eslint-plugin": "^8.47.0",
252
252
  "@typescript-eslint/parser": "^8.47.0",
253
253
  "@web/dev-server": "^0.4.6",
254
- "axios": "^1.13.2",
254
+ "axios": "^1.13.5",
255
255
  "babel-minify": "^0.5.1",
256
256
  "commitizen": "^4.3.1",
257
257
  "cross-env": "^10.1.0",
@@ -285,7 +285,7 @@
285
285
  "vitest-environment-miniflare": "^2.14.4",
286
286
  "webpack": "^5.95.0",
287
287
  "webpack-http-server": "^0.5.0",
288
- "msw": "2.12.10"
288
+ "msw": "2.12.12"
289
289
  },
290
290
  "peerDependencies": {
291
291
  "typescript": ">= 4.8.x"
package/src/core/delay.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { isNodeProcess } from 'is-node-process'
2
+ import { hasRefCounted } from './utils/internal/hasRefCounted'
2
3
 
3
4
  export const SET_TIMEOUT_MAX_ALLOWED_INT = 2147483647
4
5
  export const MIN_SERVER_RESPONSE_TIME = 100
@@ -66,5 +67,16 @@ export async function delay(
66
67
  delayTime = durationOrMode
67
68
  }
68
69
 
69
- return new Promise((resolve) => setTimeout(resolve, delayTime))
70
+ return new Promise((resolve) => {
71
+ const timeoutId = setTimeout(resolve, delayTime)
72
+
73
+ if (
74
+ delayTime === SET_TIMEOUT_MAX_ALLOWED_INT &&
75
+ isNodeProcess() &&
76
+ hasRefCounted(timeoutId)
77
+ ) {
78
+ // Prevent the process from hanging if this is the only active ref.
79
+ timeoutId.unref()
80
+ }
81
+ })
70
82
  }
@@ -120,7 +120,7 @@ export function isDocumentNode(
120
120
  }
121
121
 
122
122
  function isDocumentTypeDecoration(
123
- value: any,
123
+ value: unknown,
124
124
  ): value is DocumentTypeDecoration<any, any> {
125
125
  return value instanceof String
126
126
  }
package/src/core/index.ts CHANGED
@@ -34,7 +34,7 @@ export type AnyHandler = HttpHandler | GraphQLHandler | WebSocketHandler
34
34
 
35
35
  /* Utils */
36
36
  export { matchRequestUrl } from './utils/matching/matchRequestUrl'
37
- export * from './utils/handleRequest'
37
+ export { handleRequest, type HandleRequestOptions } from './utils/handleRequest'
38
38
  export {
39
39
  onUnhandledRequest,
40
40
  type UnhandledRequestStrategy,
@@ -92,8 +92,13 @@ export type { Path, PathParams, Match } from './utils/matching/matchRequestUrl'
92
92
  export type { ParsedGraphQLRequest } from './utils/internal/parseGraphQLRequest'
93
93
  export type { ResponseResolutionContext } from './utils/executeHandlers'
94
94
 
95
- export * from './HttpResponse'
96
- export * from './delay'
95
+ export {
96
+ HttpResponse,
97
+ type HttpResponseInit,
98
+ type StrictRequest,
99
+ type StrictResponse,
100
+ } from './HttpResponse'
101
+ export { delay, type DelayMode } from './delay'
97
102
  export { bypass } from './bypass'
98
103
  export { passthrough } from './passthrough'
99
104
  export { isCommonAssetRequest } from './isCommonAssetRequest'
package/src/core/sse.ts CHANGED
@@ -333,7 +333,7 @@ class ServerSentEventClient<
333
333
  }
334
334
 
335
335
  if (message.event) {
336
- frames.push(`event:${message.event?.toString()}`)
336
+ frames.push(`event:${message.event.toString()}`)
337
337
  }
338
338
 
339
339
  if (message.data != null) {
@@ -0,0 +1,16 @@
1
+ import { hasRefCounted } from './hasRefCounted'
2
+
3
+ it('returns true for objects with ref and unref methods', () => {
4
+ expect(
5
+ hasRefCounted({
6
+ ref() {},
7
+ unref() {},
8
+ }),
9
+ ).toBe(true)
10
+ })
11
+
12
+ it('returns false for a non-refcounted object', () => {
13
+ expect(hasRefCounted({})).toBe(false)
14
+ expect(hasRefCounted({ ref() {} })).toBe(false)
15
+ expect(hasRefCounted({ unref() {} })).toBe(false)
16
+ })
@@ -0,0 +1,8 @@
1
+ export function hasRefCounted<T extends object>(
2
+ value: T,
3
+ ): value is T & NodeJS.RefCounted {
4
+ return (
5
+ typeof Reflect.get(value, 'ref') === 'function' &&
6
+ typeof Reflect.get(value, 'unref') === 'function'
7
+ )
8
+ }
@@ -84,7 +84,7 @@ function extractMultipartVariables<VariablesType extends GraphQLVariables>(
84
84
 
85
85
  for (const path of paths) {
86
86
  if (!(path in target)) {
87
- throw new Error(`Property '${paths}' is not in operations.`)
87
+ throw new Error(`Property '${path}' is not in operations.`)
88
88
  }
89
89
 
90
90
  target = target[path]
@@ -62,7 +62,9 @@ export function parseMultipartData<T extends DefaultRequestMultipartBody>(
62
62
  return undefined
63
63
  }
64
64
 
65
- const boundaryRegExp = new RegExp(`--+${boundary}`)
65
+ const boundaryRegExp = new RegExp(
66
+ `--+${boundary.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`,
67
+ )
66
68
  const fields = data
67
69
  .split(boundaryRegExp)
68
70
  .filter((chunk) => chunk.startsWith('\r\n') && chunk.endsWith('\r\n'))
@@ -56,8 +56,7 @@ export class WebSocketIndexedDBClientStore implements WebSocketClientStore {
56
56
  promise.resolve(request.result)
57
57
  }
58
58
  request.onerror = () => {
59
- // eslint-disable-next-line no-console
60
- console.log(request.error)
59
+ console.error(request.error)
61
60
  promise.reject(
62
61
  new Error(
63
62
  `Failed to get all WebSocket clients. There is likely an additional output above.`,
package/src/core/ws.ts CHANGED
@@ -8,18 +8,13 @@ import {
8
8
  kEmitter,
9
9
  type WebSocketHandlerEventMap,
10
10
  } from './handlers/WebSocketHandler'
11
+ import { hasRefCounted } from './utils/internal/hasRefCounted'
11
12
  import { Path, isPath } from './utils/matching/matchRequestUrl'
12
13
  import { WebSocketClientManager } from './ws/WebSocketClientManager'
13
14
 
14
- function isBroadcastChannelWithUnref(
15
- channel: BroadcastChannel,
16
- ): channel is BroadcastChannel & NodeJS.RefCounted {
17
- return typeof Reflect.get(channel, 'unref') !== 'undefined'
18
- }
19
-
20
15
  const webSocketChannel = new BroadcastChannel('msw:websocket-client-manager')
21
16
 
22
- if (isBroadcastChannelWithUnref(webSocketChannel)) {
17
+ if (hasRefCounted(webSocketChannel)) {
23
18
  // Allows the Node.js thread to exit if it is the only active handle in the event system.
24
19
  // https://nodejs.org/api/worker_threads.html#broadcastchannelunref
25
20
  webSocketChannel.unref()