Repository navigation
Description
Clear and concise description of the problem
Currently, Vitest forces users to choose between global coverage thresholds and per-file thresholds (perFile: true). It is not possible to enforce both simultaneously in a single test run.
In many real-world projects, teams want to maintain a high overall project coverage (e.g., 80% global average) while simultaneously ensuring that no individual file drops below a certain absolute minimum baseline (e.g., 50% per-file).
Right now, if we use global thresholds, a single file can have 0% coverage as long as the overall average is high enough. If we use perFile: true with 50%, we completely lose the 80% global project requirement. Relying solely on glob patterns grouping doesn't solve this, as it evaluates the grouped files as a whole, not iteratively per file alongside a global check.
Suggested solution
Introduce a way to define global thresholds and per-file minimums at the same time within the coverage.thresholds options.
A clean approach could be allowing the perFile property to accept an object of thresholds instead of just a boolean, or introducing a dedicated perFileThresholds key.
Example of how the API could look:
export default defineConfig({
test: {
coverage: {
thresholds: {
// Global project thresholds (Must be met on average)
lines: 80,
functions: 80,
branches: 80,
statements: 80,
// Absolute minimums (No individual file is allowed to drop below this)
perFile: {
lines: 50,
functions: 50,
branches: 50,
statements: 50
}
}
}
}
})Alternative
No response
Additional context
It is worth noting that this dual-threshold behavior was fully supported in Karma. With the Angular ecosystem currently shifting away from Karma and moving towards Vitest as the recommended testing framework, many teams are migrating their test setups. During this migration, developers are losing this specific quality gate. Supporting this feature in Vitest would bring important feature parity and significantly ease the transition for the Angular community.
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that requests the same feature to avoid creating a duplicate.
Activity
feat(coverage): allow thresholds.perFile to accept an object
feat(coverage): allow thresholds.perFile to accept an object