msw 2.12.10 → 2.12.11
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/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/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/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 +12 -5
- 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/utils/internal/hasRefCounted.test.ts +16 -0
- package/src/core/utils/internal/hasRefCounted.ts +8 -0
- 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.11'
|
|
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.11",
|
|
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.11"
|
|
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
|
}
|
|
@@ -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
|
+
})
|
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()
|