Skip to content

Coverage: give the choice between c8 and nyc #1252

@tqn-treezor

Description

@tqn-treezor

Clear and concise description of the problem

I observed huge coverage gaps when transitioning from Jest to Vitest, the reason coming from C8 not ignoring a few things:

  • types.ts were ignored by default in Jest and not in Vitest
  • *.entity.ts were ignored by default in Jest and not in Vitest
  • *.test.ts were ignored by default in Jest and not in Vitest
  • For includes/excludes, Vitest takes absolute paths, Jest accepts relative paths (that may lead to include or exclude paths not working and giving erroneous results in your coverage)
  • Comments are ignored by default in Jest and not in Vitest
  • Import lines are ignored by default in Jest and not in Vitest
  • Objects spread in multiple lines are considered as one line in Jest, and as many lines as there is in Vitest

The "deep reason" seems that Jest uses nyc, and Vitest uses c8, and they don't have the same way of running through the code to make the coverage report.
Besides, the way c8 does it (not ignoring comments) seems objectively wrong, because adding comments in any covered branch in any file will actually increase the code coverage when it really shouldn't. Same for multiple line objects.

Suggested solution

Give the choice to use nyc instead of c8.

Alternative

Fix c8? There is actually an issue dating from 2019 talking about the comments counted as covered here: bcoe/c8#182

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestfeat: coverageIssues and PRs related to the coverage feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions