diff options
author | Andreu Botella <andreu@andreubotella.com> | 2023-03-19 23:32:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-19 23:32:54 +0100 |
commit | 090169cfbc6699486765b729d532b5b837210b12 (patch) | |
tree | 6872c34b8d9c6ac9b3ef05c2efb7a54b7c96bb28 /cli/tests/integration/compile_tests.rs | |
parent | bf149d047f4f768ced17d76c47623ca13c90f7e7 (diff) |
feat(compile): Add support for web workers in standalone mode (#17657)
This commit adds support for spawning Web Workers in self-contained
binaries created with "deno compile" subcommand.
As long as module requested in "new Worker" constructor is part of the
eszip (by means of statically importing it beforehand, or using "--include"
flag), then the worker can be spawned.
Diffstat (limited to 'cli/tests/integration/compile_tests.rs')
-rw-r--r-- | cli/tests/integration/compile_tests.rs | 85 |
1 files changed, 85 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(); |