diff options
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/integration/check_tests.rs | 63 | ||||
-rw-r--r-- | cli/tests/integration/mod.rs | 46 | ||||
-rw-r--r-- | cli/tests/integration/run_tests.rs | 82 | ||||
-rw-r--r-- | cli/tests/testdata/check/cache_config_on_off/deno.json | 5 | ||||
-rw-r--r-- | cli/tests/testdata/check/cache_config_on_off/main.ts | 1 | ||||
-rw-r--r-- | cli/tests/testdata/coverage/branch_expected.lcov | 4 | ||||
-rw-r--r-- | cli/tests/testdata/coverage/branch_expected.out | 3 | ||||
-rw-r--r-- | cli/tests/testdata/coverage/complex_expected.lcov | 22 | ||||
-rw-r--r-- | cli/tests/testdata/coverage/complex_expected.out | 4 | ||||
-rw-r--r-- | cli/tests/testdata/run/remote_type_error/main.ts | 3 | ||||
-rw-r--r-- | cli/tests/testdata/run/remote_type_error/remote.ts | 5 |
11 files changed, 160 insertions, 78 deletions
diff --git a/cli/tests/integration/check_tests.rs b/cli/tests/integration/check_tests.rs index 8000ddc9d..5ceaffe51 100644 --- a/cli/tests/integration/check_tests.rs +++ b/cli/tests/integration/check_tests.rs @@ -1,7 +1,11 @@ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. +use std::process::Stdio; + use crate::itest; +use test_util as util; + itest!(_095_check_with_bare_import { args: "check 095_cache_with_bare_import.ts", output: "095_cache_with_bare_import.ts.out", @@ -43,3 +47,62 @@ itest!(declaration_header_file_with_no_exports { args: "check --quiet declaration_header_file_with_no_exports.ts", output_str: Some(""), }); + +#[test] +fn cache_switching_config_then_no_config() { + let deno_dir = util::new_deno_dir(); + assert!(does_type_checking(&deno_dir, true)); + assert!(does_type_checking(&deno_dir, false)); + + // should now not do type checking even when it changes + // configs because it previously did + assert!(!does_type_checking(&deno_dir, true)); + assert!(!does_type_checking(&deno_dir, false)); + + fn does_type_checking(deno_dir: &util::TempDir, with_config: bool) -> bool { + let mut cmd = util::deno_cmd_with_deno_dir(deno_dir); + cmd + .current_dir(util::testdata_path()) + .stderr(Stdio::piped()) + .arg("check") + .arg("check/cache_config_on_off/main.ts"); + if with_config { + cmd + .arg("--config") + .arg("check/cache_config_on_off/deno.json"); + } + let output = cmd.spawn().unwrap().wait_with_output().unwrap(); + assert!(output.status.success()); + + let stderr = std::str::from_utf8(&output.stderr).unwrap(); + stderr.contains("Check") + } +} + +#[test] +fn reload_flag() { + // should do type checking whenever someone specifies --reload + let deno_dir = util::new_deno_dir(); + assert!(does_type_checking(&deno_dir, false)); + assert!(!does_type_checking(&deno_dir, false)); + assert!(does_type_checking(&deno_dir, true)); + assert!(does_type_checking(&deno_dir, true)); + assert!(!does_type_checking(&deno_dir, false)); + + fn does_type_checking(deno_dir: &util::TempDir, reload: bool) -> bool { + let mut cmd = util::deno_cmd_with_deno_dir(deno_dir); + cmd + .current_dir(util::testdata_path()) + .stderr(Stdio::piped()) + .arg("check") + .arg("check/cache_config_on_off/main.ts"); + if reload { + cmd.arg("--reload"); + } + let output = cmd.spawn().unwrap().wait_with_output().unwrap(); + assert!(output.status.success()); + + let stderr = std::str::from_utf8(&output.stderr).unwrap(); + stderr.contains("Check") + } +} diff --git a/cli/tests/integration/mod.rs b/cli/tests/integration/mod.rs index 42ae24142..277b6a5d6 100644 --- a/cli/tests/integration/mod.rs +++ b/cli/tests/integration/mod.rs @@ -158,12 +158,6 @@ fn cache_test() { .expect("Failed to spawn script"); assert!(output.status.success()); - let out = std::str::from_utf8(&output.stderr).unwrap(); - // Check if file and dependencies are written successfully - assert!(out.contains("host.writeFile(\"deno://subdir/print_hello.js\")")); - assert!(out.contains("host.writeFile(\"deno://subdir/mod2.js\")")); - assert!(out.contains("host.writeFile(\"deno://006_url_imports.js\")")); - let prg = util::deno_exe_path(); let output = Command::new(&prg) .env("DENO_DIR", deno_dir.path()) @@ -370,46 +364,6 @@ fn ts_no_recheck_on_redirect() { } #[test] -fn ts_reload() { - let hello_ts = util::testdata_path().join("002_hello.ts"); - assert!(hello_ts.is_file()); - - let deno_dir = TempDir::new(); - let mut initial = util::deno_cmd_with_deno_dir(&deno_dir) - .current_dir(util::testdata_path()) - .arg("cache") - .arg("--check=all") - .arg(&hello_ts) - .spawn() - .expect("failed to spawn script"); - let status_initial = - initial.wait().expect("failed to wait for child process"); - assert!(status_initial.success()); - - let output = util::deno_cmd_with_deno_dir(&deno_dir) - .current_dir(util::testdata_path()) - .arg("cache") - .arg("--check=all") - .arg("--reload") - .arg("-L") - .arg("debug") - .arg(&hello_ts) - .output() - .expect("failed to spawn script"); - - // check the output of the the bundle program. - let output_path = hello_ts.canonicalize().unwrap(); - assert!( - dbg!(std::str::from_utf8(&output.stderr).unwrap().trim()).contains( - &format!( - "host.getSourceFile(\"{}\", Latest)", - url::Url::from_file_path(&output_path).unwrap().as_str() - ) - ) - ); -} - -#[test] fn timeout_clear() { // https://github.com/denoland/deno/issues/7599 diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs index d9c20907d..e8bf3682a 100644 --- a/cli/tests/integration/run_tests.rs +++ b/cli/tests/integration/run_tests.rs @@ -2,8 +2,10 @@ use deno_core::url; use std::process::Command; +use std::process::Stdio; use test_util as util; use test_util::TempDir; +use util::assert_contains; itest!(stdout_write_all { args: "run --quiet stdout_write_all.ts", @@ -268,7 +270,7 @@ fn webstorage_location_shares_origin() { .arg("--location") .arg("https://example.com/a.ts") .arg("webstorage/fixture.ts") - .stdout(std::process::Stdio::piped()) + .stdout(Stdio::piped()) .spawn() .unwrap() .wait_with_output() @@ -283,7 +285,7 @@ fn webstorage_location_shares_origin() { .arg("--location") .arg("https://example.com/b.ts") .arg("webstorage/logger.ts") - .stdout(std::process::Stdio::piped()) + .stdout(Stdio::piped()) .spawn() .unwrap() .wait_with_output() @@ -305,7 +307,7 @@ fn webstorage_config_file() { .arg("--config") .arg("webstorage/config_a.jsonc") .arg("webstorage/fixture.ts") - .stdout(std::process::Stdio::piped()) + .stdout(Stdio::piped()) .spawn() .unwrap() .wait_with_output() @@ -320,7 +322,7 @@ fn webstorage_config_file() { .arg("--config") .arg("webstorage/config_b.jsonc") .arg("webstorage/logger.ts") - .stdout(std::process::Stdio::piped()) + .stdout(Stdio::piped()) .spawn() .unwrap() .wait_with_output() @@ -335,7 +337,7 @@ fn webstorage_config_file() { .arg("--config") .arg("webstorage/config_a.jsonc") .arg("webstorage/logger.ts") - .stdout(std::process::Stdio::piped()) + .stdout(Stdio::piped()) .spawn() .unwrap() .wait_with_output() @@ -359,7 +361,7 @@ fn webstorage_location_precedes_config() { .arg("--config") .arg("webstorage/config_a.jsonc") .arg("webstorage/fixture.ts") - .stdout(std::process::Stdio::piped()) + .stdout(Stdio::piped()) .spawn() .unwrap() .wait_with_output() @@ -376,7 +378,7 @@ fn webstorage_location_precedes_config() { .arg("--config") .arg("webstorage/config_b.jsonc") .arg("webstorage/logger.ts") - .stdout(std::process::Stdio::piped()) + .stdout(Stdio::piped()) .spawn() .unwrap() .wait_with_output() @@ -396,7 +398,7 @@ fn webstorage_main_module() { .current_dir(util::testdata_path()) .arg("run") .arg("webstorage/fixture.ts") - .stdout(std::process::Stdio::piped()) + .stdout(Stdio::piped()) .spawn() .unwrap() .wait_with_output() @@ -409,7 +411,7 @@ fn webstorage_main_module() { .current_dir(util::testdata_path()) .arg("run") .arg("webstorage/logger.ts") - .stdout(std::process::Stdio::piped()) + .stdout(Stdio::piped()) .spawn() .unwrap() .wait_with_output() @@ -422,7 +424,7 @@ fn webstorage_main_module() { .current_dir(util::testdata_path()) .arg("run") .arg("webstorage/fixture.ts") - .stdout(std::process::Stdio::piped()) + .stdout(Stdio::piped()) .spawn() .unwrap() .wait_with_output() @@ -1632,8 +1634,8 @@ fn no_validate_asm() { .current_dir(util::testdata_path()) .arg("run") .arg("no_validate_asm.js") - .stderr(std::process::Stdio::piped()) - .stdout(std::process::Stdio::piped()) + .stderr(Stdio::piped()) + .stdout(Stdio::piped()) .spawn() .unwrap() .wait_with_output() @@ -1650,7 +1652,7 @@ fn exec_path() { .arg("run") .arg("--allow-read") .arg("exec_path.ts") - .stdout(std::process::Stdio::piped()) + .stdout(Stdio::piped()) .spawn() .unwrap() .wait_with_output() @@ -1776,7 +1778,7 @@ fn rust_log() { .current_dir(util::testdata_path()) .arg("run") .arg("001_hello.js") - .stderr(std::process::Stdio::piped()) + .stderr(Stdio::piped()) .spawn() .unwrap() .wait_with_output() @@ -1790,7 +1792,7 @@ fn rust_log() { .arg("run") .arg("001_hello.js") .env("RUST_LOG", "debug") - .stderr(std::process::Stdio::piped()) + .stderr(Stdio::piped()) .spawn() .unwrap() .wait_with_output() @@ -1810,7 +1812,7 @@ fn dont_cache_on_check_fail() { .arg("--check=all") .arg("--reload") .arg("error_003_typescript.ts") - .stderr(std::process::Stdio::piped()) + .stderr(Stdio::piped()) .spawn() .unwrap() .wait_with_output() @@ -1824,7 +1826,7 @@ fn dont_cache_on_check_fail() { .arg("run") .arg("--check=all") .arg("error_003_typescript.ts") - .stderr(std::process::Stdio::piped()) + .stderr(Stdio::piped()) .spawn() .unwrap() .wait_with_output() @@ -2374,8 +2376,8 @@ fn issue12740() { .current_dir(util::testdata_path()) .arg("run") .arg(&mod1_path) - .stderr(std::process::Stdio::null()) - .stdout(std::process::Stdio::null()) + .stderr(Stdio::null()) + .stdout(Stdio::null()) .spawn() .unwrap() .wait() @@ -2387,8 +2389,8 @@ fn issue12740() { .current_dir(util::testdata_path()) .arg("run") .arg(&mod1_path) - .stderr(std::process::Stdio::null()) - .stdout(std::process::Stdio::null()) + .stderr(Stdio::null()) + .stdout(Stdio::null()) .spawn() .unwrap() .wait() @@ -2411,8 +2413,8 @@ fn issue12807() { .arg("run") .arg("--check") .arg(&mod1_path) - .stderr(std::process::Stdio::null()) - .stdout(std::process::Stdio::null()) + .stderr(Stdio::null()) + .stdout(Stdio::null()) .spawn() .unwrap() .wait() @@ -2425,8 +2427,8 @@ fn issue12807() { .arg("run") .arg("--check") .arg(&mod1_path) - .stderr(std::process::Stdio::null()) - .stdout(std::process::Stdio::null()) + .stderr(Stdio::null()) + .stdout(Stdio::null()) .spawn() .unwrap() .wait() @@ -2663,6 +2665,36 @@ itest!(js_root_with_ts_check { exit_code: 1, }); +#[test] +fn check_local_then_remote() { + let _http_guard = util::http_server(); + let deno_dir = util::new_deno_dir(); + let output = util::deno_cmd_with_deno_dir(&deno_dir) + .current_dir(util::testdata_path()) + .arg("run") + .arg("--check") + .arg("run/remote_type_error/main.ts") + .spawn() + .unwrap() + .wait_with_output() + .unwrap(); + assert!(output.status.success()); + let output = util::deno_cmd_with_deno_dir(&deno_dir) + .current_dir(util::testdata_path()) + .arg("run") + .arg("--check=all") + .arg("run/remote_type_error/main.ts") + .env("NO_COLOR", "1") + .stderr(Stdio::piped()) + .spawn() + .unwrap() + .wait_with_output() + .unwrap(); + assert!(!output.status.success()); + let stderr = std::str::from_utf8(&output.stderr).unwrap(); + assert_contains!(stderr, "Type 'string' is not assignable to type 'number'."); +} + itest!(no_prompt_flag { args: "run --quiet --unstable --no-prompt no_prompt.ts", output_str: Some(""), diff --git a/cli/tests/testdata/check/cache_config_on_off/deno.json b/cli/tests/testdata/check/cache_config_on_off/deno.json new file mode 100644 index 000000000..8ad9c9801 --- /dev/null +++ b/cli/tests/testdata/check/cache_config_on_off/deno.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "strict": false + } +} diff --git a/cli/tests/testdata/check/cache_config_on_off/main.ts b/cli/tests/testdata/check/cache_config_on_off/main.ts new file mode 100644 index 000000000..0f3785f91 --- /dev/null +++ b/cli/tests/testdata/check/cache_config_on_off/main.ts @@ -0,0 +1 @@ +console.log(5); diff --git a/cli/tests/testdata/coverage/branch_expected.lcov b/cli/tests/testdata/coverage/branch_expected.lcov index 31da70224..fb3454210 100644 --- a/cli/tests/testdata/coverage/branch_expected.lcov +++ b/cli/tests/testdata/coverage/branch_expected.lcov @@ -11,7 +11,7 @@ BRH:0 DA:1,1 DA:2,2 DA:3,2 -DA:4,2 +DA:4,0 DA:5,0 DA:6,0 DA:7,2 @@ -22,6 +22,6 @@ DA:12,0 DA:13,0 DA:14,0 DA:15,0 -LH:5 +LH:4 LF:14 end_of_record diff --git a/cli/tests/testdata/coverage/branch_expected.out b/cli/tests/testdata/coverage/branch_expected.out index 2ff5e911e..630ea93b2 100644 --- a/cli/tests/testdata/coverage/branch_expected.out +++ b/cli/tests/testdata/coverage/branch_expected.out @@ -1,4 +1,5 @@ -cover [WILDCARD]/coverage/branch.ts ... 35.714% (5/14) +cover [WILDCARD]/coverage/branch.ts ... 28.571% (4/14) + 4 | } else { 5 | return false; 6 | } -----|----- diff --git a/cli/tests/testdata/coverage/complex_expected.lcov b/cli/tests/testdata/coverage/complex_expected.lcov index 7a3cd8d92..c6f9a2578 100644 --- a/cli/tests/testdata/coverage/complex_expected.lcov +++ b/cli/tests/testdata/coverage/complex_expected.lcov @@ -11,44 +11,62 @@ FNF:4 FNH:2 BRF:0 BRH:0 +DA:13,1 +DA:14,1 +DA:15,1 +DA:16,1 DA:17,2 DA:18,2 DA:19,2 DA:20,2 +DA:21,2 DA:22,2 DA:23,2 DA:24,2 DA:25,2 DA:26,2 DA:27,2 +DA:29,1 +DA:30,1 +DA:31,1 DA:32,1 DA:33,1 DA:34,1 DA:35,1 +DA:36,1 DA:37,2 DA:38,2 DA:39,2 DA:40,2 DA:41,2 DA:42,2 +DA:44,1 +DA:45,1 DA:46,0 DA:47,0 DA:48,0 DA:49,0 +DA:50,0 DA:51,0 DA:52,0 DA:53,0 DA:54,0 DA:55,0 DA:56,0 +DA:58,1 +DA:59,1 DA:60,1 +DA:62,1 +DA:63,1 DA:64,0 DA:65,0 DA:66,0 DA:67,0 DA:68,0 +DA:70,1 DA:71,0 +DA:73,1 DA:74,1 -LH:22 -LF:38 +LH:39 +LF:56 end_of_record diff --git a/cli/tests/testdata/coverage/complex_expected.out b/cli/tests/testdata/coverage/complex_expected.out index 3f7c89e9b..aeff4cd60 100644 --- a/cli/tests/testdata/coverage/complex_expected.out +++ b/cli/tests/testdata/coverage/complex_expected.out @@ -1,9 +1,9 @@ -cover [WILDCARD]/coverage/complex.ts ... 57.895% (22/38) +cover [WILDCARD]/coverage/complex.ts ... 69.643% (39/56) 46 | export function unused( 47 | foo: string, 48 | bar: string, 49 | baz: string, ------|----- + 50 | ): Complex { 51 | return complex( 52 | foo, 53 | bar, diff --git a/cli/tests/testdata/run/remote_type_error/main.ts b/cli/tests/testdata/run/remote_type_error/main.ts new file mode 100644 index 000000000..00f8a52df --- /dev/null +++ b/cli/tests/testdata/run/remote_type_error/main.ts @@ -0,0 +1,3 @@ +import { doAction } from "http://localhost:4545/run/remote_type_error/remote.ts"; + +doAction(); diff --git a/cli/tests/testdata/run/remote_type_error/remote.ts b/cli/tests/testdata/run/remote_type_error/remote.ts new file mode 100644 index 000000000..6e9bf4adb --- /dev/null +++ b/cli/tests/testdata/run/remote_type_error/remote.ts @@ -0,0 +1,5 @@ +export function doAction() { + // this is an intentional type error + const val: number = "test"; + console.log(val); +} |