fix(coverage): don't panic if all covered files are ignored via directive (#29250)

Closes https://github.com/denoland/deno/issues/29218
This commit is contained in:
Bartek Iwańczuk 2025-05-12 02:47:32 +02:00 committed by GitHub
parent 5ab029db22
commit 2fe200f6ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 30 additions and 1 deletions

View file

@ -740,6 +740,12 @@ pub fn cover_files(
}
}
// All covered files, might have had ignore directive and we can end up
// with no reports at this point.
if file_reports.is_empty() {
return Err(anyhow!("No covered files included in the report"));
}
for reporter in reporters {
reporter.done(&coverage_root, &file_reports);
}

View file

@ -18,7 +18,7 @@ use super::CoverageReport;
use crate::args::CoverageType;
use crate::colors;
#[derive(Default)]
#[derive(Default, Debug)]
pub struct CoverageStats<'a> {
pub line_hit: usize,
pub line_miss: usize,

View file

@ -0,0 +1,6 @@
{
"tempDir": true,
"args": "test --coverage test.ts",
"output": "test_coverage.out",
"exitCode": 0
}

View file

@ -0,0 +1,5 @@
// deno-coverage-ignore-file
export function foo() {
return "foo";
}

View file

@ -0,0 +1,5 @@
import { foo } from "./lib.ts";
Deno.test("test", () => {
foo();
});

View file

@ -0,0 +1,7 @@
Check [WILDCARD]/test.ts
running 1 test from ./test.ts
test ... ok ([WILDCARD])
ok | 1 passed | 0 failed ([WILDCARD])
Error generating coverage report: No covered files included in the report