fix(coverage): Error if no files are included in the report (#22952)

Fixes #22941.

In that case, the only file with coverage was the `test.ts` file. The
coverage reporter filters out test files before compiling its report, so
after filtering we were left with an empty set of files. Later on it's
assumed that there is at least 1 file to be reported on, and we panic.
Instead of panicking, just issue an error after filtering.
This commit is contained in:
Nathan Whitaker 2024-03-15 20:58:57 -07:00 committed by GitHub
parent 92576fdcfd
commit ab67b4c645
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 26 additions and 0 deletions

View File

@ -485,6 +485,9 @@ pub async fn cover_files(
coverage_flags.exclude, coverage_flags.exclude,
npm_resolver.as_ref(), npm_resolver.as_ref(),
); );
if script_coverages.is_empty() {
return Err(generic_error("No covered files included in the report"));
}
let proc_coverages: Vec<_> = script_coverages let proc_coverages: Vec<_> = script_coverages
.into_iter() .into_iter()

View File

@ -0,0 +1,15 @@
{
"tempDir": true,
"steps": [
{
"args": "test --coverage test.ts",
"output": "test_coverage.out",
"exitCode": 0
},
{
"args": "coverage ./coverage",
"output": "no_files_in_report.out",
"exitCode": 1
}
]
}

View File

@ -0,0 +1 @@
error: No covered files included in the report

View File

@ -0,0 +1 @@
Deno.test("test", () => {});

View File

@ -0,0 +1,6 @@
Check [WILDCARD]/test.ts
running 1 test from ./test.ts
test ... ok ([WILDCARD])
ok | 1 passed | 0 failed ([WILDCARD])