diff --git a/cli/tests/integration/compile_tests.rs b/cli/tests/integration/compile_tests.rs index fdeadecd0f..add53434ff 100644 --- a/cli/tests/integration/compile_tests.rs +++ b/cli/tests/integration/compile_tests.rs @@ -564,3 +564,31 @@ fn check_local_by_default2() { r#"error: TS2322 [ERROR]: Type '12' is not assignable to type '"b"'."# )); } + +#[test] +fn dynamic_import() { + let _guard = util::http_server(); + let dir = TempDir::new(); + let exe = if cfg!(windows) { + dir.path().join("dynamic_import.exe") + } else { + dir.path().join("dynamic_import") + }; + let output = util::deno_cmd() + .current_dir(util::root_path()) + .arg("compile") + .arg("--output") + .arg(&exe) + .arg(util::testdata_path().join("./compile/dynamic_imports/main.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/import1.ts b/cli/tests/testdata/compile/dynamic_imports/import1.ts new file mode 100644 index 0000000000..2d9dde2a45 --- /dev/null +++ b/cli/tests/testdata/compile/dynamic_imports/import1.ts @@ -0,0 +1,3 @@ +import "./import2.ts"; + +console.log("import1.ts"); diff --git a/cli/tests/testdata/compile/dynamic_imports/import2.ts b/cli/tests/testdata/compile/dynamic_imports/import2.ts new file mode 100644 index 0000000000..22321a5a7b --- /dev/null +++ b/cli/tests/testdata/compile/dynamic_imports/import2.ts @@ -0,0 +1 @@ +console.log("import2.ts"); diff --git a/cli/tests/testdata/compile/dynamic_imports/main.out b/cli/tests/testdata/compile/dynamic_imports/main.out new file mode 100644 index 0000000000..4304fb06fb --- /dev/null +++ b/cli/tests/testdata/compile/dynamic_imports/main.out @@ -0,0 +1,5 @@ +Starting the main module +Dynamic importing +import2.ts +import1.ts +Dynamic import done. diff --git a/cli/tests/testdata/compile/dynamic_imports/main.ts b/cli/tests/testdata/compile/dynamic_imports/main.ts new file mode 100644 index 0000000000..7b4c487be5 --- /dev/null +++ b/cli/tests/testdata/compile/dynamic_imports/main.ts @@ -0,0 +1,6 @@ +console.log("Starting the main module"); + +setTimeout(() => { + console.log("Dynamic importing"); + import("./import1.ts").then(() => console.log("Dynamic import done.")); +}, 500);