From 4534db656d81f0e33dcbfbaf75c547009c9c31b8 Mon Sep 17 00:00:00 2001 From: Sebastien Filion Date: Tue, 7 Jul 2020 09:13:38 -0400 Subject: 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+/" --- cli/js/testing.ts | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'cli/js/testing.ts') diff --git a/cli/js/testing.ts b/cli/js/testing.ts index e8d42c2eb..0648683a4 100644 --- a/cli/js/testing.ts +++ b/cli/js/testing.ts @@ -308,6 +308,9 @@ function createFilterFn( if (filter) { if (filter instanceof RegExp) { passes = passes && filter.test(def.name); + } else if (filter.startsWith("/") && filter.endsWith("/")) { + const filterAsRegex = new RegExp(filter.slice(1, filter.length - 1)); + passes = passes && filterAsRegex.test(def.name); } else { passes = passes && def.name.includes(filter); } @@ -325,6 +328,8 @@ function createFilterFn( }; } +exposeForTest("createFilterFn", createFilterFn); + interface RunTestsOptions { exitOnFail?: boolean; failFast?: boolean; -- cgit v1.2.3