diff --git a/cli/tools/coverage/mod.rs b/cli/tools/coverage/mod.rs index 47841b0377..e1c5d9eb40 100644 --- a/cli/tools/coverage/mod.rs +++ b/cli/tools/coverage/mod.rs @@ -397,11 +397,7 @@ fn collect_coverages( )? } }), - exclude: PathOrPatternSet::from_exclude_relative_path_or_patterns( - initial_cwd, - &files.ignore, - ) - .context("Invalid ignore pattern.")?, + exclude: PathOrPatternSet::new(vec![]), }; let file_paths = FileCollector::new(|e| { e.path.extension().map(|ext| ext == "json").unwrap_or(false) @@ -411,12 +407,28 @@ fn collect_coverages( .set_vendor_folder(cli_options.vendor_dir_path().map(ToOwned::to_owned)) .collect_file_patterns(file_patterns)?; + let coverage_patterns = FilePatterns { + base: initial_cwd.to_path_buf(), + include: None, + exclude: PathOrPatternSet::from_exclude_relative_path_or_patterns( + initial_cwd, + &files.ignore, + ) + .context("Invalid ignore pattern.")?, + }; + for file_path in file_paths { let new_coverage = fs::read_to_string(file_path.as_path()) .map_err(AnyError::from) - .and_then(|json| serde_json::from_str(&json).map_err(AnyError::from)) + .and_then(|json| { + serde_json::from_str::(&json) + .map_err(AnyError::from) + }) .with_context(|| format!("Failed reading '{}'", file_path.display()))?; - coverages.push(new_coverage); + let url = Url::parse(&new_coverage.url)?; + if coverage_patterns.matches_specifier(&url) { + coverages.push(new_coverage); + } } coverages.sort_by_key(|k| k.url.clone()); diff --git a/tests/integration/coverage_tests.rs b/tests/integration/coverage_tests.rs index f6011b0544..c1e5055dab 100644 --- a/tests/integration/coverage_tests.rs +++ b/tests/integration/coverage_tests.rs @@ -547,14 +547,15 @@ fn test_summary_reporter() { output.assert_exit_code(0); output.skip_output_check(); - let output = context - .new_command() - .args_vec(vec!["coverage".to_string(), format!("{}/", tempdir)]) - .run(); + { + let output = context + .new_command() + .args_vec(vec!["coverage".to_string(), format!("{}/", tempdir)]) + .run(); - output.assert_exit_code(0); - output.assert_matches_text( - "---------------------------------- + output.assert_exit_code(0); + output.assert_matches_text( + "---------------------------------- File | Branch % | Line % | ---------------------------------- bar.ts | 0.0 | 57.1 | @@ -565,7 +566,33 @@ File | Branch % | Line % | All files | 40.0 | 61.0 | ---------------------------------- ", - ); + ); + } + + // test --ignore flag works + { + let output = context + .new_command() + .args_vec(vec![ + "coverage".to_string(), + format!("{}/", tempdir), + "--ignore=**/bar.ts,**/quux.ts".to_string(), + ]) + .run(); + + output.assert_exit_code(0); + output.assert_matches_text( + "--------------------------------- +File | Branch % | Line % | +--------------------------------- + baz/qux.ts | 100.0 | 100.0 | + foo.ts | 50.0 | 76.9 | +--------------------------------- + All files | 66.7 | 85.0 | +--------------------------------- +", + ); + } } #[test]