From 029bdf0cd55e96f393614ca566d57e4330ac9135 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 2 Aug 2023 18:38:10 +0200 Subject: feat(cli): Add dot test reporter (#19804) This commit adds a "dot" reporter to "deno test" subcommand, that can be activated using "--dot" flag. It provides a concise output using: - "." for passing test - "," for ignored test - "!" for failing test User output is silenced and not printed to the console. In non-TTY environments each result is printed on a separate line. --- cli/args/flags.rs | 86 +++++++++++++++++++++++++++++++++++++++++++++++-------- cli/args/mod.rs | 4 +-- 2 files changed, 76 insertions(+), 14 deletions(-) (limited to 'cli/args') diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 96dfbbaf5..6070ac831 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -218,6 +218,15 @@ pub struct TaskFlags { pub task: Option, } +#[derive(Clone, Debug, Default, Eq, PartialEq)] +pub enum TestReporterConfig { + #[default] + Pretty, + Dot, + // Contains path to write to or "-" to print to stdout. + Junit(String), +} + #[derive(Clone, Debug, Default, Eq, PartialEq)] pub struct TestFlags { pub doc: bool, @@ -231,7 +240,7 @@ pub struct TestFlags { pub concurrent_jobs: Option, pub trace_ops: bool, pub watch: Option, - pub junit_path: Option, + pub reporter: TestReporterConfig, } #[derive(Clone, Debug, Eq, PartialEq)] @@ -1877,6 +1886,13 @@ Directory arguments are expanded to all contained files matching the glob .require_equals(true) .default_missing_value("-") ) + .arg( + Arg::new("dot-reporter") + .long("dot") + .conflicts_with("junit") + .help("Use 'dot' test reporter with a concise output format") + .action(ArgAction::SetTrue), + ) ) } @@ -3078,6 +3094,18 @@ fn test_parse(flags: &mut Flags, matches: &mut ArgMatches) { }; let junit_path = matches.remove_one::("junit"); + let dot_reporter = matches.get_flag("dot-reporter"); + if dot_reporter { + flags.log_level = Some(Level::Error); + } + + let reporter = if dot_reporter { + TestReporterConfig::Dot + } else if let Some(path) = junit_path { + TestReporterConfig::Junit(path) + } else { + TestReporterConfig::Pretty + }; flags.subcommand = DenoSubcommand::Test(TestFlags { no_run, @@ -3091,7 +3119,7 @@ fn test_parse(flags: &mut Flags, matches: &mut ArgMatches) { concurrent_jobs, trace_ops, watch: watch_arg_parse(matches), - junit_path, + reporter, }); } @@ -5995,7 +6023,7 @@ mod tests { trace_ops: true, coverage_dir: Some("cov".to_string()), watch: Default::default(), - junit_path: None, + reporter: Default::default(), }), unstable: true, no_prompt: true, @@ -6061,6 +6089,7 @@ mod tests { Flags { subcommand: DenoSubcommand::Test(TestFlags { no_run: false, + reporter: Default::default(), doc: false, fail_fast: None, filter: None, @@ -6074,7 +6103,6 @@ mod tests { trace_ops: false, coverage_dir: None, watch: Default::default(), - junit_path: None, }), type_check_mode: TypeCheckMode::Local, no_prompt: true, @@ -6107,7 +6135,7 @@ mod tests { trace_ops: false, coverage_dir: None, watch: Default::default(), - junit_path: None, + reporter: Default::default(), }), type_check_mode: TypeCheckMode::Local, no_prompt: true, @@ -6144,7 +6172,7 @@ mod tests { trace_ops: false, coverage_dir: None, watch: Default::default(), - junit_path: None, + reporter: Default::default(), }), no_prompt: true, type_check_mode: TypeCheckMode::Local, @@ -6154,6 +6182,40 @@ mod tests { ); } + #[test] + fn test_dot() { + let r = flags_from_vec(svec!["deno", "test", "--dot"]); + assert_eq!( + r.unwrap(), + Flags { + subcommand: DenoSubcommand::Test(TestFlags { + no_run: false, + doc: false, + fail_fast: None, + filter: None, + reporter: TestReporterConfig::Dot, + allow_none: false, + shuffle: None, + files: FileFlags { + include: vec![], + ignore: vec![], + }, + concurrent_jobs: None, + trace_ops: false, + coverage_dir: None, + watch: Default::default(), + }), + no_prompt: true, + type_check_mode: TypeCheckMode::Local, + log_level: Some(Level::Error), + ..Flags::default() + } + ); + + let r = flags_from_vec(svec!["deno", "test", "--dot", "--junit"]); + assert!(r.is_err()); + } + #[test] fn test_shuffle() { let r = flags_from_vec(svec!["deno", "test", "--shuffle=1"]); @@ -6175,7 +6237,7 @@ mod tests { trace_ops: false, coverage_dir: None, watch: Default::default(), - junit_path: None, + reporter: Default::default(), }), no_prompt: true, type_check_mode: TypeCheckMode::Local, @@ -6207,7 +6269,7 @@ mod tests { watch: Some(WatchFlags { no_clear_screen: false, }), - junit_path: None, + reporter: Default::default(), }), no_prompt: true, type_check_mode: TypeCheckMode::Local, @@ -6238,7 +6300,7 @@ mod tests { watch: Some(WatchFlags { no_clear_screen: false, }), - junit_path: None, + reporter: Default::default(), }), no_prompt: true, type_check_mode: TypeCheckMode::Local, @@ -6271,7 +6333,7 @@ mod tests { watch: Some(WatchFlags { no_clear_screen: true, }), - junit_path: None, + reporter: Default::default(), }), type_check_mode: TypeCheckMode::Local, no_prompt: true, @@ -6301,7 +6363,7 @@ mod tests { trace_ops: false, coverage_dir: None, watch: Default::default(), - junit_path: Some("-".to_string()), + reporter: TestReporterConfig::Junit("-".to_string()), }), type_check_mode: TypeCheckMode::Local, no_prompt: true, @@ -6331,7 +6393,7 @@ mod tests { trace_ops: false, coverage_dir: None, watch: Default::default(), - junit_path: Some("junit.xml".to_string()), + reporter: TestReporterConfig::Junit("junit.xml".to_string()), }), type_check_mode: TypeCheckMode::Local, no_prompt: true, diff --git a/cli/args/mod.rs b/cli/args/mod.rs index 9df26b063..eb7eea44f 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -227,7 +227,7 @@ pub struct TestOptions { pub shuffle: Option, pub concurrent_jobs: NonZeroUsize, pub trace_ops: bool, - pub junit_path: Option, + pub reporter: TestReporterConfig, } impl TestOptions { @@ -252,7 +252,7 @@ impl TestOptions { no_run: test_flags.no_run, shuffle: test_flags.shuffle, trace_ops: test_flags.trace_ops, - junit_path: test_flags.junit_path, + reporter: test_flags.reporter, }) } } -- cgit v1.2.3