Filtering tests
Select which test files, projects, and test cases Rstest runs via CLI filters, configuration options, watch shortcuts, or test API modifiers.
Filter by file name
Run all tests:
Positional filters accept substrings, relative or absolute file paths, and directory paths (multiple filters match any of them):
Wrap a filter in quotes for exact whole-path matching (for example, to avoid matching foo.test.tsx when targeting foo.test.ts). Because the shell strips one layer of quotes, pass two layers:
Rstest does not parse positional filters as glob patterns. Use --include for glob patterns, quoted to prevent shell expansion:
include/exclude
Positional filters apply on top of the files matched by the include and exclude configuration. You can also override include and exclude from the CLI:
By default, Rstest exits with an error when no matching test files are found. Pass --passWithNoTests (or enable passWithNoTests in your config) to exit with code 0 instead.
Filter by test name
Use --testNamePattern (-t for short) or the testNamePattern config option to run only tests whose names match a string or regular expression.
Match by keyword
Pass a keyword to run any test case or suite whose name contains it. If a suite name matches, all tests inside that suite run:
Rstest compiles -t / testNamePattern into a single RegExp. When the pattern does not contain >, Rstest joins outer-to-inner suite names and the test name with a single space (suite-foo suite-bar test-baz). As a result, a space-separated string matches that exact consecutive sequence across suite and test boundaries:
To match non-adjacent keywords across nested suites, join them with .*:
Match by full test name
In terminal output, Rstest joins outer-to-inner suite names and the test case name with >. When a pattern contains >, Rstest matches against that >-delimited full name.
Consider the following test file and its output:
Output:
To run only the test-baz test directly inside suite-bar:
Match by regular expression
Because the pattern is evaluated as a regular expression, you can use anchors such as ^ and $ to match a full test name exactly instead of any substring match:
You can also set a RegExp directly in rstest.config.ts via testNamePattern, such as /^(?!.*slow).*$/ to exclude tests containing slow.
Filter by project name
In a multi-project workspace configured with projects, use --project to select projects by their name.
Match specific project names:
Match project names with * wildcards:
Exclude projects with a leading !:
Failed tests, changes, and shards
- Re-run failed test files: Pass
-for--onlyFailures(seeonlyFailures) to re-run only test files that failed in the previous full run. - Run tests related to source files: Pass
--related(or--findRelatedTests) with source file paths to run tests that depend on them; see Run related tests. - Run tests for Git changes: Pass
--changedto run tests affected by local or committed Git changes; see Run changed tests. - Split tests across CI jobs: Pass
--shard <index>/<count>to distribute test files across shards; see Sharding tests. - Interactive watch filtering: In watch mode, press
tto filter by test name pattern,pto filter by file filters,fto re-run failed files, orato clear active filters and re-run all tests; see CLI shortcuts.
Combined filtering
File, project, and test name filters can be combined:
This command runs only tests whose names contain login across .test.ts files under test/, excluding test/legacy/.
Filter via test API
Control which suites and test cases run directly in test code with test and describe modifiers:
.only: runs only the marked suites or test cases inside the current file (combine with a CLI file filter to isolate one file)..skip/.todo: skips suites or test cases, or marks them as todo..skipIf(condition)/.runIf(condition): conditionally skips or runs suites or test cases.context.skip(): skips a test dynamically during execution.