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 /docs/testing.md | |
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 'docs/testing.md')
-rw-r--r-- | docs/testing.md | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/docs/testing.md b/docs/testing.md index f44483125..174123cce 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -129,10 +129,33 @@ There are a number of options to filter the tests you are running. Tests can be run individually or in groups using the command line `--filter` option. +The filter flags accept a string or a pattern as value. + +Assuming the following tests: + +```ts +Deno.test({ name: "my-test", fn: myTest }); +Deno.test({ name: "test-1", fn: test1 }); +Deno.test({ name: "test2", fn: test2 }); +``` + +This command will run all of these tests because they all contain the word +"test". + ```shell -deno test --filter "hello world" tests/ +deno test --filter "test" tests/ ``` +On the flip side, the following command uses a pattern and will run the second +and third tests. + +```shell +deno test --filter "/test-*\d/" tests/ +``` + +_To let Deno know that you want to use a pattern, wrap your filter with +forward-slashes like the JavaScript syntactic sugar for a REGEX._ + This command will run any test which contains the string "hello world" in its test name for tests found within files in the `tests/` directory. |