diff --git a/cli/args/flags.rs b/cli/args/flags.rs index c3e2b8cfb2..2e99aab82a 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -87,9 +87,8 @@ pub struct CompletionsFlags { #[derive(Clone, Debug, Eq, PartialEq)] pub struct CoverageFlags { - pub files: Vec, + pub files: FileFlags, pub output: Option, - pub ignore: Vec, pub include: Vec, pub exclude: Vec, pub lcov: bool, @@ -2430,9 +2429,11 @@ fn coverage_parse(flags: &mut Flags, matches: &clap::ArgMatches) { let lcov = matches.is_present("lcov"); let output = matches.value_of("output").map(PathBuf::from); flags.subcommand = DenoSubcommand::Coverage(CoverageFlags { - files, + files: FileFlags { + include: files, + ignore, + }, output, - ignore, include, exclude, lcov, @@ -6100,9 +6101,11 @@ mod tests { r.unwrap(), Flags { subcommand: DenoSubcommand::Coverage(CoverageFlags { - files: vec![PathBuf::from("foo.json")], + files: FileFlags { + include: vec![PathBuf::from("foo.json")], + ignore: vec![], + }, output: None, - ignore: vec![], include: vec![r"^file:".to_string()], exclude: vec![r"test\.(js|mjs|ts|jsx|tsx)$".to_string()], lcov: false, @@ -6125,8 +6128,10 @@ mod tests { r.unwrap(), Flags { subcommand: DenoSubcommand::Coverage(CoverageFlags { - files: vec![PathBuf::from("foo.json")], - ignore: vec![], + files: FileFlags { + include: vec![PathBuf::from("foo.json")], + ignore: vec![], + }, include: vec![r"^file:".to_string()], exclude: vec![r"test\.(js|mjs|ts|jsx|tsx)$".to_string()], lcov: true, diff --git a/cli/tools/coverage/mod.rs b/cli/tools/coverage/mod.rs index 075a43feaa..cbb2bd9cc1 100644 --- a/cli/tools/coverage/mod.rs +++ b/cli/tools/coverage/mod.rs @@ -1,6 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. use crate::args::CoverageFlags; +use crate::args::FileFlags; use crate::args::Flags; use crate::colors; use crate::emit::get_source_hash; @@ -555,8 +556,7 @@ impl CoverageReporter for PrettyCoverageReporter { } fn collect_coverages( - files: Vec, - ignore: Vec, + files: FileFlags, ) -> Result, AnyError> { let mut coverages: Vec = Vec::new(); let file_paths = FileCollector::new(|file_path| { @@ -564,8 +564,8 @@ fn collect_coverages( }) .ignore_git_folder() .ignore_node_modules() - .add_ignore_paths(&ignore) - .collect_files(&files)?; + .add_ignore_paths(&files.ignore) + .collect_files(&files.include)?; for file_path in file_paths { let json = fs::read_to_string(file_path.as_path())?; @@ -609,14 +609,13 @@ pub async fn cover_files( flags: Flags, coverage_flags: CoverageFlags, ) -> Result<(), AnyError> { - if coverage_flags.files.is_empty() { + if coverage_flags.files.include.is_empty() { return Err(generic_error("No matching coverage profiles found")); } let ps = ProcState::build(flags).await?; - let script_coverages = - collect_coverages(coverage_flags.files, coverage_flags.ignore)?; + let script_coverages = collect_coverages(coverage_flags.files)?; let script_coverages = filter_coverages( script_coverages, coverage_flags.include,