0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-02-01 20:25:12 -05:00

fix(coverage): do not report transpiled files with no lines (#14699)

This commit omits files from the coverage report that have no
lines of code to report coverage for.

Fixes: https://github.com/denoland/deno/issues/14683
This commit is contained in:
Colin Ihrig 2022-05-22 10:45:22 -04:00 committed by GitHub
parent 75315dfe00
commit d55444b41c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 104 additions and 1 deletions

View file

@ -236,3 +236,76 @@ fn no_snaps_included(test_name: &str, extension: &str) {
assert!(output.status.success());
}
#[test]
fn no_transpiled_lines() {
let deno_dir = TempDir::new();
let tempdir = TempDir::new();
let tempdir = tempdir.path().join("cov");
let status = util::deno_cmd_with_deno_dir(&deno_dir)
.current_dir(util::testdata_path())
.arg("test")
.arg("--quiet")
.arg(format!("--coverage={}", tempdir.to_str().unwrap()))
.arg("coverage/no_transpiled_lines/")
.stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::inherit())
.status()
.unwrap();
assert!(status.success());
let output = util::deno_cmd_with_deno_dir(&deno_dir)
.current_dir(util::testdata_path())
.arg("coverage")
.arg(format!("{}/", tempdir.to_str().unwrap()))
.stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::piped())
.output()
.unwrap();
let actual =
util::strip_ansi_codes(std::str::from_utf8(&output.stdout).unwrap())
.to_string();
let expected = fs::read_to_string(
util::testdata_path().join("coverage/no_transpiled_lines/expected.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_with_deno_dir(&deno_dir)
.current_dir(util::testdata_path())
.arg("coverage")
.arg("--lcov")
.arg(format!("{}/", tempdir.to_str().unwrap()))
.stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::inherit())
.output()
.unwrap();
let actual =
util::strip_ansi_codes(std::str::from_utf8(&output.stdout).unwrap())
.to_string();
let expected = fs::read_to_string(
util::testdata_path().join("coverage/no_transpiled_lines/expected.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());
}

View file

@ -0,0 +1,12 @@
SF:[WILDCARD]index.ts
FNF:0
FNH:0
BRF:0
BRH:0
DA:1,1
DA:2,1
DA:3,1
DA:5,1
LH:4
LF:4
end_of_record

View file

@ -0,0 +1 @@
cover [WILDCARD]index.ts ... 100.000% (4/4)

View file

@ -0,0 +1,5 @@
export {
assertStrictEquals,
} from "https://deno.land/std@0.139.0/testing/asserts.ts";
export * from "./interface.ts";

View file

@ -0,0 +1,3 @@
export interface TestInterface {
id: string;
}

View file

@ -0,0 +1,7 @@
import { assertStrictEquals, TestInterface } from "./index.ts";
Deno.test(function noTranspiledLines() {
const foo: TestInterface = { id: "id" };
assertStrictEquals(foo.id, "id");
});

View file

@ -703,7 +703,9 @@ pub async fn cover_files(
&out_mode,
);
reporter.report(&coverage_report, original_source)?;
if !coverage_report.found_lines.is_empty() {
reporter.report(&coverage_report, original_source)?;
}
}
reporter.done();