nyc
nyc copied to clipboard
Generate report from a JSON file merged from `nyc merge`
I have multiple coverage results from different types of tests (regression tests: node processes instrumented by nyc, jest tests: can produce coverage json results). I run nyc merge
to merge all the .json
results in one coverage.json
file. Now I want to produce an HTML&text report from that merged .json
file.
After trying multiple nyc commands to produce the report from JSON with no luck, I found an interesting behavior of nyc: You have to be in the parent directory of the instrumented code when you are generating a report. For example:
If the code I instrumented is in /usr/share/node/**
, and the merged coverage.json
result is in /tmp
directory. If I run nyc report --temp-dir=/tmp --reporter=text
under /tmp
, I won't get anything.
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 0 | 0 | 0 | 0 |
----------|---------|----------|---------|---------|-------------------
But if I run the same command under /usr/share/node
or /
, I'm able to get the correct output with coverage numbers.
Not sure if it's a weird permission issue in nyc. If it's an expected behavior of nyc, it should be documented. Thanks!
Environment Information
System:
OS: Linux 5.3
CPU: (16) x64 Intel(R) Xeon(R) CPU E5-2686 v4 @ 2.30GHz
Memory: 64.74 GB / 119.89 GB
Binaries:
Node: 12.18.3 - /usr/bin/node
npm: 6.14.6 - /usr/bin/npm
@ansjcy Thanks for filing this issue as I had the same problem.
My solution was just to replace all the file paths in the coverage-final.json with the current working directory (I had a copy of the code already checked out).
For anyone running into this, use the --cwd
option to set nyc
's current working directory to the root of your project.