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

Getting coverage numbers on blank lines when using c8 and mocha #390

Closed
drazisil opened this issue Apr 16, 2022 · 4 comments
Closed

Getting coverage numbers on blank lines when using c8 and mocha #390

drazisil opened this issue Apr 16, 2022 · 4 comments
Labels

Comments

@drazisil
Copy link

  • Version: v16.14.0 (using volta, in case that matters, will be hard for me to test without it, but I don't think it should matter)
  • Platform: Linux banana 5.15.25-1-MANJARO #1 SMP PREEMPT Wed Feb 23 14:44:03 UTC 2022 x86_64 GNU/Linux

When running c8 mocha in a repository, c8 is reporting coverage on all lines that are not code.

Example repo: https://github.com/drazisil/c8-test

Coverage with c8: (npm run)

----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
----------|---------|----------|---------|---------|-------------------
All files |   63.63 |      100 |       0 |   63.63 |                   
 index.js |   63.63 |      100 |       0 |   63.63 | 3-4,9-10          
----------|---------|----------|---------|---------|-------------------

Expected coverage with nyc: (npx nyc --all mocha)

----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
----------|---------|----------|---------|---------|-------------------
All files |       0 |      100 |       0 |       0 |                   
 index.js |       0 |      100 |       0 |       0 | 3-9               
----------|---------|----------|---------|---------|-------------------

Is this expected behavior? Does the very act of importing file cause the entire file to be considered covered, unless proven otherwise? My apologies if I missed an existing image, or docs regarding this.

Please let me know if I can provide any further help.

@drazisil
Copy link
Author

Might be a duplicate of #34, I'm having trouble following that.

@drazisil
Copy link
Author

Maybe also a duplicate of #244

The difference here is I'm using pure ESM with no transpiling.

@bcoe bcoe added the bug label Apr 20, 2022
@bcoe
Copy link
Owner

bcoe commented May 15, 2022

@drazisil I believe that this is expected behavior. V8 sees the classes themselves as having been covered, but as you do not call the constructor for either class, they will both not have been called.

Importing a file causes it to be executed (this is actually similar behavior to nyc, it's how you'd collect coverage for a script). The major reason for the discrepancy between c8/nyc, is that nyc doesn't properly parse ESM.

@drazisil
Copy link
Author

Thanks, @bcoe that makes sense.

@drazisil-codecov, @mitchell-codecov let's lets discuss tomorrow if this is similar to what we are seeing with xcode/lcov. It feels similar.

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

No branches or pull requests

2 participants