From e0a269c23af2bccfa71d7a22506a348574be138a Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Wed, 6 Sep 2023 14:54:21 +0200 Subject: [PATCH] fix: don't show filtered test suites as running (#20385) --- cli/tests/integration/test_tests.rs | 6 ++++++ cli/tests/testdata/test/hide_empty_suites.out | 4 ++++ cli/tools/test/mod.rs | 4 ++++ cli/tools/test/reporters/pretty.rs | 10 ++++++++-- 4 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 cli/tests/testdata/test/hide_empty_suites.out diff --git a/cli/tests/integration/test_tests.rs b/cli/tests/integration/test_tests.rs index 030da05e1e..f84c2a5608 100644 --- a/cli/tests/integration/test_tests.rs +++ b/cli/tests/integration/test_tests.rs @@ -278,6 +278,12 @@ itest!(clear_timeout { output: "test/clear_timeout.out", }); +itest!(hide_empty_suites { + args: "test --filter none test/pass.ts", + exit_code: 0, + output: "test/hide_empty_suites.out", +}); + itest!(finally_timeout { args: "test test/finally_timeout.ts", exit_code: 1, diff --git a/cli/tests/testdata/test/hide_empty_suites.out b/cli/tests/testdata/test/hide_empty_suites.out new file mode 100644 index 0000000000..d270cb05a5 --- /dev/null +++ b/cli/tests/testdata/test/hide_empty_suites.out @@ -0,0 +1,4 @@ +Check [WILDCARD]/test/pass.ts + +ok | 0 passed | 0 failed | 16 filtered out ([WILDCARD]) + diff --git a/cli/tools/test/mod.rs b/cli/tools/test/mod.rs index 296d306e25..7ab74ff7c4 100644 --- a/cli/tools/test/mod.rs +++ b/cli/tools/test/mod.rs @@ -343,6 +343,7 @@ struct TestSpecifiersOptions { concurrent_jobs: NonZeroUsize, fail_fast: Option, log_level: Option, + filter: bool, specifier: TestSpecifierOptions, reporter: TestReporterConfig, junit_path: Option, @@ -384,6 +385,7 @@ fn get_test_reporter(options: &TestSpecifiersOptions) -> Box { TestReporterConfig::Pretty => Box::new(PrettyTestReporter::new( parallel, options.log_level != Some(Level::Error), + options.filter, )), TestReporterConfig::Junit => { Box::new(JunitTestReporter::new("-".to_string())) @@ -1144,6 +1146,7 @@ pub async fn run_tests( concurrent_jobs: test_options.concurrent_jobs, fail_fast: test_options.fail_fast, log_level, + filter: test_options.filter.is_some(), reporter: test_options.reporter, junit_path: test_options.junit_path, specifier: TestSpecifierOptions { @@ -1276,6 +1279,7 @@ pub async fn run_tests_with_watch( concurrent_jobs: test_options.concurrent_jobs, fail_fast: test_options.fail_fast, log_level, + filter: test_options.filter.is_some(), reporter: test_options.reporter, junit_path: test_options.junit_path, specifier: TestSpecifierOptions { diff --git a/cli/tools/test/reporters/pretty.rs b/cli/tools/test/reporters/pretty.rs index 394a7c4908..8a2b77bb0c 100644 --- a/cli/tools/test/reporters/pretty.rs +++ b/cli/tools/test/reporters/pretty.rs @@ -8,6 +8,7 @@ pub struct PrettyTestReporter { parallel: bool, echo_output: bool, in_new_line: bool, + filter: bool, scope_test_id: Option, cwd: Url, did_have_user_output: bool, @@ -18,11 +19,16 @@ pub struct PrettyTestReporter { } impl PrettyTestReporter { - pub fn new(parallel: bool, echo_output: bool) -> PrettyTestReporter { + pub fn new( + parallel: bool, + echo_output: bool, + filter: bool, + ) -> PrettyTestReporter { PrettyTestReporter { parallel, echo_output, in_new_line: true, + filter, scope_test_id: None, cwd: Url::from_directory_path(std::env::current_dir().unwrap()).unwrap(), did_have_user_output: false, @@ -133,7 +139,7 @@ impl TestReporter for PrettyTestReporter { fn report_plan(&mut self, plan: &TestPlan) { self.summary.total += plan.total; self.summary.filtered_out += plan.filtered_out; - if self.parallel { + if self.parallel || (self.filter && plan.total == 0) { return; } let inflection = if plan.total == 1 { "test" } else { "tests" };