1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-25 00:29:09 -05:00

refactor(coverage): use FileFlags struct (#17388)

This commit is contained in:
Geert-Jan Zwiers 2023-01-13 22:56:29 +01:00 committed by Bartek Iwańczuk
parent 3c53c4b049
commit 3888162cfa
No known key found for this signature in database
GPG key ID: 0C6BCDDC3B3AD750
2 changed files with 19 additions and 15 deletions

View file

@ -87,9 +87,8 @@ pub struct CompletionsFlags {
#[derive(Clone, Debug, Eq, PartialEq)] #[derive(Clone, Debug, Eq, PartialEq)]
pub struct CoverageFlags { pub struct CoverageFlags {
pub files: Vec<PathBuf>, pub files: FileFlags,
pub output: Option<PathBuf>, pub output: Option<PathBuf>,
pub ignore: Vec<PathBuf>,
pub include: Vec<String>, pub include: Vec<String>,
pub exclude: Vec<String>, pub exclude: Vec<String>,
pub lcov: bool, pub lcov: bool,
@ -2430,9 +2429,11 @@ fn coverage_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
let lcov = matches.is_present("lcov"); let lcov = matches.is_present("lcov");
let output = matches.value_of("output").map(PathBuf::from); let output = matches.value_of("output").map(PathBuf::from);
flags.subcommand = DenoSubcommand::Coverage(CoverageFlags { flags.subcommand = DenoSubcommand::Coverage(CoverageFlags {
files, files: FileFlags {
include: files,
ignore,
},
output, output,
ignore,
include, include,
exclude, exclude,
lcov, lcov,
@ -6100,9 +6101,11 @@ mod tests {
r.unwrap(), r.unwrap(),
Flags { Flags {
subcommand: DenoSubcommand::Coverage(CoverageFlags { subcommand: DenoSubcommand::Coverage(CoverageFlags {
files: vec![PathBuf::from("foo.json")], files: FileFlags {
include: vec![PathBuf::from("foo.json")],
ignore: vec![],
},
output: None, output: None,
ignore: vec![],
include: vec![r"^file:".to_string()], include: vec![r"^file:".to_string()],
exclude: vec![r"test\.(js|mjs|ts|jsx|tsx)$".to_string()], exclude: vec![r"test\.(js|mjs|ts|jsx|tsx)$".to_string()],
lcov: false, lcov: false,
@ -6125,8 +6128,10 @@ mod tests {
r.unwrap(), r.unwrap(),
Flags { Flags {
subcommand: DenoSubcommand::Coverage(CoverageFlags { subcommand: DenoSubcommand::Coverage(CoverageFlags {
files: vec![PathBuf::from("foo.json")], files: FileFlags {
ignore: vec![], include: vec![PathBuf::from("foo.json")],
ignore: vec![],
},
include: vec![r"^file:".to_string()], include: vec![r"^file:".to_string()],
exclude: vec![r"test\.(js|mjs|ts|jsx|tsx)$".to_string()], exclude: vec![r"test\.(js|mjs|ts|jsx|tsx)$".to_string()],
lcov: true, lcov: true,

View file

@ -1,6 +1,7 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
use crate::args::CoverageFlags; use crate::args::CoverageFlags;
use crate::args::FileFlags;
use crate::args::Flags; use crate::args::Flags;
use crate::colors; use crate::colors;
use crate::emit::get_source_hash; use crate::emit::get_source_hash;
@ -555,8 +556,7 @@ impl CoverageReporter for PrettyCoverageReporter {
} }
fn collect_coverages( fn collect_coverages(
files: Vec<PathBuf>, files: FileFlags,
ignore: Vec<PathBuf>,
) -> Result<Vec<ScriptCoverage>, AnyError> { ) -> Result<Vec<ScriptCoverage>, AnyError> {
let mut coverages: Vec<ScriptCoverage> = Vec::new(); let mut coverages: Vec<ScriptCoverage> = Vec::new();
let file_paths = FileCollector::new(|file_path| { let file_paths = FileCollector::new(|file_path| {
@ -564,8 +564,8 @@ fn collect_coverages(
}) })
.ignore_git_folder() .ignore_git_folder()
.ignore_node_modules() .ignore_node_modules()
.add_ignore_paths(&ignore) .add_ignore_paths(&files.ignore)
.collect_files(&files)?; .collect_files(&files.include)?;
for file_path in file_paths { for file_path in file_paths {
let json = fs::read_to_string(file_path.as_path())?; let json = fs::read_to_string(file_path.as_path())?;
@ -609,14 +609,13 @@ pub async fn cover_files(
flags: Flags, flags: Flags,
coverage_flags: CoverageFlags, coverage_flags: CoverageFlags,
) -> Result<(), AnyError> { ) -> Result<(), AnyError> {
if coverage_flags.files.is_empty() { if coverage_flags.files.include.is_empty() {
return Err(generic_error("No matching coverage profiles found")); return Err(generic_error("No matching coverage profiles found"));
} }
let ps = ProcState::build(flags).await?; let ps = ProcState::build(flags).await?;
let script_coverages = let script_coverages = collect_coverages(coverage_flags.files)?;
collect_coverages(coverage_flags.files, coverage_flags.ignore)?;
let script_coverages = filter_coverages( let script_coverages = filter_coverages(
script_coverages, script_coverages,
coverage_flags.include, coverage_flags.include,