Jest v28 sharding, merge coverage report to single file missing branch data

Viewed 171

Using Jest v28 --shard flag significantly speeds up tests in our CI/CD pipeline, but it creates the issue of having to merge multiple coverage reports into a single file (required for our code quality report on PRs).

I am forced to use lcov format for the coverage report. I am able to merge the coverage report using lcov CLI tool:

lcov --add-tracefile ./coverage-unit/lcov-1.info --add-tracefile ./coverage-unit/lcov-2.info  --output-file ./coverage-unit/lcov.info

But the merged ./coverage-unit/lcov.info file does not pick up the branch data:

Combining tracefiles.
Reading tracefile ./coverage-unit/lcov-1.info
Reading tracefile ./coverage-unit/lcov-2.info
Writing data to ./coverage-unit/lcov.info
Summary coverage rate:
  lines......: 87.9% (5003 of 5691 lines)
  functions..: 85.4% (543 of 636 functions)
  branches...: no data found

This results in a merged lcov.info that is omitting the BRH, BRF, and BRDA fields.

Is there a proper way to merge lcov report files?

1 Answers

lcov has branch coverage data disabled by default. Using the lcov_branch_coverage=1 flag enables it.

The following command properly merges the coverage reports with branch coverage data:

lcov --rc lcov_branch_coverage=1 \
  --add-tracefile ./coverage-unit/lcov-1.info \
  --add-tracefile ./coverage-unit/lcov-2.info  \
  --output-file ./coverage-unit/lcov.info
Related