summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/bundle.test.out6
-rw-r--r--cli/tests/integration_tests.rs41
2 files changed, 46 insertions, 1 deletions
diff --git a/cli/tests/bundle.test.out b/cli/tests/bundle.test.out
index d6f6e8a62..23b7de35e 100644
--- a/cli/tests/bundle.test.out
+++ b/cli/tests/bundle.test.out
@@ -14,5 +14,9 @@ define("mod1", ["require", "exports", "subdir2/mod2"], function (require, export
[WILDCARD]
});
-instantiate(["mod1"]);
+const __rootExports = instantiate("mod1");
+export const returnsHi = __rootExports["returnsHi"];
+export const returnsFoo2 = __rootExports["returnsFoo2"];
+export const printHello3 = __rootExports["printHello3"];
+export const throwsError = __rootExports["throwsError"];
diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs
index 195202d49..7fd7a396b 100644
--- a/cli/tests/integration_tests.rs
+++ b/cli/tests/integration_tests.rs
@@ -55,6 +55,47 @@ fn js_unit_tests() {
drop(g);
}
+#[test]
+fn bundle_exports() {
+ use tempfile::TempDir;
+
+ // First we have to generate a bundle of some module that has exports.
+ let mod1 = util::root_path().join("cli/tests/subdir/mod1.ts");
+ assert!(mod1.is_file());
+ let t = TempDir::new().expect("tempdir fail");
+ let bundle = t.path().join("mod1.bundle.js");
+ let mut deno = util::deno_cmd()
+ .current_dir(util::root_path())
+ .arg("bundle")
+ .arg(mod1)
+ .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 \"./mod1.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_eq!(std::str::from_utf8(&output.stdout).unwrap().trim(), "Hello");
+ assert_eq!(output.stderr, b"");
+}
+
// TODO(#2933): Rewrite this test in rust.
#[test]
fn repl_test() {