Skip to content

Commit 9e4ac7b

Browse files
committed
docs(en): merging all conflicts
2 parents 287d45f + 89a0dbd commit 9e4ac7b

3 files changed

Lines changed: 111 additions & 0 deletions

File tree

config/coverage.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,76 @@ npx vitest --coverage.enabled --coverage.provider=istanbul
233233

234234
### coverage.thresholds.perFile
235235

236+
<<<<<<< HEAD
236237
- **类型:** `boolean`
237238
- **默认值:** `false`
238239
- **可用的测试提供者:** `'v8' | 'istanbul'`
239240
- **命令行终端:** `--coverage.thresholds.perFile`, `--coverage.thresholds.perFile=false`
240241

241242
按文件检查覆盖率阈值。
243+
=======
244+
- **Type:** `boolean | { 100?: boolean, lines?: number, functions?: number, branches?: number, statements?: number }`
245+
- **Default:** `false`
246+
- **Available for providers:** `'v8' | 'istanbul'`
247+
- **CLI:** `--coverage.thresholds.perFile`, `--coverage.thresholds.perFile=false`
248+
249+
When `true`, each file is checked against the top-level thresholds instead of the project-wide aggregate. When set to an object, both are checked: the aggregate against the top-level thresholds, and every file against these per-file minimums.
250+
251+
<!-- eslint-skip -->
252+
```ts
253+
{
254+
coverage: {
255+
thresholds: {
256+
lines: 80,
257+
functions: 80,
258+
branches: 80,
259+
statements: 80,
260+
perFile: {
261+
lines: 50,
262+
functions: 50,
263+
branches: 50,
264+
statements: 50,
265+
},
266+
}
267+
}
268+
}
269+
```
270+
271+
`{ 100: true }` is also accepted inside the object as a shortcut for setting all four metrics to `100`:
272+
273+
<!-- eslint-skip -->
274+
```ts
275+
{
276+
coverage: {
277+
thresholds: {
278+
lines: 80,
279+
perFile: {
280+
100: true,
281+
},
282+
}
283+
}
284+
}
285+
```
286+
287+
`perFile` can also be set on an individual [glob-pattern threshold](/config/coverage#coverage-thresholds-glob-pattern). Glob patterns do **not** inherit the top-level `perFile`; set it on each glob explicitly.
288+
289+
<!-- eslint-skip -->
290+
```ts
291+
{
292+
coverage: {
293+
thresholds: {
294+
perFile: true,
295+
lines: 80,
296+
297+
'src/utils/**': {
298+
lines: 90,
299+
perFile: true,
300+
},
301+
}
302+
}
303+
}
304+
```
305+
>>>>>>> 89a0dbd2c3f2002cd2061b660fc7d0bd480e98eb
242306
243307
### coverage.thresholds.autoUpdate
244308

@@ -257,9 +321,12 @@ npx vitest --coverage.enabled --coverage.provider=istanbul
257321
{
258322
coverage: {
259323
thresholds: {
324+
<<<<<<< HEAD
260325
// 更新阈值为整数
261326
autoUpdate: (newThreshold) => Math.floor(newThreshold),
262327

328+
=======
329+
>>>>>>> 89a0dbd2c3f2002cd2061b660fc7d0bd480e98eb
263330
// Log the change and update without decimals
264331
autoUpdate: (newThreshold, previousThreshold) => {
265332
console.log(`Updated threshold from ${previousThreshold} to ${newThreshold}`)
@@ -285,15 +352,29 @@ npx vitest --coverage.enabled --coverage.provider=istanbul
285352

286353
### coverage.thresholds[glob-pattern]
287354

355+
<<<<<<< HEAD
288356
- **类型:** `{ statements?: number functions?: number branches?: number lines?: number }`
289357
- **默认值:** `undefined`
290358
- **可用的测试提供者:** `'v8' | 'istanbul'`
359+
=======
360+
- **Type:** `{ statements?: number, functions?: number, branches?: number, lines?: number, perFile?: boolean | object }`
361+
- **Default:** `undefined`
362+
- **Available for providers:** `'v8' | 'istanbul'`
363+
>>>>>>> 89a0dbd2c3f2002cd2061b660fc7d0bd480e98eb
291364
292365
设置与 glob 模式匹配的文件的阈值。
293366

367+
<<<<<<< HEAD
294368
::: tip 注意
295369
Vitest 会将所有文件(包括匹配 glob 模式的文件)计入全局覆盖率阈值计算。
296370
此做法与 Jest 不同。
371+
=======
372+
Each glob pattern can set its own `perFile` (`boolean | object`), checked exactly like the top-level `perFile` but scoped to the matched files. Glob patterns do not inherit the top-level `perFile` — set it per glob.
373+
374+
::: tip NOTE
375+
Vitest counts all files, including those covered by glob-patterns, into the global coverage thresholds.
376+
This is different from Jest behavior.
377+
>>>>>>> 89a0dbd2c3f2002cd2061b660fc7d0bd480e98eb
297378
:::
298379

299380
<!-- eslint-skip -->
@@ -311,6 +392,8 @@ Vitest 会将所有文件(包括匹配 glob 模式的文件)计入全局覆
311392
functions: 90,
312393
branches: 85,
313394
lines: 80,
395+
// each matching file must individually hit the thresholds above
396+
perFile: true,
314397
},
315398

316399
// 匹配此模式的文件仅设置行覆盖率阈值

guide/cli-generated.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,17 @@ Coverage reporters to use. Visit [`coverage.reporter`](/config/coverage#coverage
197197

198198
### coverage.thresholds.perFile
199199

200+
<<<<<<< HEAD
200201
- **命令行终端:** `--coverage.thresholds.perFile`
201202
- **配置:** [coverage.thresholds.perFile](/config/coverage#coverage-thresholds-perfile)
202203

203204
检查每个文件的阈值。 `--coverage.thresholds.lines`, `--coverage.thresholds.functions`, `--coverage.thresholds.branches`, `--coverage.thresholds.statements` 为实际阈值(默认值:`false`
205+
=======
206+
- **CLI:** `--coverage.thresholds.perFile <boolean>`
207+
- **Config:** [coverage.thresholds.perFile](/config/coverage#coverage-thresholds-perfile)
208+
209+
Check thresholds per file. See `--coverage.thresholds.lines`, `--coverage.thresholds.functions`, `--coverage.thresholds.branches` and `--coverage.thresholds.statements` for the actual thresholds (default: `false`). Object form is available in config files only.
210+
>>>>>>> 89a0dbd2c3f2002cd2061b660fc7d0bd480e98eb
204211
205212
### coverage.thresholds.autoUpdate
206213

guide/migration.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,27 @@ await expect.element(banner).toMatchTextContent(/error/i) // [!code ++]
125125
await expect.element(banner).toHaveTextContent('Error!')
126126
```
127127

128+
### Glob Coverage Thresholds No Longer Inherit `perFile`
129+
130+
`coverage.thresholds.perFile` previously applied to every threshold set, including files matched by glob-pattern thresholds. Glob patterns now control their own per-file checking and no longer inherit the top-level `perFile` — set `perFile` on each glob that needs it.
131+
132+
```ts [vitest.config.ts]
133+
export default defineConfig({
134+
test: {
135+
coverage: {
136+
thresholds: {
137+
'perFile': true,
138+
139+
'src/utils/**': {
140+
lines: 80,
141+
perFile: true, // [!code ++]
142+
},
143+
},
144+
},
145+
},
146+
})
147+
```
148+
128149
### Config Files Are Not Looked Up From Parent Directories
129150

130151
Vitest no longer searches parent directories for config files. If you previously relied on running `vitest` from a subdirectory while using a config file from a parent directory, pass the config explicitly and scope test discovery with `--dir`. For example,

0 commit comments

Comments
 (0)