Search code examples
node.jstypescriptvisual-studio-codecode-coveragenyc

Why does nyc does not gather test coverage for my project?


I am developing an extension for vscode using typescript. I set up a GitHub Action which is executing my test cases. To gather the test coverage I am using nyc.

These are my node scripts:

"compile": "tsc -p ./",
"test": "npm run compile && node ./out/test/runTest.js",
"coverage": "nyc npm run test"

When I run npm run coverage I see all my test cases are getting executed (they are not stored in the file runTest.js), but only the coverage for the test file runTest.js is gathered. The relevant classes lib.ts and extension.ts are not shown in the coverage.

Why is this so? What am I doing wrong?

See my package.json and .nycrc.json for configuration.


Solution

  • I could fix this problem by sticking to the great blogpost which I found posted on a similar Question.

    The problem is, that NYC is a command line tool. When executing the test I focused on my configuration in the .nycrc file. Fact is, that the visual studio code test runner is not using this configuration and has to be configured inside the test runner.

    I fixed the broken test coverage generation inside this commit.