summaryrefslogtreecommitdiff
path: root/cli/tests/integration_tests.rs
diff options
context:
space:
mode:
authorCasper Beyer <caspervonb@pm.me>2021-02-24 22:27:51 +0800
committerGitHub <noreply@github.com>2021-02-24 15:27:51 +0100
commitae8874b4b2015453e53965dae2a2dae9cacbce70 (patch)
treedc61e231685fc3bd0b32e90769ce0d3ad112e875 /cli/tests/integration_tests.rs
parentf6a80f34d9f750e6c9c6c40f57211fc95befdf7a (diff)
feat: add "deno coverage" subcommand (#8664)
This commit adds a new subcommand called "coverage" which can generate code coverage reports to stdout in multiple formats from code coverage profiles collected to disk. Currently this supports outputting a pretty printed diff and the lcov format for interoperability with third-party services and tools. Code coverage is still collected via other subcommands that run and collect code coverage such as "deno test --coverage=<directory>" but that command no longer prints a pretty printed report at the end of a test run with coverage collection enabled. The restrictions on which files that can be reported on has also been relaxed and are fully controllable with the include and exclude regular expression flags on the coverage subcommand. Co-authored-by: Luca Casonato <lucacasonato@yahoo.com>
Diffstat (limited to 'cli/tests/integration_tests.rs')
-rw-r--r--cli/tests/integration_tests.rs196
1 files changed, 154 insertions, 42 deletions
diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs
index e57bca27f..f9f458016 100644
--- a/cli/tests/integration_tests.rs
+++ b/cli/tests/integration_tests.rs
@@ -3612,48 +3612,6 @@ console.log("finish");
output: "redirect_cache.out",
});
- itest!(deno_test_coverage {
- args: "test --coverage --unstable test_coverage.ts",
- output: "test_coverage.out",
- exit_code: 0,
- });
-
- itest!(deno_test_comment_coverage {
- args: "test --coverage --unstable test_comment_coverage.ts",
- output: "test_comment_coverage.out",
- exit_code: 0,
- });
-
- itest!(deno_test_branch_coverage {
- args: "test --coverage --unstable test_branch_coverage.ts",
- output: "test_branch_coverage.out",
- exit_code: 0,
- });
-
- itest!(deno_test_coverage_explicit {
- args: "test --coverage=.test_coverage --unstable test_coverage.ts",
- output: "test_coverage.out",
- exit_code: 0,
- });
-
- itest!(deno_test_run_test_coverage {
- args: "test --allow-all --coverage --unstable test_run_test_coverage.ts",
- output: "test_run_test_coverage.out",
- exit_code: 0,
- });
-
- itest!(deno_test_run_run_coverage {
- args: "test --allow-all --coverage --unstable test_run_run_coverage.ts",
- output: "test_run_run_coverage.out",
- exit_code: 0,
- });
-
- itest!(deno_test_run_combined_coverage {
- args: "test --allow-all --coverage --unstable test_run_run_coverage.ts test_run_test_coverage.ts",
- output: "test_run_combined_coverage.out",
- exit_code: 0,
- });
-
itest!(deno_lint {
args: "lint --unstable lint/file1.js lint/file2.ts lint/ignored_file.ts",
output: "lint/expected.out",
@@ -3988,6 +3946,160 @@ console.log("finish");
assert_eq!(output.stderr, b"");
}
+ mod coverage {
+ use super::*;
+
+ #[test]
+ fn branch() {
+ let tempdir = TempDir::new().expect("tempdir fail");
+ let status = util::deno_cmd()
+ .current_dir(util::root_path())
+ .arg("test")
+ .arg("--quiet")
+ .arg("--unstable")
+ .arg(format!("--coverage={}", tempdir.path().to_str().unwrap()))
+ .arg("cli/tests/coverage/branch_test.ts")
+ .stdout(std::process::Stdio::piped())
+ .stderr(std::process::Stdio::inherit())
+ .status()
+ .expect("failed to spawn test runner");
+
+ assert!(status.success());
+
+ let output = util::deno_cmd()
+ .current_dir(util::root_path())
+ .arg("coverage")
+ .arg("--quiet")
+ .arg("--unstable")
+ .arg(format!("{}/", tempdir.path().to_str().unwrap()))
+ .stdout(std::process::Stdio::piped())
+ .stderr(std::process::Stdio::inherit())
+ .output()
+ .expect("failed to spawn coverage reporter");
+
+ let actual =
+ util::strip_ansi_codes(std::str::from_utf8(&output.stdout).unwrap())
+ .to_string();
+
+ let expected = fs::read_to_string(
+ util::root_path().join("cli/tests/coverage/expected_branch.out"),
+ )
+ .unwrap();
+
+ if !util::wildcard_match(&expected, &actual) {
+ println!("OUTPUT\n{}\nOUTPUT", actual);
+ println!("EXPECTED\n{}\nEXPECTED", expected);
+ panic!("pattern match failed");
+ }
+
+ assert!(output.status.success());
+
+ let output = util::deno_cmd()
+ .current_dir(util::root_path())
+ .arg("coverage")
+ .arg("--quiet")
+ .arg("--unstable")
+ .arg("--lcov")
+ .arg(format!("{}/", tempdir.path().to_str().unwrap()))
+ .stdout(std::process::Stdio::piped())
+ .stderr(std::process::Stdio::inherit())
+ .output()
+ .expect("failed to spawn coverage reporter");
+
+ let actual =
+ util::strip_ansi_codes(std::str::from_utf8(&output.stdout).unwrap())
+ .to_string();
+
+ let expected = fs::read_to_string(
+ util::root_path().join("cli/tests/coverage/expected_branch.lcov"),
+ )
+ .unwrap();
+
+ if !util::wildcard_match(&expected, &actual) {
+ println!("OUTPUT\n{}\nOUTPUT", actual);
+ println!("EXPECTED\n{}\nEXPECTED", expected);
+ panic!("pattern match failed");
+ }
+
+ assert!(output.status.success());
+ }
+
+ #[test]
+ fn complex() {
+ let tempdir = TempDir::new().expect("tempdir fail");
+ let status = util::deno_cmd()
+ .current_dir(util::root_path())
+ .arg("test")
+ .arg("--quiet")
+ .arg("--unstable")
+ .arg(format!("--coverage={}", tempdir.path().to_str().unwrap()))
+ .arg("cli/tests/coverage/complex_test.ts")
+ .stdout(std::process::Stdio::piped())
+ .stderr(std::process::Stdio::inherit())
+ .status()
+ .expect("failed to spawn test runner");
+
+ assert!(status.success());
+
+ let output = util::deno_cmd()
+ .current_dir(util::root_path())
+ .arg("coverage")
+ .arg("--quiet")
+ .arg("--unstable")
+ .arg(format!("{}/", tempdir.path().to_str().unwrap()))
+ .stdout(std::process::Stdio::piped())
+ .stderr(std::process::Stdio::inherit())
+ .output()
+ .expect("failed to spawn coverage reporter");
+
+ let actual =
+ util::strip_ansi_codes(std::str::from_utf8(&output.stdout).unwrap())
+ .to_string();
+
+ let expected = fs::read_to_string(
+ util::root_path().join("cli/tests/coverage/expected_complex.out"),
+ )
+ .unwrap();
+
+ if !util::wildcard_match(&expected, &actual) {
+ println!("OUTPUT\n{}\nOUTPUT", actual);
+ println!("EXPECTED\n{}\nEXPECTED", expected);
+ panic!("pattern match failed");
+ }
+
+ assert!(output.status.success());
+
+ let output = util::deno_cmd()
+ .current_dir(util::root_path())
+ .arg("coverage")
+ .arg("--quiet")
+ .arg("--unstable")
+ .arg("--lcov")
+ .arg(format!("{}/", tempdir.path().to_str().unwrap()))
+ .stdout(std::process::Stdio::piped())
+ .stderr(std::process::Stdio::inherit())
+ .output()
+ .expect("failed to spawn coverage reporter");
+
+ let actual =
+ util::strip_ansi_codes(std::str::from_utf8(&output.stdout).unwrap())
+ .to_string();
+
+ let expected = fs::read_to_string(
+ util::root_path().join("cli/tests/coverage/expected_complex.lcov"),
+ )
+ .unwrap();
+
+ if !util::wildcard_match(&expected, &actual) {
+ println!("OUTPUT\n{}\nOUTPUT", actual);
+ println!("EXPECTED\n{}\nEXPECTED", expected);
+ panic!("pattern match failed");
+ }
+
+ assert!(output.status.success());
+ }
+ }
+
mod permissions {
use super::*;