> For AI agents: the complete documentation index is available at /zh/llms.txt, the full documentation bundle is available at /zh/llms-full.txt.

# include

- **类型：** `string[]`
- **默认值：** `['**/*.{test,spec}.?(c|m)[jt]s?(x)']`
- **CLI：** `--include '**/*.test.ts' --include '**/*.spec.ts'`

匹配 glob 规则的文件将被视为测试文件。这些规则会相对于 [root](/zh/config/test/root.md) 解析（默认是 `process.cwd()`）。


**CLI**

```bash
npx rstest --include '**/*.{test,spec}.?(c|m)[jt]s?(x)'
```


**rstest.config.ts**

```ts
import { defineConfig } from '@rstest/core';

export default defineConfig({
  include: ['**/*.{test,spec}.?(c|m)[jt]s?(x)'],
});
```


你可以运行 `npx rstest list --filesOnly` 来查看 Rstest 会包含的测试文件列表。

```bash
$ npx rstest list --filesOnly

# the output is shown below:
a.test.ts
b.test.ts
```

## 默认行为

默认情况下，Rstest 会匹配当前项目下所有文件名带有 `.test.` 或 `.spec.` 中缀的 JavaScript / TypeScript 文件。

下面是默认匹配模式的示例：

```bash
├── __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`。

```diff
import { defineConfig } from '@rstest/core';

export default defineConfig({
-  include: ['index.test.ts'],
+  include: ['**/index.test.ts'],
});
```

需要注意的是，单个扩展名应直接写成 `**/*.ts`，不要写成 `**/*.{ts}`。底层 glob 库会把单元素花括号按字面量处理，因此 `**/*.{ts}` 不会匹配 `.ts` 文件。
