include
- 类型:
string[]
- 默认值:
['**/*.{test,spec}.?(c|m)[jt]s?(x)']
- CLI:
--include '**/*.test.ts' --include '**/*.spec.ts'
匹配 glob 规则的文件将被视为测试文件。这些规则会相对于 root 解析(默认是 process.cwd())。
import { defineConfig } from '@rstest/core';
export default defineConfig({
include: ['**/*.{test,spec}.?(c|m)[jt]s?(x)'],
});
你可以运行 npx rstest list --filesOnly 来查看 Rstest 会包含的测试文件列表。
$ npx rstest list --filesOnly
# the output is shown below:
a.test.ts
b.test.ts
默认行为
默认情况下,Rstest 会匹配当前项目下所有文件名带有 .test. 或 .spec. 中缀的 JavaScript / TypeScript 文件。
下面是默认匹配模式的示例:
├── __tests__
│ └── index.test.js # test
│ └── App.spec.tsx # test
│ └── helper.ts # not test
├── src
│ └── component.ts # not test
│ └── component.test.tsx # test
├── bar.spec.jsx # test
├── index.test.js # test
└── index.js # not test
需要注意的是,如果你将 include 配置为 index.test.ts,Rstest 只会匹配根目录下的 index.test.ts。如果要匹配所有子目录中的 index.test.ts,需要使用 **/index.test.ts。
import { defineConfig } from '@rstest/core';
export default defineConfig({
- include: ['index.test.ts'],
+ include: ['**/index.test.ts'],
});