summaryrefslogtreecommitdiff
path: root/cli/main.rs
diff options
context:
space:
mode:
authorCasper Beyer <caspervonb@pm.me>2021-02-24 22:27:51 +0800
committerGitHub <noreply@github.com>2021-02-24 15:27:51 +0100
commitae8874b4b2015453e53965dae2a2dae9cacbce70 (patch)
treedc61e231685fc3bd0b32e90769ce0d3ad112e875 /cli/main.rs
parentf6a80f34d9f750e6c9c6c40f57211fc95befdf7a (diff)
feat: add "deno coverage" subcommand (#8664)
This commit adds a new subcommand called "coverage" which can generate code coverage reports to stdout in multiple formats from code coverage profiles collected to disk. Currently this supports outputting a pretty printed diff and the lcov format for interoperability with third-party services and tools. Code coverage is still collected via other subcommands that run and collect code coverage such as "deno test --coverage=<directory>" but that command no longer prints a pretty printed report at the end of a test run with coverage collection enabled. The restrictions on which files that can be reported on has also been relaxed and are fully controllable with the include and exclude regular expression flags on the coverage subcommand. Co-authored-by: Luca Casonato <lucacasonato@yahoo.com>
Diffstat (limited to 'cli/main.rs')
-rw-r--r--cli/main.rs51
1 files changed, 36 insertions, 15 deletions
diff --git a/cli/main.rs b/cli/main.rs
index b9516e704..e957b9342 100644
--- a/cli/main.rs
+++ b/cli/main.rs
@@ -978,6 +978,34 @@ async fn run_command(flags: Flags, script: String) -> Result<(), AnyError> {
Ok(())
}
+async fn coverage_command(
+ flags: Flags,
+ files: Vec<PathBuf>,
+ ignore: Vec<PathBuf>,
+ include: Vec<String>,
+ exclude: Vec<String>,
+ lcov: bool,
+) -> Result<(), AnyError> {
+ if !flags.unstable {
+ exit_unstable("compile");
+ }
+
+ if files.is_empty() {
+ println!("No matching coverage profiles found");
+ std::process::exit(1);
+ }
+
+ tools::coverage::cover_files(
+ flags.clone(),
+ files,
+ ignore,
+ include,
+ exclude,
+ lcov,
+ )
+ .await
+}
+
async fn test_command(
flags: Flags,
include: Option<Vec<String>>,
@@ -1047,7 +1075,6 @@ async fn test_command(
let mut maybe_coverage_collector =
if let Some(ref coverage_dir) = program_state.coverage_dir {
let session = worker.create_inspector_session();
-
let coverage_dir = PathBuf::from(coverage_dir);
let mut coverage_collector =
tools::coverage::CoverageCollector::new(coverage_dir, session);
@@ -1067,20 +1094,6 @@ async fn test_command(
if let Some(coverage_collector) = maybe_coverage_collector.as_mut() {
coverage_collector.stop_collecting().await?;
-
- // TODO(caspervonb) extract reporting into it's own subcommand.
- // For now, we'll only report for the command that passed --coverage as a flag.
- if flags.coverage_dir.is_some() {
- let mut exclude = test_modules.clone();
- exclude.push(main_module.clone());
- tools::coverage::report_coverages(
- program_state.clone(),
- &coverage_collector.dir,
- quiet,
- exclude,
- )
- .await?;
- }
}
Ok(())
@@ -1172,6 +1185,14 @@ fn get_subcommand(
target,
} => compile_command(flags, source_file, output, args, target, lite)
.boxed_local(),
+ DenoSubcommand::Coverage {
+ files,
+ ignore,
+ include,
+ exclude,
+ lcov,
+ } => coverage_command(flags, files, ignore, include, exclude, lcov)
+ .boxed_local(),
DenoSubcommand::Fmt {
check,
files,