CLI
Rstest comes with a lightweight CLI that includes commands such as rstest watch and rstest run.
rstest -h
rstest -h displays all available CLI commands and options:
Use npx rstest <command> -h to see command-specific options. For example, npx rstest init -h only shows initialization options, while npx rstest merge-reports -h only shows merge-related options.
rstest [...filters]
Running rstest without a subcommand runs tests in the current directory:
See Filtering tests for positional filters, exact path matching, and test-name filtering.
Watch mode
To rerun tests automatically when files change, pass --watch or run rstest watch:
rstest run
rstest run performs a single test run without watching for file changes, suitable for CI environments and one-off checks.
Run related tests
Use --related to treat positional arguments as source files and run only the tests that depend on those files:
Rstest resolves related tests from the build module graph, so the same filter works for Node mode and Browser Mode projects. You can also use the Jest-compatible alias:
Compilation errors in files unrelated to the requested source do not fail --related or --changed. If a test file itself fails to compile, Rstest cannot analyze its dependencies, so it may be missed by the selection and a warning is printed. passWithNoTests only permits an empty selection.
To inspect the affected test files without running them, combine --related with rstest list:
--related and --findRelatedTests are not supported in watch mode, which already reruns tests affected by file changes.
Run changed tests
Use --changed to collect changed files from the current Git repository and run the tests related to those files. By default, it includes unstaged, staged, and untracked files:
You can also pass a commit or branch. Rstest includes files changed between that ref and HEAD, plus local staged, unstaged, and untracked files:
When a changed file matches forceRerunTriggers, Rstest runs the whole test suite instead of only related tests.
When coverage is enabled and coverage.changed is not configured, --changed also limits coverage reports to changed source files. If a changed file matches forceRerunTriggers, Rstest runs the whole test suite and reports full coverage unless coverage.changed is explicitly enabled.
Use rstest list to preview which tests would run without executing them:
--changed cannot be combined with positional filters or --related / --findRelatedTests, because it already provides the source-file filter from Git state. It is not supported in watch mode either.
Test selection limitations
--related and --changed use dependencies found during the build to select tests. They do not run your tests to discover which files are loaded. The following cases can cause tests to be missed:
- Computed imports in Node mode. Requests such as
import(`./shipping/${method}.mjs`),require(`./shipping/${method}.cjs`), orimport(modulePath)are not tracked reliably. Changing the loaded file, or a file it depends on, may not select the test, even when the directory is written directly in the request. - Files referenced only by
require.resolve(). Callingrequire.resolve('./provider.cjs')does not establish a tracked dependency onprovider.cjs. Changes to that file may not select the test. - Files read or loaded outside the build. Examples include files read with
fs.readFile(), modules loaded through custom Node loading hooks, and dependencies inside files excluded from parsing withnoParse. - Deleted files.
--changedcurrently excludes staged and committed deletions. Even when a deleted path is passed to--related, the build may no longer contain enough information to find its tests.
Rstest does not automatically run all tests when these dependencies are missing, and a warning is not guaranteed. Use npx rstest run for a full test run in these cases. For files read or loaded outside the build, forceRerunTriggers can make --changed run the full suite when it detects a matching file change.
Run a shard
Use --shard <index>/<count> to split test files into several shards for parallel execution. count is the total number of shards and index (1-based) is the shard to run:
In CI/CD, you can split the suite across jobs to reduce total run time, then merge the per-shard reports with rstest merge-reports.
Test files are sorted by the SHA-1 hash of their path relative to the root of the Rstest run, with path separators normalized to /. This spreads files from the same directory across shards while keeping the result consistent across runs and checkout locations. Sharding happens during test-file scanning, before the build. Make sure 1 <= index <= count.
Files are distributed evenly across shards, with any remainder assigned one file at a time to the first shards. For example, 10 files split into 3 shards produce 4, 3, and 3 files, respectively.
rstest watch
rstest watch runs tests in watch mode and reruns affected test files when test files or their dependencies change.
If you set Rspack's watchOptions.ignored to a function, that function controls all watch exclusions. When dev.writeToDisk is enabled, return true for the build output directory and its contents so writing build artifacts does not trigger another compilation.
rstest list
rstest list prints matching tests without executing them. By default, it prints the full name of each matching test:
rstest list inherits Rstest's filtering options (except -f, --onlyFailures), so you can filter files directly or use -t to match test names:
Use --filesOnly to print only the matching test file paths:
Use --json to print tests as JSON or write the output to a file:
In Browser Mode, rstest list evaluates test files in each selected browser instance without running test bodies. With --filesOnly, it lists each matching file once per selected instance without launching browsers. When a project selects multiple instances, --json identifies each by its instance project name, such as web (chromium) or web (firefox).
Use --includeSuites to include test suites alongside test cases:
Use --printLocation to include file paths and line/column locations:
Use --summary to append a compact summary after the list output:
When used with --json, --summary changes the JSON output shape from an array to an object with items and summary fields.
rstest merge-reports
rstest merge-reports merges blob reports generated by multiple test shards into a unified report when running tests across CI machines with --shard.
Workflow
- Run each shard with the
blobreporter to generate blob report files:
- Collect all
.rstest-reports/directories into a single location, then merge:
By default, blob reports are read from .rstest-reports/ in the project root. You can specify a custom path:
The merge command will:
- Combine test results from all blobs
- Run configured reporters (e.g.,
default,junit) with the merged data - Merge the coverage collected by all blob-producing runs (if coverage is enabled)
- Apply
coverage.includeonce to add files that none of those runs tested - Generate coverage reports and check thresholds against the unified result
With coverage providers that support deferred finalization, runs using the blob reporter skip coverage report generation and threshold checks. Runs without the blob reporter finalize coverage normally, including sharded runs. Older providers retain their existing per-run finalization behavior. Enable coverage for merge-reports through your configuration or the --coverage flag so the merge job can finalize coverage. merge-reports accepts the same --coverage.* options as rstest run. Coverage options passed only to a blob-producing run are not stored in its blob, so define finalization options such as coverage.include, coverage.reporters, and coverage.reportsDirectory in the configuration file or repeat them on merge-reports.
Use --cleanup to remove the blob report inputs after merging. The directory is also removed when it becomes empty. If coverage.reportsDirectory is the blob directory or one of its subdirectories, generated coverage reports and their containing directory are retained:
rstest init
rstest init creates starter configuration for supported project types:
Currently, browser is the available initializer:
Use --yes to skip the interactive prompt and apply the default setup:
CLI options
Rstest CLI options are registered per command rather than shared globally across every command.
Test commands
rstest, rstest run, and rstest watch share the same test runtime options, except --related, --findRelatedTests, --changed, and --shard, which are rejected in watch mode:
rstest also supports -w, --watch, which switches the default command into watch mode.
rstest list
rstest list supports the same options as the test commands above except -f, --onlyFailures, and adds:
rstest merge-reports
rstest merge-reports shares -h/--help, -c/--config, --config-loader, -r/--root, --reporters, --coverage, and --coverage.* flags with Test commands, and adds:
rstest init
rstest init only accepts initialization-specific options:
Boolean option negation
For boolean options, prefix --no- to set them to false:
CLI shortcuts
In watch mode on an interactive TTY, press h to print the available keyboard shortcuts:
Press h at any time to display this shortcut list.
CLI shortcuts are only available when running Rstest in watch mode (rstest watch or rstest --watch) and when stdin is an interactive TTY.