diff options
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/bundle_im.json | 5 | ||||
-rw-r--r-- | cli/tests/bundle_im.ts | 17 | ||||
-rw-r--r-- | cli/tests/integration_tests.rs | 44 |
3 files changed, 66 insertions, 0 deletions
diff --git a/cli/tests/bundle_im.json b/cli/tests/bundle_im.json new file mode 100644 index 000000000..8ebc00c5b --- /dev/null +++ b/cli/tests/bundle_im.json @@ -0,0 +1,5 @@ +{ + "imports": { + "mod2": "./subdir/subdir2/mod2.ts" + } +} diff --git a/cli/tests/bundle_im.ts b/cli/tests/bundle_im.ts new file mode 100644 index 000000000..b751aa689 --- /dev/null +++ b/cli/tests/bundle_im.ts @@ -0,0 +1,17 @@ +import { returnsFoo, printHello2 } from "mod2"; + +export function returnsHi(): string { + return "Hi"; +} + +export function returnsFoo2(): string { + return returnsFoo(); +} + +export function printHello3(): void { + printHello2(); +} + +export function throwsError(): void { + throw Error("exception from mod1"); +} diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index bef4c8d56..c22d1cfd2 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -525,6 +525,50 @@ fn bundle_dynamic_import() { } #[test] +fn bundle_import_map() { + let import = util::root_path().join("cli/tests/bundle_im.ts"); + let import_map_path = util::root_path().join("cli/tests/bundle_im.json"); + assert!(import.is_file()); + let t = TempDir::new().expect("tempdir fail"); + let bundle = t.path().join("import_map.bundle.js"); + let mut deno = util::deno_cmd() + .current_dir(util::root_path()) + .arg("bundle") + .arg("--importmap") + .arg(import_map_path) + .arg(import) + .arg(&bundle) + .spawn() + .expect("failed to spawn script"); + let status = deno.wait().expect("failed to wait for the child process"); + assert!(status.success()); + assert!(bundle.is_file()); + + // Now we try to use that bundle from another module. + let test = t.path().join("test.js"); + std::fs::write( + &test, + " + import { printHello3 } from \"./import_map.bundle.js\"; + printHello3(); ", + ) + .expect("error writing file"); + + let output = util::deno_cmd() + .current_dir(util::root_path()) + .arg("run") + .arg(&test) + .output() + .expect("failed to spawn script"); + // check the output of the test.ts program. + assert!(std::str::from_utf8(&output.stdout) + .unwrap() + .trim() + .ends_with("Hello")); + assert_eq!(output.stderr, b""); +} + +#[test] fn repl_test_console_log() { let (out, err) = util::run_and_collect_output( true, |