Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable ignoring line patterns #398

Open
tqn-treezor opened this issue May 6, 2022 · 4 comments
Open

Enable ignoring line patterns #398

tqn-treezor opened this issue May 6, 2022 · 4 comments

Comments

@tqn-treezor
Copy link

  • Version: v16.13.1
  • Platform: Darwin MacbookPro.local 21.2.0 Darwin Kernel Version 21.2.0: Sun Nov 28 20:28:41 PST 2021; root:xnu-8019.61.5~1/RELEASE_ARM64_T6000 arm64

I am transitioning from Jest to Vitest, which uses C8 to generate the coverage report.
I noticed a huge difference (x3 factor) in coverage between Jest and Vitest, explained by 3 things:

  • Jest ignores import lines by default, Vitest (C8) doesn't
  • Jest ignores all comments by default, Vitest doesn't
  • Multiple lines object are considered as one line by Jest, and are considered as many lines as there is by Vitest

Example with Vitest (C8):
image

Example with Jest:
image

Since I suppose c8 wants to remain unopinionated, I suppose it would be best to give the option to the c8 user to choose if he wants to ignore import / require lines or not, comments or not, and to count multiple line objects as one line or not.

Is it possible to add an option to c8 to do that?

@tqn-treezor
Copy link
Author

It kind of relates to that, on the possibility to ignore comments, by the way: #182

@bcoe
Copy link
Owner

bcoe commented May 15, 2022

With regards to import/require, the problem is that these constructs can be fairly complex, and take up multiple lines. Unlike Istanbul, c8 doesn't actually create an AST of the source code that's being covered (so doesn't know what constructs are being covered or uncovered).

The above is true of comments as well, although it might be easier to come up with a heuristic for comments.

I guess, ultimately my question is, if imports and comments tend to be 100% covered, since they're executed by default, what's the problem with them showing up as covered, vs., them showing as ignored in the report?

If it's mostly an aesthetic difference, I question whether it's worth adding to the complexity of c8 to address the problem.

@tqn-treezor
Copy link
Author

The problem with comments being 100% covered means that if I decide one day to comment my code, my code coverage will increase when it should not.
Obviously same goes for imports. The more I import useless things, the more coverage I'll get, since a < b implies (a + n) / (b + n) > a / b.

@AriPerkkio
Copy link
Contributor

I am transitioning from Jest to Vitest, which uses C8 to generate the coverage report.

This is fixed in Vitest v1.6 and v2: vitest-dev/vitest#5457. It's no longer c8 related issue. For c8 there's also an upstream fix available: istanbuljs/v8-to-istanbul#244.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants