@vitest/web-worker 4.0.13 → 4.0.15
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/dist/index.js +1 -1
- package/dist/pure.js +13 -5
- package/package.json +3 -4
package/dist/index.js
CHANGED
package/dist/pure.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MessageChannel } from 'node:worker_threads';
|
|
2
2
|
import { getWorkerState, VitestModuleEvaluator, startVitestModuleRunner, VITEST_VM_CONTEXT_SYMBOL } from 'vitest/internal/module-runner';
|
|
3
|
-
import createDebug from '
|
|
3
|
+
import { createDebug } from 'obug';
|
|
4
4
|
|
|
5
5
|
function startWebWorkerModuleRunner(context) {
|
|
6
6
|
const state = getWorkerState();
|
|
@@ -314,11 +314,17 @@ function createClonedMessageEvent(data, transferOrOptions, clone) {
|
|
|
314
314
|
const transfer = Array.isArray(transferOrOptions) ? transferOrOptions : transferOrOptions?.transfer;
|
|
315
315
|
debug("clone worker message %o", data);
|
|
316
316
|
const origin = typeof location === "undefined" ? undefined : location.origin;
|
|
317
|
+
const ports = transfer?.filter((t) => t instanceof MessagePort);
|
|
318
|
+
const transferWithoutPorts = transfer?.filter(
|
|
319
|
+
// `ports` must be excluded from the `transfer` option passed to `structuredClone` to keep the MessagePort objects working correctly in the same thread.
|
|
320
|
+
(t) => !(t instanceof MessagePort)
|
|
321
|
+
);
|
|
317
322
|
if (typeof structuredClone === "function" && clone === "native") {
|
|
318
323
|
debug("create message event, using native structured clone");
|
|
319
324
|
return new MessageEvent("message", {
|
|
320
|
-
data: structuredClone(data, { transfer }),
|
|
321
|
-
origin
|
|
325
|
+
data: structuredClone(data, { transfer: transferWithoutPorts }),
|
|
326
|
+
origin,
|
|
327
|
+
ports
|
|
322
328
|
});
|
|
323
329
|
}
|
|
324
330
|
if (clone !== "none") {
|
|
@@ -328,13 +334,15 @@ function createClonedMessageEvent(data, transferOrOptions, clone) {
|
|
|
328
334
|
}
|
|
329
335
|
return new MessageEvent("message", {
|
|
330
336
|
data: ponyfillStructuredClone(data, { lossy: true }),
|
|
331
|
-
origin
|
|
337
|
+
origin,
|
|
338
|
+
ports
|
|
332
339
|
});
|
|
333
340
|
}
|
|
334
341
|
debug("create message event without cloning an object");
|
|
335
342
|
return new MessageEvent("message", {
|
|
336
343
|
data,
|
|
337
|
-
origin
|
|
344
|
+
origin,
|
|
345
|
+
ports
|
|
338
346
|
});
|
|
339
347
|
}
|
|
340
348
|
function createMessageEvent(data, transferOrOptions, clone) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitest/web-worker",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.0.
|
|
4
|
+
"version": "4.0.15",
|
|
5
5
|
"description": "Web Worker support for testing in Vitest",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
|
@@ -33,13 +33,12 @@
|
|
|
33
33
|
"dist"
|
|
34
34
|
],
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"vitest": "4.0.
|
|
36
|
+
"vitest": "4.0.15"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"
|
|
39
|
+
"obug": "^2.1.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@types/debug": "^4.1.12",
|
|
43
42
|
"@types/ungap__structured-clone": "^1.2.0",
|
|
44
43
|
"@ungap/structured-clone": "^1.3.0"
|
|
45
44
|
},
|