string[]
[]
In-source testing is where the test code lives within the same file as the source code, similar to Rust's module tests.
You can define a list of glob patterns that match your in-source test files via includeSource
configuration.
In-source testing is usually suitable for small functional functions and utilities, allowing for easy and rapid verification and debugging. For more complex functions and modules, independent test files are recommended.
When includeSource
defined, Rstest will run all matched files with import.meta.rstest
inside.
You can get the Rstest test API via import.meta.rstest
.
Put the test code inside the if (import.meta.rstest)
block, and define import.meta.rstest
as undefined
in your build configuration (e.g., rsbuild.config.ts
), which will help the bundler eliminate dead code.
To get TypeScript support for import.meta.rstest
, you should add @rstest/core/importMeta
to your tsconfig.json
: