include
- 类型:
string[] - 默认值:
['**/*.{test,spec}.?(c|m)[jt]s?(x)'] - CLI:
--include '**/*.test.ts' --include '**/*.spec.ts'
匹配测试文件的 glob 规则列表,相对于 root(默认为 process.cwd())解析。设置 include 会覆盖默认匹配规则。
运行 npx rstest list --filesOnly 可以查看实际匹配到的测试文件:
默认行为
默认情况下,Rstest 会匹配文件名中包含 .test. 或 .spec. 的 JavaScript / TypeScript 文件:
不含目录前缀的模式(如 index.test.ts)只会匹配根目录下的文件。需要匹配所有子目录时,使用 **/index.test.ts:
匹配单个扩展名时应写成 **/*.ts,不要写成 **/*.{ts}。底层 glob 库会把单元素花括号按字面量处理,**/*.{ts} 不会匹配 .ts 文件。