summaryrefslogtreecommitdiff
path: root/cli/tests/coverage_tests.rs
diff options
context:
space:
mode:
authorsigmaSd <bedisnbiba@gmail.com>2022-11-29 18:43:54 +0100
committerGitHub <noreply@github.com>2022-11-29 18:43:54 +0100
commit2656af2544cd1773e5b7d57e4306a8cec15ef887 (patch)
tree8e809cf8461162c0301f447c002120f2d379813a /cli/tests/coverage_tests.rs
parente4fe5ee72ace30ccd1b7b6b15717164cf79f49c4 (diff)
fix(coverage): Error if the emit cache is invalid (#16850)
Diffstat (limited to 'cli/tests/coverage_tests.rs')
-rw-r--r--cli/tests/coverage_tests.rs62
1 files changed, 62 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();