diff options
author | Sebastien Filion <sebastienfilion@mac.com> | 2020-07-07 09:13:38 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-07 15:13:38 +0200 |
commit | 4534db656d81f0e33dcbfbaf75c547009c9c31b8 (patch) | |
tree | 514b958141446f7a96224b213ad13d9b7429ac4c /cli/tests | |
parent | 14a44464a6e2c078fd329c26eff2ecfbc9b58603 (diff) |
feat(test): Add support for regex in filter flag (#6343)
Currently, the documentation makes it sound like the test subcommand's filter
flag could accept some kind of pattern matching value like a glob or a regex,
although the function "createFilterFn" accepts a regex as an argument, there's
no way to pass an actual regex value from the CLI.
This commit makes it possible to pass a string that could be cast as regex
when string matches "^/.*/$".
With this change, a user can use the filter flag as follow:
deno test --filter "/test-.+/"
Also tested that `\` get escaped properly, on MacOS at least, and this is
also a valid flag:
deno test --filter "/test-\d+/"
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/unit/filter_function_test.ts | 52 | ||||
-rw-r--r-- | cli/tests/unit/unit_tests.ts | 1 |
2 files changed, 53 insertions, 0 deletions
diff --git a/cli/tests/unit/filter_function_test.ts b/cli/tests/unit/filter_function_test.ts new file mode 100644 index 000000000..dd83c1dbc --- /dev/null +++ b/cli/tests/unit/filter_function_test.ts @@ -0,0 +1,52 @@ +import { unitTest, assertEquals } from "./test_util.ts"; + +// @ts-expect-error TypeScript (as of 3.7) does not support indexing namespaces by symbol +const { createFilterFn } = Deno[Deno.internal]; + +unitTest(function filterAsString(): void { + const filterFn = createFilterFn("my-test"); + const tests = [ + { + fn(): void {}, + name: "my-test", + }, + { + fn(): void {}, + name: "other-test", + }, + ]; + const filteredTests = tests.filter(filterFn); + assertEquals(filteredTests.length, 1); +}); + +unitTest(function filterAsREGEX(): void { + const filterFn = createFilterFn("/.+-test/"); + const tests = [ + { + fn(): void {}, + name: "my-test", + }, + { + fn(): void {}, + name: "other-test", + }, + ]; + const filteredTests = tests.filter(filterFn); + assertEquals(filteredTests.length, 2); +}); + +unitTest(function filterAsEscapedREGEX(): void { + const filterFn = createFilterFn("/\\w+-test/"); + const tests = [ + { + fn(): void {}, + name: "my-test", + }, + { + fn(): void {}, + name: "other-test", + }, + ]; + const filteredTests = tests.filter(filterFn); + assertEquals(filteredTests.length, 2); +}); diff --git a/cli/tests/unit/unit_tests.ts b/cli/tests/unit/unit_tests.ts index 1701170d1..ad820a55c 100644 --- a/cli/tests/unit/unit_tests.ts +++ b/cli/tests/unit/unit_tests.ts @@ -24,6 +24,7 @@ import "./event_target_test.ts"; import "./fetch_test.ts"; import "./file_test.ts"; import "./files_test.ts"; +import "./filter_function_test.ts"; import "./form_data_test.ts"; import "./format_error_test.ts"; import "./fs_events_test.ts"; |