istanbuljs / nyc

the Istanbul command line interface

Home Page:https://istanbul.js.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

yinonby opened this issue · comments

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

  • Tried the following .nycrc config, and some subsets of it, following some other posts, nothing works:
"exclude-after-remap": false,
"exclude": [
    "*.test.*",
    "**/*.d.ts"
],
"extension": [
    ".js",
    ".jsx",
    ".ts",
    ".tsx"
],
"check-coverage": true,
"cache": false,
"all": false,
"source-map": true,
"produce-source-map": true,

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

@yinonby were you able to root cause the issue?

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.