Skip to content

coverage-v8: Duplicate statements when merging coverage from multiple projects with different environments #9366

@stevez

Description

@stevez

Describe the bug

When using vitest's projects configuration with multiple environments (e.g., jsdom for unit tests and browser for component tests), files that are covered by both projects get duplicate coverage entries, resulting in inflated statement/function/branch counts.

For example, a file with 15 statements is reported as having 29 statements in the combined coverage report.

Reproduction

Repository: https://github.com/stevez/restaurant-reviews-platform
Branch: test/vitest-coverage-bug

Steps:

  1. Clone the repo and checkout the branch
    git clone https://github.com/stevez/restaurant-reviews-platform
    cd restaurant-reviews-platform
    git checkout test/vitest-coverage-bug

Run npm install
Run npx vitest --coverage
Check coverage for src/lib/constants.ts - it shows 29 statements instead of 15

System Info

System: OS: Windows 11 Node: v22.x Packages: vitest: 4.0.x @vitest/coverage-v8: 4.0.x

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions