Skip to content

Source map resolution difference between Istanbul and V8 coverage plugins #5341

@just-boris

Description

@just-boris

Describe the bug

In our project setup, we have a pre-processing step, so the test run against a lib folder instead of src. This causes differences in behavior between istanbul and v8 coverage providers.

When running tests with istanbul it follows the source maps and the resolves the file to the original index.ts source:

 % Coverage report from istanbul
----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files |     100 |      100 |     100 |     100 |
 index.ts |     100 |      100 |     100 |     100 |
----------|---------|----------|---------|---------|-------------------

But it does not happen with v8, the report shows transpiled index.js

 % Coverage report from v8
----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files |     100 |      100 |     100 |     100 |
 index.js |     100 |      100 |     100 |     100 |
----------|---------|----------|---------|---------|-------------------

This becomes an issue when uploading reports to tools like Codecov, because they cannot match up the coverage report against the source

Reproduction

Minimal repro can be found here: https://github.com/just-boris/vitest-coverage-issue-5341

System Info

System:
    OS: macOS 13.6.4
    CPU: (10) arm64 Apple M1 Pro
    Memory: 594.05 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.19.0 - ~/n/bin/node
    npm: 10.2.3 - ~/n/bin/npm
  Browsers:
    Chrome: 122.0.6261.94
    Edge: 122.0.2365.63
    Safari: 17.3.1
  npmPackages:
    @vitest/coverage-istanbul: ^1.3.1 => 1.3.1
    @vitest/coverage-v8: ^1.3.1 => 1.3.1
    vitest: ^1.3.1 => 1.3.1

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: coverageIssues and PRs related to the coverage featurep3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions