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

No coverage for typescript compiled project #1210

Closed
repinvv opened this issue Oct 21, 2019 · 9 comments
Closed

No coverage for typescript compiled project #1210

repinvv opened this issue Oct 21, 2019 · 9 comments

Comments

@repinvv
Copy link

repinvv commented Oct 21, 2019

https://gist.github.com/repinvv/9440648d1f128dd9d144589e5be7d456

npm i
npm test

Expected Behavior

This is how it works with nyc@13.3
image

Observed Behavior

nyc@14
image

Environment Information

System:
OS: Windows 10
CPU: (8) x64 Intel(R) Core(TM) i5-8350U CPU @ 1.70GHz
Memory: 1.83 GB / 7.84 GB
Binaries:
Node: 12.11.1 - C:\Program Files\nodejs\node.EXE
npm: 6.11.3 - C:\Program Files\nodejs\npm.CMD

@repinvv
Copy link
Author

repinvv commented Oct 21, 2019

the same on another PC:
System:
OS: Linux 4.4 Ubuntu 18.04.1 LTS (Bionic Beaver)
CPU: (16) x64 AMD Ryzen 7 1700X Eight-Core Processor
Memory: 20.86 GB / 31.94 GB
Binaries:
Node: 12.0.0 - /usr/bin/node
npm: 6.9.0 - /usr/bin/npm
npmPackages:
nyc: ^14.1.1 => 14.1.1
typescript: ^3.6.4 => 3.6.4

@coreyfarrell
Copy link
Member

I think you need to remove the nyc include option and set "extension": [".ts"]. .js is automatically added to allow nyc to instrument the output of tsc but your current configuration is excluding the original source filename which causes it to be removed from the reports.

@repinvv
Copy link
Author

repinvv commented Oct 27, 2019

image
Still does not work. I expect to see 1 line add.ts and it has to be 100% covered.

Forgot to add, with nyc 13.3 it works, with 14.1.1 it fails.
But with 13.3 there is another issue now, which caused me to go upgrade.

@DavidSichau
Copy link

I experience the same behaviour that istanbul is only reporting 100% Branch coverage.

@rhysd
Copy link

rhysd commented Nov 25, 2019

I also ran into this issue with v14.1.1. Configuration was pretty simple:

  "nyc": {
    "extends": "@istanbuljs/nyc-config-typescript",
    "check-coverage": true
  }

in my package.json. v13.3 did not cause this issue as reported in this issue.

And after adding extension as follows, v14.1.1 now works fine for me:

  "nyc": {
    "extends": "@istanbuljs/nyc-config-typescript",
    "extension": [
      ".ts"
    ],
    "check-coverage": true
  }

EDIT:

It seems that this issue was already fixed on HEAD with this PR:

istanbuljs/istanbuljs@a01a2b8#diff-0f1bb8bd3767c66869730d250d7bb39f

It added extension to the config. But seems not published yet.

@coreyfarrell
Copy link
Member

@rhysd this is a known breaking change of 14.x. Changing the default extension list is also considered a breaking change for nyc so adding .ts to the defaults is part of nyc@15. You can get that version using npm i -D nyc@next, subscribe to #1104 for updates on progress towards the final release.

@repinvv I've had a moment to clone your gist. I recommend upgrading to nyc 15 which includes some fixes that apply to your project. After upgrading make changes to your nyc configuration:

  1. Set "cache": false
  2. Remove include and extension settings
  3. Change exclude to ["*.spec.*"]

@rhysd
Copy link

rhysd commented Nov 26, 2019

@coreyfarrell Thank you for the information. I'll wait for v15 keeping my configuration meantime.

@repinvv
Copy link
Author

repinvv commented Dec 1, 2019

yes, nyc@15 beta works for me. Needs a lot more specified in exclude section, but it works. I wonder if it does instrument more files than needed which might impact its performance, since I don't specify what to include anymore.

@coreyfarrell
Copy link
Member

As an alternative you could specify "include": ["*.js", "*.ts"] if you are worried about sub-directories potentially being included, otherwise the default extension list already restricts what can be included. Unless you have specific performance issues with the --all feature then I'd recommend not worrying about being more strict than you need to.

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

No branches or pull requests

4 participants