summaryrefslogtreecommitdiff
path: root/tests/specs/node
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2024-05-16 00:09:35 -0700
committerGitHub <noreply@github.com>2024-05-16 07:09:35 +0000
commit88983fb3eb5a085f7d358a7a98d5c738a21b5d27 (patch)
treed4d83c5bd668edc25d30616fd4a3decc1cea3fb9 /tests/specs/node
parentbba553bea5938932518dc6382e464968ce8374b4 (diff)
fix(node): seperate worker module cache (#23634)
Construct a new module graph container for workers instead of sharing it with the main worker. Fixes #17248 Fixes #23461 --------- Co-authored-by: David Sherret <dsherret@gmail.com>
Diffstat (limited to 'tests/specs/node')
-rw-r--r--tests/specs/node/worker_threads_cache/__test__.jsonc5
-rw-r--r--tests/specs/node/worker_threads_cache/main.out2
-rw-r--r--tests/specs/node/worker_threads_cache/main.ts13
3 files changed, 20 insertions, 0 deletions
diff --git a/tests/specs/node/worker_threads_cache/__test__.jsonc b/tests/specs/node/worker_threads_cache/__test__.jsonc
new file mode 100644
index 000000000..a47fed572
--- /dev/null
+++ b/tests/specs/node/worker_threads_cache/__test__.jsonc
@@ -0,0 +1,5 @@
+{
+ "tempDir": true,
+ "args": "run -A main.ts",
+ "output": "main.out"
+}
diff --git a/tests/specs/node/worker_threads_cache/main.out b/tests/specs/node/worker_threads_cache/main.out
new file mode 100644
index 000000000..d14c028e5
--- /dev/null
+++ b/tests/specs/node/worker_threads_cache/main.out
@@ -0,0 +1,2 @@
+[Module: null prototype] { default: true }
+[Module: null prototype] { default: false }
diff --git a/tests/specs/node/worker_threads_cache/main.ts b/tests/specs/node/worker_threads_cache/main.ts
new file mode 100644
index 000000000..9703ac8f6
--- /dev/null
+++ b/tests/specs/node/worker_threads_cache/main.ts
@@ -0,0 +1,13 @@
+import fs from "node:fs/promises";
+import { isMainThread, Worker } from "node:worker_threads";
+
+await fs.writeFile("mod.mjs", "export default " + isMainThread);
+
+const path = new URL("mod.mjs", import.meta.url);
+const i = await import(path.href);
+console.log(i);
+
+if (isMainThread) {
+ const worker = new Worker(new URL("main.ts", import.meta.url));
+ worker.on("message", (msg) => console.log(msg));
+}