istanbuljs / nyc

the Istanbul command line interface
https://istanbul.js.org/
ISC License
5.59k stars 359 forks source link

Why is nyc coverage with typescript (using mocha) returning zero coverage #1520

Open yinonby opened 1 year ago

yinonby commented 1 year ago

Link to bug demonstration repository

https://codesandbox.io/p/sandbox/xenodochial-babbage-jrwj0b

Expected Behavior

npm run coverage

I expect 100% coverage

Observed Behavior

npm run coverage

=============================== Coverage summary ===============================
Statements   : Unknown% ( 0/0 )
Branches     : Unknown% ( 0/0 )
Functions    : Unknown% ( 0/0 )
Lines        : Unknown% ( 0/0 )
================================================================================

Troubleshooting steps

Environment Information

# paste the output here
  Binaries:
    Node: 16.17.0 - F:\programs\nodejs\node.EXE
    npm: 8.15.0 - F:\programs\nodejs\npm.CMD
  npmPackages:
    nyc: ^15.1.0 => 15.1.0
    source-map-support: ^0.5.21 => 0.5.21
    ts-node: ^10.9.1 => 10.9.1
    typescript: ^5.0.4 => 5.0.4
kalpeshhpatel commented 1 year ago

@yinonby were you able to root cause the issue?

PhilHannent commented 1 year ago

I was watching this issue because I had the same problem. Switching to the c8 library solved the problem for me. My project was an ESM modules project, which seems to have teething problems in some projects.