diff options
Diffstat (limited to 'cli/tests')
4 files changed, 54 insertions, 1 deletions
diff --git a/cli/tests/integration/compile_tests.rs b/cli/tests/integration/compile_tests.rs index add53434f..828e04b1f 100644 --- a/cli/tests/integration/compile_tests.rs +++ b/cli/tests/integration/compile_tests.rs @@ -592,3 +592,37 @@ fn dynamic_import() { .unwrap(); assert_eq!(String::from_utf8(output.stdout).unwrap(), expected); } + +#[test] +fn dynamic_import_unanalyzable() { + let _guard = util::http_server(); + let dir = TempDir::new(); + let exe = if cfg!(windows) { + dir.path().join("dynamic_import_unanalyzable.exe") + } else { + dir.path().join("dynamic_import_unanalyzable") + }; + let output = util::deno_cmd() + .current_dir(util::root_path()) + .arg("compile") + .arg("--allow-read") + .arg("--include") + .arg(util::testdata_path().join("./compile/dynamic_imports/import1.ts")) + .arg("--output") + .arg(&exe) + .arg( + util::testdata_path() + .join("./compile/dynamic_imports/main_unanalyzable.ts"), + ) + .output() + .unwrap(); + assert!(output.status.success()); + + let output = Command::new(&exe).env("NO_COLOR", "").output().unwrap(); + assert!(output.status.success()); + let expected = std::fs::read_to_string( + util::testdata_path().join("./compile/dynamic_imports/main.out"), + ) + .unwrap(); + assert_eq!(String::from_utf8(output.stdout).unwrap(), expected); +} diff --git a/cli/tests/testdata/compile/dynamic_imports/import_path b/cli/tests/testdata/compile/dynamic_imports/import_path new file mode 100644 index 000000000..98222a208 --- /dev/null +++ b/cli/tests/testdata/compile/dynamic_imports/import_path @@ -0,0 +1 @@ +./import1.ts diff --git a/cli/tests/testdata/compile/dynamic_imports/main.ts b/cli/tests/testdata/compile/dynamic_imports/main.ts index 7b4c487be..b889e2203 100644 --- a/cli/tests/testdata/compile/dynamic_imports/main.ts +++ b/cli/tests/testdata/compile/dynamic_imports/main.ts @@ -3,4 +3,4 @@ console.log("Starting the main module"); setTimeout(() => { console.log("Dynamic importing"); import("./import1.ts").then(() => console.log("Dynamic import done.")); -}, 500); +}, 0); diff --git a/cli/tests/testdata/compile/dynamic_imports/main_unanalyzable.ts b/cli/tests/testdata/compile/dynamic_imports/main_unanalyzable.ts new file mode 100644 index 000000000..e8e3e849b --- /dev/null +++ b/cli/tests/testdata/compile/dynamic_imports/main_unanalyzable.ts @@ -0,0 +1,18 @@ +import { join } from "https://deno.land/std@0.178.0/path/mod.ts"; + +console.log("Starting the main module"); + +// We load the dynamic import path from the file system, to make sure any +// improvements in static analysis can't defeat the purpose of this test, which +// is to make sure the `--include` flag works to add non-analyzed imports to the +// module graph. +const IMPORT_PATH_FILE_PATH = join( + Deno.cwd(), + "tests/testdata/compile/dynamic_imports/import_path", +); + +setTimeout(async () => { + console.log("Dynamic importing"); + const importPath = (await Deno.readTextFile(IMPORT_PATH_FILE_PATH)).trim(); + import(importPath).then(() => console.log("Dynamic import done.")); +}, 0); |