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.
- package/config/scripts/postinstall.js +2 -2
- package/lib/core/{HttpResponse-Cw4ELwIN.d.mts → HttpResponse-B9rGc56D.d.mts} +1 -1
- package/lib/core/{HttpResponse-CVs3ngx3.d.ts → HttpResponse-Dz84tqeA.d.ts} +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/delay.js +7 -1
- package/lib/core/delay.js.map +1 -1
- package/lib/core/delay.mjs +7 -1
- package/lib/core/delay.mjs.map +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/GraphQLHandler.js.map +1 -1
- package/lib/core/handlers/GraphQLHandler.mjs.map +1 -1
- package/lib/core/handlers/HttpHandler.d.mts +1 -1
- package/lib/core/handlers/HttpHandler.d.ts +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 +3 -3
- package/lib/core/index.d.ts +3 -3
- package/lib/core/index.js +6 -4
- package/lib/core/index.js.map +1 -1
- package/lib/core/index.mjs +8 -3
- 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/sse.js +1 -1
- package/lib/core/sse.js.map +1 -1
- package/lib/core/sse.mjs +1 -1
- package/lib/core/sse.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/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/hasRefCounted.d.mts +3 -0
- package/lib/core/utils/internal/hasRefCounted.d.ts +3 -0
- package/lib/core/utils/internal/hasRefCounted.js +27 -0
- package/lib/core/utils/internal/hasRefCounted.js.map +1 -0
- package/lib/core/utils/internal/hasRefCounted.mjs +7 -0
- package/lib/core/utils/internal/hasRefCounted.mjs.map +1 -0
- 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/parseGraphQLRequest.js +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.js.map +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.mjs +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.mjs.map +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/parseMultipartData.js +3 -1
- package/lib/core/utils/internal/parseMultipartData.js.map +1 -1
- package/lib/core/utils/internal/parseMultipartData.mjs +3 -1
- package/lib/core/utils/internal/parseMultipartData.mjs.map +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/ws/WebSocketIndexedDBClientStore.js +1 -1
- package/lib/core/ws/WebSocketIndexedDBClientStore.js.map +1 -1
- package/lib/core/ws/WebSocketIndexedDBClientStore.mjs +1 -1
- package/lib/core/ws/WebSocketIndexedDBClientStore.mjs.map +1 -1
- package/lib/core/ws/handleWebSocketEvent.d.mts +1 -1
- package/lib/core/ws/handleWebSocketEvent.d.ts +1 -1
- package/lib/core/ws.js +2 -4
- package/lib/core/ws.js.map +1 -1
- package/lib/core/ws.mjs +2 -4
- package/lib/core/ws.mjs.map +1 -1
- package/lib/iife/index.js +18 -14
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/package.json +3 -3
- package/src/core/delay.ts +13 -1
- package/src/core/handlers/GraphQLHandler.ts +1 -1
- package/src/core/index.ts +8 -3
- package/src/core/sse.ts +1 -1
- package/src/core/utils/internal/hasRefCounted.test.ts +16 -0
- package/src/core/utils/internal/hasRefCounted.ts +8 -0
- package/src/core/utils/internal/parseGraphQLRequest.ts +1 -1
- package/src/core/utils/internal/parseMultipartData.ts +3 -1
- package/src/core/ws/WebSocketIndexedDBClientStore.ts +1 -2
- package/src/core/ws.ts +2 -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.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.
|
|
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.
|
|
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.
|
|
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) =>
|
|
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
|
}
|
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
|
|
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
|
|
96
|
-
|
|
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
|
@@ -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
|
+
})
|
|
@@ -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 '${
|
|
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(
|
|
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
|
-
|
|
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 (
|
|
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()
|