fix(coverage): error if no files found (#21615)

This commit fixes a panic in `deno coverage` command if the file
to be covered doesn't produce any coverage data.

Fixes https://github.com/denoland/deno/issues/21580
This commit is contained in:
Bartek Iwańczuk 2023-12-18 11:43:27 +01:00 committed by GitHub
parent a44a5de430
commit 5b2caed7fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 1 deletions

View file

@ -630,3 +630,9 @@ File | Branch % | Line % |
",
);
}
itest!(no_files_found {
args: "coverage doesnt_exist.js",
exit_code: 1,
output: "coverage/doesnt_exist.out",
});

View file

@ -0,0 +1 @@
error: No coverage files found

View file

@ -453,8 +453,10 @@ pub async fn cover_files(
// Use the first include path as the default output path.
let coverage_root = coverage_flags.files.include[0].clone();
let script_coverages = collect_coverages(coverage_flags.files)?;
if script_coverages.is_empty() {
return Err(generic_error("No coverage files found"));
}
let script_coverages = filter_coverages(
script_coverages,
coverage_flags.include,