mirror of
https://github.com/denoland/deno.git
synced 2024-12-24 08:09:08 -05:00
refactor(coverage): use FileFlags struct (#17388)
This commit is contained in:
parent
3c53c4b049
commit
3888162cfa
2 changed files with 19 additions and 15 deletions
|
@ -87,9 +87,8 @@ pub struct CompletionsFlags {
|
|||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct CoverageFlags {
|
||||
pub files: Vec<PathBuf>,
|
||||
pub files: FileFlags,
|
||||
pub output: Option<PathBuf>,
|
||||
pub ignore: Vec<PathBuf>,
|
||||
pub include: Vec<String>,
|
||||
pub exclude: Vec<String>,
|
||||
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,
|
||||
|
|
|
@ -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<PathBuf>,
|
||||
ignore: Vec<PathBuf>,
|
||||
files: FileFlags,
|
||||
) -> Result<Vec<ScriptCoverage>, AnyError> {
|
||||
let mut coverages: Vec<ScriptCoverage> = 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,
|
||||
|
|
Loading…
Reference in a new issue