Merging coverage reports from nyc

2.5k views Asked by At

I have a CI running that does mocha test executions in parallel. A test execution creates a coverage report coverage.json - generated by nyc. I want to have a final merged report from all of the coverage.jsons in lcov format, but I can't manage to generate one - I always end up having an empty text summary. What I've tried:

  1. Running nyc report:
nyc report --temp-dir=nyc/coverage_dir --reporter=text --reporter=lcov 

gives an empty report and text summary

  1. First running nyc merge and then nyc report
nyc merge ./coverage_dir coverage.json
nyc report --report-dir=temp --reporter=text --reporter=lcov

This combination does seem to merge the coverage.jsons files, at least judging from the file size, but the report step still displays an empty text summary.

  1. Trying the above with different version, i.e. nyc 15.1.0 and nyc 14.1.1
  2. Specifying the -t flag and --report-dir options outlined in this answer
  3. Changing to a parent directory and rerunning the commands as specified by this answer.

All resulting in an empty text summary of the final report.

2

There are 2 answers

0
TOPKAT On

FYI, there is now a section in nyc doc about it: combining-reports-from-multiple-runs

0
Marco Caberletti On

I solved it in this way.

Copy all the json files in the default folder:

mkdir .nyc_output
cp project_a/coverage/coverage-final.json .nyc_output/project_a.json
cp project_b/coverage/coverage-final.json .nyc_output/project_b.json

Then generate the report:

nyc report --reporter=text --reporter=lcov --report-dir=destination-dir