Rstest provides a variety of flexible ways to filter and select which test files and test cases to run. You can precisely control the test scope via configuration files, command-line arguments, and test APIs.
Run all tests:
Run a specific test file:
Use glob patterns:
Run test files with foo
in the name, such as foo.test.ts
, foo/index.test.ts
, foo-bar/index.test.ts
, etc.:
You can also specify multiple test files or glob patterns:
When you filter files directly with rstest **/*.test.ts
, rstest will further filter files based on the include and exclude configuration.
You can modify the test file scope using the include
and exclude
options.
For example, to match test files named index
in the test/a
directory:
To match test files in test/a
or test/b
directories:
If you only want to run test cases whose names contain a specific keyword, you can use testNamePattern.
For example, to only run test cases whose names contain "login":
All filtering methods can be combined. For example:
In this case, rstest will only run test cases whose names contain login in all .test.ts
files under the test
directory, while excluding the test/legacy
directory.
Run a specific file only: rstest test/foo.test.ts
Run tests in a specific directory only: rstest test/api/*.test.ts
Exclude certain tests: rstest --exclude test/legacy/**
Run only tests whose names contain login: rstest -t login
Combined filtering: rstest test/**/*.test.ts --exclude test/legacy/** --testNamePattern login
Use the .only
modifier to run only certain test suites or cases.
For example, only the test cases in suite A
and case A
will be run:
Use .skip
or .todo
to skip certain test suites or cases.