summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2022-02-11 13:41:56 +0100
committerGitHub <noreply@github.com>2022-02-11 13:41:56 +0100
commit2fa0096821cd04334210fcae6f54f85d304dc17a (patch)
treef4c76302e48861e2d7cf802feab9f3d560fd1c9c /cli/tests
parent2f2c778a074d0eff991c6c22da54429de3de6704 (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')
-rw-r--r--cli/tests/integration/compat_tests.rs5
-rw-r--r--cli/tests/testdata/compat/worker/worker.mjs9
-rw-r--r--cli/tests/testdata/compat/worker/worker_test.mjs18
-rw-r--r--cli/tests/testdata/compat/worker/worker_test.out2
4 files changed, 34 insertions, 0 deletions
diff --git a/cli/tests/integration/compat_tests.rs b/cli/tests/integration/compat_tests.rs
index bafe24af3..189e1eb41 100644
--- a/cli/tests/integration/compat_tests.rs
+++ b/cli/tests/integration/compat_tests.rs
@@ -90,6 +90,11 @@ itest!(top_level_fail_esm {
output: "compat/test_runner/top_level_fail_esm.out",
});
+itest!(compat_worker {
+ args: "run --compat --unstable -A --quiet --no-check compat/worker/worker_test.mjs",
+ output: "compat/worker/worker_test.out",
+});
+
#[test]
fn globals_in_repl() {
let (out, _err) = util::run_and_collect_output_with_args(
diff --git a/cli/tests/testdata/compat/worker/worker.mjs b/cli/tests/testdata/compat/worker/worker.mjs
new file mode 100644
index 000000000..eb7cfed19
--- /dev/null
+++ b/cli/tests/testdata/compat/worker/worker.mjs
@@ -0,0 +1,9 @@
+console.log("hello from worker");
+
+self.onmessage = (e) => {
+ if (e.data != "hello") {
+ throw new Error("wrong message");
+ }
+
+ self.postMessage({ pid: process.pid });
+}
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();
diff --git a/cli/tests/testdata/compat/worker/worker_test.out b/cli/tests/testdata/compat/worker/worker_test.out
new file mode 100644
index 000000000..373841945
--- /dev/null
+++ b/cli/tests/testdata/compat/worker/worker_test.out
@@ -0,0 +1,2 @@
+hello from worker
+process.pid from worker: [WILDCARD]