includeSource
- Type:
string[] - Default:
[]
Glob patterns for files that contain in-source tests alongside source code, similar to Rust's module tests. Patterns are resolved relative to root and respect exclude.
In-source testing suits small utilities that benefit from living next to their implementation. Use dedicated test files for larger modules or suites with complex setup.
includeSource works in both Node mode and Browser Mode projects.
Writing in-source tests
Rstest scans files matching includeSource and runs only the ones that reference import.meta.rstest, which exposes the Rstest test API (it, test, describe, expect, and hooks):
For production
Keep test code inside an if (import.meta.rstest) block. In production builds, define import.meta.rstest as false so the bundler tree-shakes the test block as dead code:
- With Rspack's DefinePlugin:
- With Rsbuild's source.define:
TypeScript
Add @rstest/core/importMeta to compilerOptions.types in your tsconfig.json for import.meta.rstest type definitions:
If
compilerOptions.typesis already set, append@rstest/core/importMetato the array.
Alternatively, add a triple-slash reference in an ambient declaration file: