You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
240
242
241
-
按文件检查覆盖率阈值。
243
+
<!-- eslint-skip -->
244
+
```ts
245
+
{
246
+
coverage: {
247
+
thresholds: {
248
+
lines: 80,
249
+
functions: 80,
250
+
branches: 80,
251
+
statements: 80,
252
+
perFile: {
253
+
lines: 50,
254
+
functions: 50,
255
+
branches: 50,
256
+
statements: 50,
257
+
},
258
+
}
259
+
}
260
+
}
261
+
```
262
+
263
+
`{ 100: true }` is also accepted inside the object as a shortcut for setting all four metrics to `100`:
264
+
265
+
<!-- eslint-skip -->
266
+
```ts
267
+
{
268
+
coverage: {
269
+
thresholds: {
270
+
lines: 80,
271
+
perFile: {
272
+
100: true,
273
+
},
274
+
}
275
+
}
276
+
}
277
+
```
278
+
279
+
`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.
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.
检查每个文件的阈值。 `--coverage.thresholds.lines`, `--coverage.thresholds.functions`, `--coverage.thresholds.branches`, `--coverage.thresholds.statements` 为实际阈值(默认值:`false`)。Object form is available in config files only.
### 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
+
exportdefaultdefineConfig({
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
+
128
149
### Config Files Are Not Looked Up From Parent Directories
129
150
130
151
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