diff options
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/coverage_tests.rs | 62 | ||||
-rw-r--r-- | cli/tests/testdata/coverage/invalid_cache/mod.test.ts | 2 | ||||
-rw-r--r-- | cli/tests/testdata/coverage/invalid_cache/mod_after.ts | 6 | ||||
-rw-r--r-- | cli/tests/testdata/coverage/invalid_cache/mod_before.ts | 15 |
4 files changed, 85 insertions, 0 deletions
diff --git a/cli/tests/coverage_tests.rs b/cli/tests/coverage_tests.rs index 1806417ea..6515fd6ec 100644 --- a/cli/tests/coverage_tests.rs +++ b/cli/tests/coverage_tests.rs @@ -26,6 +26,68 @@ mod coverage { no_snaps_included("no_snaps_included", "ts"); } + #[test] + fn error_if_invalid_cache() { + let deno_dir = TempDir::new(); + let deno_dir_path = deno_dir.path(); + let tempdir = TempDir::new(); + let tempdir = tempdir.path().join("cov"); + + let invalid_cache_path = + util::testdata_path().join("coverage/invalid_cache"); + let mod_before_path = util::testdata_path() + .join(&invalid_cache_path) + .join("mod_before.ts"); + let mod_after_path = util::testdata_path() + .join(&invalid_cache_path) + .join("mod_after.ts"); + let mod_test_path = util::testdata_path() + .join(&invalid_cache_path) + .join("mod.test.ts"); + + let mod_temp_path = deno_dir_path.join("mod.ts"); + let mod_test_temp_path = deno_dir_path.join("mod.test.ts"); + + // Write the inital mod.ts file + std::fs::copy(mod_before_path, &mod_temp_path).unwrap(); + // And the test file + std::fs::copy(mod_test_path, &mod_test_temp_path).unwrap(); + + // Generate coverage + let status = util::deno_cmd_with_deno_dir(&deno_dir) + .current_dir(deno_dir_path) + .arg("test") + .arg("--quiet") + .arg(format!("--coverage={}", tempdir.to_str().unwrap())) + .stdout(std::process::Stdio::piped()) + .stderr(std::process::Stdio::inherit()) + .status() + .unwrap(); + + assert!(status.success()); + + // Modify the file between deno test and deno coverage, thus invalidating the cache + std::fs::copy(mod_after_path, mod_temp_path).unwrap(); + + let output = util::deno_cmd_with_deno_dir(&deno_dir) + .current_dir(deno_dir_path) + .arg("coverage") + .arg(format!("{}/", tempdir.to_str().unwrap())) + .stdout(std::process::Stdio::piped()) + .stderr(std::process::Stdio::piped()) + .output() + .unwrap(); + + assert!(output.stdout.is_empty()); + + // Expect error + let error = + util::strip_ansi_codes(std::str::from_utf8(&output.stderr).unwrap()) + .to_string(); + assert!(error.contains("error: Missing transpiled source code")); + assert!(error.contains("Before generating coverage report, run `deno test --coverage` to ensure consistent state.")); + } + fn run_coverage_text(test_name: &str, extension: &str) { let deno_dir = TempDir::new(); let tempdir = TempDir::new(); diff --git a/cli/tests/testdata/coverage/invalid_cache/mod.test.ts b/cli/tests/testdata/coverage/invalid_cache/mod.test.ts new file mode 100644 index 000000000..5815d07a3 --- /dev/null +++ b/cli/tests/testdata/coverage/invalid_cache/mod.test.ts @@ -0,0 +1,2 @@ +import { test } from "./mod.ts"; +Deno.test("test", () => void test()); diff --git a/cli/tests/testdata/coverage/invalid_cache/mod_after.ts b/cli/tests/testdata/coverage/invalid_cache/mod_after.ts new file mode 100644 index 000000000..294dc0843 --- /dev/null +++ b/cli/tests/testdata/coverage/invalid_cache/mod_after.ts @@ -0,0 +1,6 @@ +export function test() { + return 42; +} +if (import.meta.main) { + test(); +} diff --git a/cli/tests/testdata/coverage/invalid_cache/mod_before.ts b/cli/tests/testdata/coverage/invalid_cache/mod_before.ts new file mode 100644 index 000000000..ea52ccbce --- /dev/null +++ b/cli/tests/testdata/coverage/invalid_cache/mod_before.ts @@ -0,0 +1,15 @@ +export function test() { + console.log("1"); + console.log("2"); + console.log("3"); + console.log("4"); + console.log("5"); + console.log("6"); + console.log("7"); + console.log("8"); + console.log("9"); + return 42; +} +if (import.meta.main) { + test(); +} |