From 2cbd1b40cb4392b6a4f6b2e7315e610f488d66b7 Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Wed, 6 Sep 2023 17:07:37 +0100 Subject: [PATCH] fix(test): apply filter before checking for "only" (#20389) --- cli/tests/integration/test_tests.rs | 5 +++++ cli/tests/testdata/test/filtered_out_only.out | 5 +++++ cli/tests/testdata/test/filtered_out_only.ts | 2 ++ cli/tools/test/mod.rs | 10 +++++----- 4 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 cli/tests/testdata/test/filtered_out_only.out create mode 100644 cli/tests/testdata/test/filtered_out_only.ts diff --git a/cli/tests/integration/test_tests.rs b/cli/tests/integration/test_tests.rs index f84c2a5608..042e840789 100644 --- a/cli/tests/integration/test_tests.rs +++ b/cli/tests/integration/test_tests.rs @@ -91,6 +91,11 @@ itest!(test_with_malformed_config { output: "test/collect_with_malformed_config.out", }); +itest!(test_filtered_out_only { + args: "test --quiet --filter foo test/filtered_out_only.ts", + output: "test/filtered_out_only.out", +}); + itest!(parallel_flag { args: "test test/short-pass.ts --parallel", exit_code: 0, diff --git a/cli/tests/testdata/test/filtered_out_only.out b/cli/tests/testdata/test/filtered_out_only.out new file mode 100644 index 0000000000..337893848a --- /dev/null +++ b/cli/tests/testdata/test/filtered_out_only.out @@ -0,0 +1,5 @@ +running 1 test from ./test/filtered_out_only.ts +foo ... ok ([WILDCARD]) + +ok | 1 passed | 0 failed | 1 filtered out ([WILDCARD]) + diff --git a/cli/tests/testdata/test/filtered_out_only.ts b/cli/tests/testdata/test/filtered_out_only.ts new file mode 100644 index 0000000000..bda301a43b --- /dev/null +++ b/cli/tests/testdata/test/filtered_out_only.ts @@ -0,0 +1,2 @@ +Deno.test("foo", () => {}); +Deno.test("bar", { only: true }, () => {}); diff --git a/cli/tools/test/mod.rs b/cli/tools/test/mod.rs index 7ab74ff7c4..15f8d25970 100644 --- a/cli/tools/test/mod.rs +++ b/cli/tools/test/mod.rs @@ -464,14 +464,14 @@ pub async fn test_specifier( std::mem::take(&mut state.borrow_mut::().0) }; let unfiltered = tests.len(); - let (only, no_only): (Vec<_>, Vec<_>) = - tests.into_iter().partition(|(d, _)| d.only); - let used_only = !only.is_empty(); - let tests = if used_only { only } else { no_only }; - let mut tests = tests + let tests = tests .into_iter() .filter(|(d, _)| options.filter.includes(&d.name)) .collect::>(); + let (only, no_only): (Vec<_>, Vec<_>) = + tests.into_iter().partition(|(d, _)| d.only); + let used_only = !only.is_empty(); + let mut tests = if used_only { only } else { no_only }; if let Some(seed) = options.shuffle { tests.shuffle(&mut SmallRng::seed_from_u64(seed)); }