Skip to content

Support combining global coverage thresholds with minimum per-file thresholds #10114

Description

@ermancekic

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

Activity

  1. added 2 commits that reference this issue on Apr 24, 2026
    f0fc07c
    0050d1a
  2. locked and limited conversation to collaborators on Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: coverageIssues and PRs related to the coverage featurep2-nice-to-haveNot breaking anything but nice to have (priority)

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions