diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-05-29 16:32:15 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-29 16:32:15 +0200 |
commit | ad6d2a7734aafb4a64837abc6abd1d1d0fb20017 (patch) | |
tree | 4c0e8714384bc47211a4b68953a925fb54b7a015 /cli/tests | |
parent | b97459b5ae3918aae21f0c02342fd7c18189ad3e (diff) |
refactor: TS compiler and module graph (#5817)
This PR addresses many problems with module graph loading
introduced in #5029, as well as many long standing issues.
"ModuleGraphLoader" has been wired to "ModuleLoader" implemented
on "State" - that means that dependency analysis and fetching is done
before spinning up TS compiler worker.
Basic dependency tracking for TS compilation has been implemented.
Errors caused by import statements are now annotated with import
location.
Co-authored-by: Ryan Dahl <ry@tinyclouds.org>
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/disallow_http_from_https_js.out | 1 | ||||
-rw-r--r-- | cli/tests/disallow_http_from_https_ts.out | 1 | ||||
-rw-r--r-- | cli/tests/error_005_missing_dynamic_import.ts.out | 2 | ||||
-rw-r--r-- | cli/tests/error_012_bad_dynamic_import_specifier.ts.out | 3 | ||||
-rw-r--r-- | cli/tests/error_local_static_import_from_remote.js.out | 1 | ||||
-rw-r--r-- | cli/tests/error_local_static_import_from_remote.ts.out | 1 | ||||
-rw-r--r-- | cli/tests/error_syntax.js.out | 5 | ||||
-rw-r--r-- | cli/tests/error_syntax_empty_trailing_line.mjs.out | 3 | ||||
-rw-r--r-- | cli/tests/integration_tests.rs | 69 |
9 files changed, 76 insertions, 10 deletions
diff --git a/cli/tests/disallow_http_from_https_js.out b/cli/tests/disallow_http_from_https_js.out index 7b71cb6bf..e4e421159 100644 --- a/cli/tests/disallow_http_from_https_js.out +++ b/cli/tests/disallow_http_from_https_js.out @@ -1 +1,2 @@ error: Modules loaded over https:// are not allowed to import modules over http:// +Imported from "https://localhost:5545/cli/tests/disallow_http_from_https.js:2" diff --git a/cli/tests/disallow_http_from_https_ts.out b/cli/tests/disallow_http_from_https_ts.out index 7b71cb6bf..55e10b733 100644 --- a/cli/tests/disallow_http_from_https_ts.out +++ b/cli/tests/disallow_http_from_https_ts.out @@ -1 +1,2 @@ error: Modules loaded over https:// are not allowed to import modules over http:// +Imported from "https://localhost:5545/cli/tests/disallow_http_from_https.ts:2" diff --git a/cli/tests/error_005_missing_dynamic_import.ts.out b/cli/tests/error_005_missing_dynamic_import.ts.out index 346e8cd6f..8a64175ec 100644 --- a/cli/tests/error_005_missing_dynamic_import.ts.out +++ b/cli/tests/error_005_missing_dynamic_import.ts.out @@ -1 +1 @@ -error: Cannot resolve module "[WILDCARD]/bad-module.ts" from "[WILDCARD]/error_005_missing_dynamic_import.ts" +error: Uncaught TypeError: Cannot resolve module "[WILDCARD]/bad-module.ts" from "[WILDCARD]/error_005_missing_dynamic_import.ts" diff --git a/cli/tests/error_012_bad_dynamic_import_specifier.ts.out b/cli/tests/error_012_bad_dynamic_import_specifier.ts.out index 7bebeda12..78770dc81 100644 --- a/cli/tests/error_012_bad_dynamic_import_specifier.ts.out +++ b/cli/tests/error_012_bad_dynamic_import_specifier.ts.out @@ -1 +1,2 @@ -error: relative import path "bad-module.ts" not prefixed with / or ./ or ../ Imported from "[WILDCARD]/error_012_bad_dynamic_import_specifier.ts" +Compile [WILDCARD]error_012_bad_dynamic_import_specifier.ts +error: Uncaught TypeError: relative import path "bad-module.ts" not prefixed with / or ./ or ../ Imported from "[WILDCARD]/error_012_bad_dynamic_import_specifier.ts" diff --git a/cli/tests/error_local_static_import_from_remote.js.out b/cli/tests/error_local_static_import_from_remote.js.out index c3fda1274..1a2dcb2e3 100644 --- a/cli/tests/error_local_static_import_from_remote.js.out +++ b/cli/tests/error_local_static_import_from_remote.js.out @@ -1,2 +1,3 @@ [WILDCARD] error: Remote modules are not allowed to statically import local modules. Use dynamic import instead. +Imported from "[WILDCARD]error_local_static_import_from_remote.js:1" diff --git a/cli/tests/error_local_static_import_from_remote.ts.out b/cli/tests/error_local_static_import_from_remote.ts.out index c3fda1274..a2f2e1bbf 100644 --- a/cli/tests/error_local_static_import_from_remote.ts.out +++ b/cli/tests/error_local_static_import_from_remote.ts.out @@ -1,2 +1,3 @@ [WILDCARD] error: Remote modules are not allowed to statically import local modules. Use dynamic import instead. +Imported from "[WILDCARD]error_local_static_import_from_remote.ts:1" diff --git a/cli/tests/error_syntax.js.out b/cli/tests/error_syntax.js.out index 202e04a32..107bc1df0 100644 --- a/cli/tests/error_syntax.js.out +++ b/cli/tests/error_syntax.js.out @@ -1,4 +1 @@ -error: Uncaught SyntaxError: Unexpected identifier -(the following is a syntax error ^^ ! ) - ~~~~~~~~~ - at [WILDCARD]tests/error_syntax.js:3:6 +error: Expected Comma, got Some(Word(following)) at [WILDCARD]tests/error_syntax.js:3:5 diff --git a/cli/tests/error_syntax_empty_trailing_line.mjs.out b/cli/tests/error_syntax_empty_trailing_line.mjs.out index 6e8a268e9..3b78a23a6 100644 --- a/cli/tests/error_syntax_empty_trailing_line.mjs.out +++ b/cli/tests/error_syntax_empty_trailing_line.mjs.out @@ -1,2 +1 @@ -error: Uncaught SyntaxError: Unexpected end of input - at [WILDCARD]tests/error_syntax_empty_trailing_line.mjs:[WILDCARD] +error: Unexpected eof at [WILDCARD]tests/error_syntax_empty_trailing_line.mjs:2:21 diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index f892b9a87..653f5a008 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -413,6 +413,71 @@ fn js_unit_tests() { } #[test] +fn ts_dependency_recompilation() { + let t = TempDir::new().expect("tempdir fail"); + let ats = t.path().join("a.ts"); + + std::fs::write( + &ats, + " + import { foo } from \"./b.ts\"; + + function print(str: string): void { + console.log(str); + } + + print(foo);", + ) + .unwrap(); + + let bts = t.path().join("b.ts"); + std::fs::write( + &bts, + " + export const foo = \"foo\";", + ) + .unwrap(); + + let output = util::deno_cmd() + .current_dir(util::root_path()) + .env("NO_COLOR", "1") + .arg("run") + .arg(&ats) + .output() + .expect("failed to spawn script"); + + let stdout_output = std::str::from_utf8(&output.stdout).unwrap().trim(); + let stderr_output = std::str::from_utf8(&output.stderr).unwrap().trim(); + + assert!(stdout_output.ends_with("foo")); + assert!(stderr_output.starts_with("Compile")); + + // Overwrite contents of b.ts and run again + std::fs::write( + &bts, + " + export const foo = 5;", + ) + .expect("error writing file"); + + let output = util::deno_cmd() + .current_dir(util::root_path()) + .env("NO_COLOR", "1") + .arg("run") + .arg(&ats) + .output() + .expect("failed to spawn script"); + + let stdout_output = std::str::from_utf8(&output.stdout).unwrap().trim(); + let stderr_output = std::str::from_utf8(&output.stderr).unwrap().trim(); + + // error: TS2345 [ERROR]: Argument of type '5' is not assignable to parameter of type 'string'. + assert!(stderr_output.contains("TS2345")); + assert!(!output.status.success()); + assert!(stdout_output.is_empty()); +} + +#[test] fn bundle_exports() { // First we have to generate a bundle of some module that has exports. let mod1 = util::root_path().join("cli/tests/subdir/mod1.ts"); @@ -1377,7 +1442,7 @@ itest!(error_004_missing_module { }); itest!(error_005_missing_dynamic_import { - args: "run --reload --allow-read error_005_missing_dynamic_import.ts", + args: "run --reload --allow-read --quiet error_005_missing_dynamic_import.ts", exit_code: 1, output: "error_005_missing_dynamic_import.ts.out", }); @@ -1424,7 +1489,7 @@ itest!(error_014_catch_dynamic_import_error { }); itest!(error_015_dynamic_import_permissions { - args: "run --reload error_015_dynamic_import_permissions.js", + args: "run --reload --quiet error_015_dynamic_import_permissions.js", output: "error_015_dynamic_import_permissions.out", exit_code: 1, http_server: true, |