bcoe/c8

Getting coverage numbers on blank lines when using c8 and mocha

Closed this issue · 4 comments

  • 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.

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

Maybe also a duplicate of #244

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

bcoe commented

@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.

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.