diff options
| author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2022-02-11 13:41:56 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-11 13:41:56 +0100 |
| commit | 2fa0096821cd04334210fcae6f54f85d304dc17a (patch) | |
| tree | f4c76302e48861e2d7cf802feab9f3d560fd1c9c /cli/tests/testdata/compat/worker/worker_test.mjs | |
| parent | 2f2c778a074d0eff991c6c22da54429de3de6704 (diff) | |
compat: support --compat in web workers (#13629)
Adds another callback to WebWorkerOptions that allows to execute
some modules before actual worker code executes. This allows to set up Node
global using std/node.
Diffstat (limited to 'cli/tests/testdata/compat/worker/worker_test.mjs')
| -rw-r--r-- | cli/tests/testdata/compat/worker/worker_test.mjs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/cli/tests/testdata/compat/worker/worker_test.mjs b/cli/tests/testdata/compat/worker/worker_test.mjs new file mode 100644 index 000000000..215605487 --- /dev/null +++ b/cli/tests/testdata/compat/worker/worker_test.mjs @@ -0,0 +1,18 @@ +import { deferred } from "../../../../../test_util/std/async/deferred.ts"; + +const promise = deferred(); +const url = new URL("./worker.mjs", import.meta.url); +const worker = new Worker(url.href, { type: "module", deno: true }); + +worker.onmessage = (e) => { + const pid = e.data.pid; + if (typeof pid != "number") { + throw new Error("pid is not a number"); + } + console.log("process.pid from worker:", pid); + promise.resolve(); +}; + +worker.postMessage("hello"); +await promise; +worker.terminate(); |
