istanbuljs / nyc

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

Reporting zero coverage for *.js file where as *.ts file coverage shows 100% #1408

Open vellala2000 opened 3 years ago

vellala2000 commented 3 years ago

Link to bug demonstration repository

https://github.com/vellala2000/nyc-bug-demo

Expected Behavior

Some level of coverage for logger.js file with 'npm run jscoverage' image

Observed Behavior

0% coverage for logger.js file. image

Troubleshooting steps

Environment Information

npx: installed 1 in 2.284s

  System:
    OS: Windows 10 10.0.18363
    CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
    Memory: 10.71 GB / 31.52 GB
  Binaries:
    Node: 14.16.1 - C:\Program Files\nodejs\node.EXE
    npm: 6.14.12 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    nyc: ^15.1.0 => 15.1.0
    source-map-support: ^0.5.19 => 0.5.19
    ts-node: 8.10.1 => 8.10.1
    typescript: 4.2.4 => 4.2.4
ssube commented 3 years ago

I am seeing a similar or identical issue. It occurs when including the typescript config preset, and removing that from my package.json seems to fix the coverage.

With the nyc config stanza like so:

  "nyc": {
    "cache": false,
    "branches": 10,
    "lines": 10,
    "functions": 10,
    "statements": 10
  }

I see the expected coverage:

Statements   : 43.18% ( 620/1436 )
Branches     : 40.98% ( 159/388 )
Functions    : 45.61% ( 161/353 )
Lines        : 42.99% ( 595/1384 )

Adding the preset, with or without the additional cache key, immediately brings coverage down by about (but not exactly) half:

Statements   : 20.3% ( 288/1419 )
Branches     : 9.52% ( 36/378 )
Functions    : 22.7% ( 79/348 )
Lines        : 19.39% ( 265/1367 )

With the following in package.json:

  "nyc": {
    "extends": "@istanbuljs/nyc-config-typescript",
    "branches": 10,
    "lines": 10,
    "functions": 10,
    "statements": 10
  }

As far as I can tell, the preset only defines cache and parserPlugins (https://github.com/istanbuljs/istanbuljs/blob/master/packages/nyc-config-typescript/index.js), and changing cache in my package.json does not seem to make a difference. I have tried running with an existing out/ dir and cleaning beforehand, same results. I don't have a MVCE, but building https://github.com/ssube/textual-engine with make cover in a codespace/gitpod should demonstrate the issue.