I have Jenkins building our nx Angular mono repo. Right now, each app/module produces its own report under the coverage directory. Is there an approved way or a good way to merge all those reports into a single html report?
5 Answers
istanbul-combine will be deprecated in favor of istanbul report. I did a migration lately.
This was the old configuration that I was using with istanbul-combine
:
istanbul-combine -d coverage -p none -r lcov -r cobertura coverage/hierarchical-grid/coverage-final.json coverage/tree-grid/coverage-final.json coverage/non-grid/coverage-final.json coverage/grid/coverage-final.json
Changed to:
istanbul report --dir coverage --include coverage/**/coverage-final.json lcov
I was searching for a way to combine a couple .json reports with GitHub Actions CI.
The good side of this configuration above is that all .json files are part of similar directories:
- coverage/grid/coverage-final.json
- coverage/non-grid/coverage-final.json etc.
This is where the lcov report would be generated:

- 1,569
- 14
- 20
-
istanbul report worked perfect for me. Good to now is, that you must generate the `json` coverage report for each single coverage report you want to merge. – superheroicCoding Jan 27 '21 at 14:47
I've had the same problem myself. After running into this demand in 3 different projects, I've decided to write a blog post about it: https://yonatankra.com/how-to-create-a-workspace-coverage-report-in-nrwl-nx-monorepo/
In essence, I've written a script that takes the lcov
files and combines them:
const glob = require('glob');
const fs = require('fs');
const path = require('path');
const getLcovFiles = function (src) {
return new Promise((resolve, reject) => {
glob(`${src}/**/lcov.info`, (error, result) => {
if (error) return reject(error);
resolve(result);
});
})
};
(async function(){
const files = await getLcovFiles('coverage');
const mergedReport = files.reduce((mergedReport, currFile) => mergedReport += fs.readFileSync(currFile), '');
await fs.writeFile(path.resolve('./coverage/lcov.info'), mergedReport, (err) => {
if (err) throw err;
console.log('The file has been saved!');
});
})();
I then used it after the npm test
script.
If you need the JSON format, you can use https://github.com/davglass/lcov-parse or some other converter after the merge.

- 2,168
- 4
- 25
- 47
istanbul-combine is the best solution I've found for this. It uses an old version of istanbul internally, but it worked for me.

- 621
- 1
- 7
- 10
One possibility I found was to create a simple script to take care of the job. Fully under your control, so you can keep it up2date. I could not find something that was perfect for my needs.
https://github.com/neekware/fullerstack/blob/main/tools/utils/coverageMerge.ts
I am still looking to have a way to send the individual coverage files for publishable libraries, to be sent to coveralls separately. Once the solution is found, I will update the script. For now, all public libs sadly have to use the overall combined coverage links.

- 17,692
- 14
- 63
- 66
Merging reports using the cobertura-merge
library is another option (if you can use the cobertura reporting format), see here for a link to detailed step-by-step instructions https://stackoverflow.com/a/75614044/18727037
The linked blog article also includes instructions on integrating the merged coverage results into a Gitlab CI/CD pipeline. Maybe you can apply some of that to your jenkins pipeline.

- 11
- 2