Skip to content

V8 Coverage: Exclude empty lines, comments, TS types #5423

@AriPerkkio

Description

@AriPerkkio

Clear and concise description of the problem

There's now a PR for improved v8 coverage remapping in v8-to-istanbul:

There are some coverage reports in the linked PR that show what kind of changes it would cause.

  • Comments are excluded (esbuild doesn't add comments in source maps, tsc does though)
  • Empty lines are excluded
  • Typescript typings are excluded (except enums that compile to actual runtime code)
  • HTML-like templates from transpiled languages like Svelte and Vue are excluded, as long as they don't contain code that those compilers consider (user's) runtime code.
  • Ignore hints (/* v8 ignore ... */) exclude the lines instead of marking them as covered. Exactly as istanbul-lib-instrument does.

Related issues:

Suggested solution

Typically PRs in istanbuljs organization take long time to land so we could apply the changes as pnpm patch and bundle v8-to-istanbul into @vitest/coverage-v8 package.

At first we might want to introduce this as opt-in coverage option and enable it by default in V2. The changes that this introduces can affect line coverage in such ways that projects using coverage.thresholds may now fail in CI - exactly as they should do. Line coverage is now more accurate as comments don't increase it.

Alternative

No response

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: coverageIssues and PRs related to the coverage featurep3-significantHigh priority enhancement (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions