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:
parent
75315dfe00
commit
d55444b41c
7 changed files with 104 additions and 1 deletions
|
@ -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());
|
||||
}
|
||||
|
|
12
cli/tests/testdata/coverage/no_transpiled_lines/expected.lcov
vendored
Normal file
12
cli/tests/testdata/coverage/no_transpiled_lines/expected.lcov
vendored
Normal 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
|
1
cli/tests/testdata/coverage/no_transpiled_lines/expected.out
vendored
Normal file
1
cli/tests/testdata/coverage/no_transpiled_lines/expected.out
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
cover [WILDCARD]index.ts ... 100.000% (4/4)
|
5
cli/tests/testdata/coverage/no_transpiled_lines/index.ts
vendored
Normal file
5
cli/tests/testdata/coverage/no_transpiled_lines/index.ts
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
export {
|
||||
assertStrictEquals,
|
||||
} from "https://deno.land/std@0.139.0/testing/asserts.ts";
|
||||
|
||||
export * from "./interface.ts";
|
3
cli/tests/testdata/coverage/no_transpiled_lines/interface.ts
vendored
Normal file
3
cli/tests/testdata/coverage/no_transpiled_lines/interface.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
export interface TestInterface {
|
||||
id: string;
|
||||
}
|
7
cli/tests/testdata/coverage/no_transpiled_lines/repro_test.ts
vendored
Normal file
7
cli/tests/testdata/coverage/no_transpiled_lines/repro_test.ts
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
import { assertStrictEquals, TestInterface } from "./index.ts";
|
||||
|
||||
Deno.test(function noTranspiledLines() {
|
||||
const foo: TestInterface = { id: "id" };
|
||||
|
||||
assertStrictEquals(foo.id, "id");
|
||||
});
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Reference in a new issue