summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/integration/compile_tests.rs85
-rw-r--r--cli/tests/testdata/compile/workers/basic.out5
-rw-r--r--cli/tests/testdata/compile/workers/basic.ts11
-rw-r--r--cli/tests/testdata/compile/workers/not_in_module_map.ts11
-rw-r--r--cli/tests/testdata/compile/workers/worker.ts14
5 files changed, 126 insertions, 0 deletions
diff --git a/cli/tests/integration/compile_tests.rs b/cli/tests/integration/compile_tests.rs
index 828e04b1f..810cf5f80 100644
--- a/cli/tests/integration/compile_tests.rs
+++ b/cli/tests/integration/compile_tests.rs
@@ -566,6 +566,91 @@ fn check_local_by_default2() {
}
#[test]
+fn workers_basic() {
+ let _guard = util::http_server();
+ let dir = TempDir::new();
+ let exe = if cfg!(windows) {
+ dir.path().join("basic.exe")
+ } else {
+ dir.path().join("basic")
+ };
+ let output = util::deno_cmd()
+ .current_dir(util::root_path())
+ .arg("compile")
+ .arg("--no-check")
+ .arg("--output")
+ .arg(&exe)
+ .arg(util::testdata_path().join("./compile/workers/basic.ts"))
+ .output()
+ .unwrap();
+ assert!(output.status.success());
+
+ let output = Command::new(&exe).output().unwrap();
+ assert!(output.status.success());
+ let expected = std::fs::read_to_string(
+ util::testdata_path().join("./compile/workers/basic.out"),
+ )
+ .unwrap();
+ assert_eq!(String::from_utf8(output.stdout).unwrap(), expected);
+}
+
+#[test]
+fn workers_not_in_module_map() {
+ let _guard = util::http_server();
+ let dir = TempDir::new();
+ let exe = if cfg!(windows) {
+ dir.path().join("not_in_module_map.exe")
+ } else {
+ dir.path().join("not_in_module_map")
+ };
+ let output = util::deno_cmd()
+ .current_dir(util::root_path())
+ .arg("compile")
+ .arg("--output")
+ .arg(&exe)
+ .arg(util::testdata_path().join("./compile/workers/not_in_module_map.ts"))
+ .output()
+ .unwrap();
+ assert!(output.status.success());
+
+ let output = Command::new(&exe).env("NO_COLOR", "").output().unwrap();
+ assert!(!output.status.success());
+ let stderr = String::from_utf8(output.stderr).unwrap();
+ assert!(stderr.starts_with(concat!(
+ "error: Uncaught (in worker \"\") Module not found\n",
+ "error: Uncaught (in promise) Error: Unhandled error in child worker.\n"
+ )));
+}
+
+#[test]
+fn workers_with_include_flag() {
+ let _guard = util::http_server();
+ let dir = TempDir::new();
+ let exe = if cfg!(windows) {
+ dir.path().join("workers_with_include_flag.exe")
+ } else {
+ dir.path().join("workers_with_include_flag")
+ };
+ let output = util::deno_cmd()
+ .current_dir(util::root_path())
+ .arg("compile")
+ .arg("--include")
+ .arg(util::testdata_path().join("./compile/workers/worker.ts"))
+ .arg("--output")
+ .arg(&exe)
+ .arg(util::testdata_path().join("./compile/workers/not_in_module_map.ts"))
+ .output()
+ .unwrap();
+ assert!(output.status.success());
+
+ let output = Command::new(&exe).env("NO_COLOR", "").output().unwrap();
+ assert!(output.status.success());
+ let expected_stdout =
+ concat!("Hello from worker!\n", "Received 42\n", "Closing\n");
+ assert_eq!(&String::from_utf8(output.stdout).unwrap(), expected_stdout);
+}
+
+#[test]
fn dynamic_import() {
let _guard = util::http_server();
let dir = TempDir::new();
diff --git a/cli/tests/testdata/compile/workers/basic.out b/cli/tests/testdata/compile/workers/basic.out
new file mode 100644
index 000000000..9cf9aa18f
--- /dev/null
+++ b/cli/tests/testdata/compile/workers/basic.out
@@ -0,0 +1,5 @@
+worker.js imported from main thread
+Starting worker
+Hello from worker!
+Received 42
+Closing
diff --git a/cli/tests/testdata/compile/workers/basic.ts b/cli/tests/testdata/compile/workers/basic.ts
new file mode 100644
index 000000000..8edf58de9
--- /dev/null
+++ b/cli/tests/testdata/compile/workers/basic.ts
@@ -0,0 +1,11 @@
+import "./worker.ts";
+
+console.log("Starting worker");
+const worker = new Worker(
+ new URL("./worker.ts", import.meta.url),
+ { type: "module" },
+);
+
+setTimeout(() => {
+ worker.postMessage(42);
+}, 500);
diff --git a/cli/tests/testdata/compile/workers/not_in_module_map.ts b/cli/tests/testdata/compile/workers/not_in_module_map.ts
new file mode 100644
index 000000000..b43f8cb1f
--- /dev/null
+++ b/cli/tests/testdata/compile/workers/not_in_module_map.ts
@@ -0,0 +1,11 @@
+// This time ./worker.ts is not in the module map, so the worker
+// initialization will fail unless worker.js is passed as a side module.
+
+const worker = new Worker(
+ new URL("./worker.ts", import.meta.url),
+ { type: "module" },
+);
+
+setTimeout(() => {
+ worker.postMessage(42);
+}, 500);
diff --git a/cli/tests/testdata/compile/workers/worker.ts b/cli/tests/testdata/compile/workers/worker.ts
new file mode 100644
index 000000000..a1c357ab1
--- /dev/null
+++ b/cli/tests/testdata/compile/workers/worker.ts
@@ -0,0 +1,14 @@
+/// <reference no-default-lib="true" />
+/// <reference lib="deno.worker" />
+
+if (import.meta.main) {
+ console.log("Hello from worker!");
+
+ addEventListener("message", (evt) => {
+ console.log(`Received ${evt.data}`);
+ console.log("Closing");
+ self.close();
+ });
+} else {
+ console.log("worker.js imported from main thread");
+}