From da8cb408c878aa6e90542e26173f1f14b5254d29 Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Thu, 19 Mar 2020 03:39:53 +1100 Subject: Provide compiled JSON to TypeScript compiler. (#4404) Fixes #4101 Previously, we would just provide the raw JSON to the TypeScript compiler worker, but TypeScript does not transform JSON. This caused a problem when emitting a bundle, that the JSON would just be "inlined" into the output, instead of being transformed into a module. This fixes this problem by providing the compiled JSON to the TypeScript compiler, so TypeScript just sees JSON as a "normal" TypeScript module. --- cli/tests/integration_tests.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'cli/tests') diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index 9cdf0af56..29203d411 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -398,6 +398,40 @@ fn bundle_single_module() { assert_eq!(output.stderr, b""); } +#[test] +fn bundle_json() { + use tempfile::TempDir; + + let json_modules = util::root_path().join("cli/tests/020_json_modules.ts"); + assert!(json_modules.is_file()); + let t = TempDir::new().expect("tempdir fail"); + let bundle = t.path().join("020_json_modules.bundle.js"); + let mut deno = util::deno_cmd() + .current_dir(util::root_path()) + .arg("bundle") + .arg(json_modules) + .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()); + + let output = util::deno_cmd() + .current_dir(util::root_path()) + .arg("run") + .arg("--reload") + .arg(&bundle) + .output() + .expect("failed to spawn script"); + // check the output of the the bundle program. + assert!(std::str::from_utf8(&output.stdout) + .unwrap() + .trim() + .ends_with("{\"foo\":{\"bar\":true,\"baz\":[\"qat\",1]}}")); + assert_eq!(output.stderr, b""); +} + #[test] fn bundle_tla() { // First we have to generate a bundle of some module that has exports. -- cgit v1.2.3