fix(coverage): ignore files from npm registry (#18457)

Fixes https://github.com/denoland/deno/issues/17664 and part of
https://github.com/denoland/deno/issues/18454 by excluding files
belonging to npm modules by default in the coverage output.
This commit is contained in:
Geert-Jan Zwiers 2023-03-30 19:40:22 +02:00 committed by GitHub
parent 30ee846588
commit 206c593519
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 65 additions and 0 deletions

View file

@ -588,6 +588,7 @@ fn filter_coverages(
coverages: Vec<ScriptCoverage>,
include: Vec<String>,
exclude: Vec<String>,
npm_root_dir: &str,
) -> Vec<ScriptCoverage> {
let include: Vec<Regex> =
include.iter().map(|e| Regex::new(e).unwrap()).collect();
@ -599,6 +600,7 @@ fn filter_coverages(
.into_iter()
.filter(|e| {
let is_internal = e.url.starts_with("ext:")
|| e.url.starts_with(npm_root_dir)
|| e.url.ends_with("__anonymous__")
|| e.url.ends_with("$deno$test.js")
|| e.url.ends_with(".snap");
@ -620,12 +622,14 @@ pub async fn cover_files(
}
let ps = ProcState::build(flags).await?;
let root_dir_url = ps.npm_resolver.root_dir_url();
let script_coverages = collect_coverages(coverage_flags.files)?;
let script_coverages = filter_coverages(
script_coverages,
coverage_flags.include,
coverage_flags.exclude,
root_dir_url.as_str(),
);
let proc_coverages: Vec<_> = script_coverages