Skip to content

Commit bc58899

Browse files
authored
docs: clarify single-value include glob behavior (#1100)
1 parent 2d44633 commit bc58899

File tree

5 files changed

+18
-0
lines changed

5 files changed

+18
-0
lines changed

packages/core/tests/coverage/include.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ describe('getIncludedFiles', () => {
9494
expect(await glob(['**/*.d.ts'])).toMatchInlineSnapshot('[]');
9595
});
9696

97+
it('should not treat single-value braces as an extension alternation', async () => {
98+
expect(await glob(['**/*.{ts}'])).toMatchInlineSnapshot('[]');
99+
expect(await glob(['**/*.ts'])).toMatchInlineSnapshot(`
100+
[
101+
"apps/a.ts",
102+
"apps/dist/a.ts",
103+
]
104+
`);
105+
});
106+
97107
it('should exclude test and spec files by default', async () => {
98108
expect(await glob(['**/*.{test,spec}.*'])).toMatchInlineSnapshot('[]');
99109
});

website/docs/en/config/test/coverage.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ A list of glob patterns that should be included for coverage collection.
110110

111111
By default, rstest will only collect coverage for files that are tested. If you want to include untested files in the coverage report, you can use the `include` option to specify the files or patterns to include.
112112

113+
Note that you should use standard glob syntax here. For a single extension, write `src/**/*.ts` instead of `src/**/*.{ts}`. Single-value braces are treated literally by the underlying glob libraries, so `src/**/*.{ts}` will not match `.ts` files.
114+
113115
```ts title='rstest.config.ts'
114116
import { defineConfig } from '@rstest/core';
115117

website/docs/en/config/test/include.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,5 @@ export default defineConfig({
6868
+ include: ['**/index.test.ts'],
6969
});
7070
```
71+
72+
It should be noted that for a single extension you should write `**/*.ts` instead of `**/*.{ts}`. The underlying glob libraries treat single-value braces literally, so `**/*.{ts}` will not match `.ts` files.

website/docs/zh/config/test/coverage.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ import { PackageManagerTabs } from '@theme';
110110

111111
默认情况下,Rstest 会收集已测试文件的覆盖率。如果你希望在覆盖率报告中包含未测试的文件,可以使用 `include` 选项指定要包含的文件或模式。
112112

113+
需要注意的是,这里应使用标准 glob 语法。匹配单个扩展名时,请写 `src/**/*.ts`,不要写 `src/**/*.{ts}`。底层 glob 库会把单元素花括号按字面量处理,因此 `src/**/*.{ts}` 不会匹配 `.ts` 文件。
114+
113115
```ts title='rstest.config.ts'
114116
import { defineConfig } from '@rstest/core';
115117

website/docs/zh/config/test/include.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,5 @@ export default defineConfig({
6868
+ include: ['**/index.test.ts'],
6969
});
7070
```
71+
72+
需要注意的是,单个扩展名应直接写成 `**/*.ts`,不要写成 `**/*.{ts}`。底层 glob 库会把单元素花括号按字面量处理,因此 `**/*.{ts}` 不会匹配 `.ts` 文件。

0 commit comments

Comments
 (0)