diff options
Diffstat (limited to 'cli/tests/integration')
-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 |
3 files changed, 120 insertions, 71 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(""), |