Reputation: 378
I'm using istanbul to know what lines of code were executed when I perform an operation on my web app. In order to do this I first instrumented the code using: npx nyc instrument
Then I deployed this code and did my testing. This generated a __coverage__ global object that I have copied into ./.nyc_output/coverage.json
To get the code coverage report, I tried npx nyc report --reporter=html --report-dir=./coverage
However on opening the resultant html file, I see it's empty:
What can I do to fix this?
Upvotes: 2
Views: 445
Reputation: 1471
I had a similar issue and it was due to Nyc options: In a monorepo
I was trying to get the coverage of files from another package.
- monorepo
- apps
- package_1
- node webapp.js (using the content instrumented of package_2 )
- package_2
- dist
- build.js (instrumented with Istambul)
The first thing to check is that the .json
files in .nyc_output
have the expected coverage content.
If it is, you may move the cwd
entry of Nyc options like me:
// monorepo/apps/package_1/nyc.config.js
export default {
cwd: `${process.cwd()}/../../`, // targetting the monorepo root
reportDir: `${process.cwd()}/coverage/backend`,
tempDir: `${process.cwd()}/.nyc_output`,
}
// process.cwd() is monorepo/apps/package_1
Then nyc report
worked like a charm
Upvotes: 0