coverage
- Type:
- Default:
undefined
Collect code coverage and generate coverage reports.
Options
enabled
- Type:
boolean - Default:
false - CLI:
--coverage,--coverage=false,--no-coverage
Enable or disable test coverage collection.
provider
- Type:
'istanbul' - Default:
'istanbul'
The coverage provider to use. Currently, only istanbul is supported.
Istanbul provider
Istanbul is a widely used JavaScript code coverage tool that collects code coverage information through instrumentation.
To enable istanbul coverage, you need to install the @rstest/coverage-istanbul package first.
@rstest/coverage-istanbul is powered by swc-plugin-coverage-instrument.
include
- Type:
string[] - Default:
undefined
A list of glob patterns that should be included for coverage collection.
By default, rstest will only collect coverage for files that are tested. If you want to include untested files in the coverage report, you can use the include option to specify the files or patterns to include.
Note that you should use standard glob syntax here. For a single extension, write src/**/*.ts instead of src/**/*.{ts}. Single-value braces are treated literally by the underlying glob libraries, so src/**/*.{ts} will not match .ts files.
exclude
- Type:
string[] - Default:
A glob pattern array to exclude files from test coverage collection.
Any patterns specified here will be merged with default values.
reporters
- Type:
(ReporterName | [ReporterName, ReporterOptions>])[] - Default:
['text', 'html', 'clover', 'json']
The reporters to use for coverage collection. Each reporter can be either a string (the reporter name) or a tuple with the reporter name and its options.
- See Istanbul Reporters for available reporters.
- See @types/istanbul-reporter for details about reporter specific options.
reportsDirectory
- Type:
string - Default:
'./coverage'
The directory to store coverage reports.
reportOnFailure
- Type:
boolean - Default:
false
Whether to report coverage and check thresholds when tests fail.
allowExternal
- Type:
boolean - Default:
false - CLI:
--coverage.allowExternal
Whether to collect coverage for source files outside the project root directory. This is useful in monorepo setups where tests import modules from sibling packages.
By default, rstest excludes files outside the project root from coverage reports, which aligns with the behavior of Jest and Vitest.
clean
- Type:
boolean - Default:
true
Whether to clean the coverage directory before running tests.
thresholds
- Type:
- Default:
undefined
Coverage thresholds for enforcing minimum coverage requirements. You can set thresholds for statements, functions, branches, and lines.
Thresholds specified as a positive number are taken to be the minimum percentage required. Thresholds specified as a negative number represent the maximum number of uncovered entities allowed.
When the code coverage is below the specified thresholds, the test will fail and output an error message like below:
glob pattern
If globs are specified, thresholds will be checked for each matched file pattern. If the file specified by path is not found, an error is returned.
Following the above configuration, rstest will fail if:
- The total code coverage of all files in
src/**is below 100%. - The total code coverage of all files in
node/**/*.jsis below 90%. - The global code coverage is below 80% for statements.
check threshold for per file
Rstest also supports checking thresholds for each matched file by setting perFile to true.