Can we merge coverage report Jest and Mocha?

1.8k Views Asked by At

I have problem when merge coverage report Jest and mocha. Currently I can export each of them. Any solution for this?

Coverage Jest:

enter image description here

Coverage Mocha: enter image description here

2

There are 2 best solutions below

0
On

How I was doing it:

1) get mocha and jest (I was using different technologies) to generate lcov files as output. You've gotta check the corresponding documentation, but lcov is one of the standard output options for many system

2) merge it with one of the tools. I was using linux lcov I think. Here is the script extract:

cp test/coverage/lcov.info cov-data/unit.info
cp bdd/coverage/lcov.info cov-data/it.info
#fixing the absolute folder to relative ones
sed -i -E 's,(SF:).*(/app/.*),\1.\2,' cov-data/unit.info
sed -i -E 's,(SF:).*(/app/.*),\1.\2,' cov-data/it.info
lcov --add-tracefile cov-data/unit.info -a cov-data/it.info -o cov-data/common.info --rc lcov_branch_coverage=1

3) Now you have your common.info file, that has the joint coverage data from both runs. All you need to do, is to visualize it somehow. I'd suggest using sonar, as it also does static code analysis for you. You will have to create configuration that points to the source and to the coverage. And, ofc, you will have to run an instance of the sonar server (could be done in virtual machine or/and with docker).

https://www.sonarqube.org/

0
On

The given solution requires linux lcov. How to automate merging reports ? like, some scripts defined in github on postbuild, so that post coverage, the reports would be merged automatically and finally taken by sonarqube.