-1

I have two projects (actually, a project and its sidecar) in the same repository - the server (root) and aux/sidecar (at aux/sidecar folder). I generate coverage for them using jest --coverage calls, which generates lcov.info files, which are located at coverage/lcov.info and aux/sidecar/coverage/lcov.info. I would like to merge them into a single report, so it could be uploaded to sonarqube and we could see the consolidated coverage for the whole repository.

I found lcov-result-merger tool, but I couldn't make it work as expected. I tried the following script on my package.json:

    "merge-coverage": "lcov-result-merger 'coverage/lcov.info' 'aux/sidecar/coverage/lcov.info' coverage/lcov.info",

My idea was to put all results into the root project's result. However, when running this line, it seems that the third argument is ignored (I think it only expects two arguments).

I also tried the following (creating a pattern - that I'm not sure it is correct - that would grab both files):

    "merge-coverage": "lcov-result-merger './**/**/coverage/lcov.info' 'coverage/lcov.info'",

But it also didn't work as expected (my sonarqube still shows 0% coverage).

I wonder if there is any other option - maybe something to fix my scripts, but I'm also open to other tools that would do the trick.

3 Answers 3

3

Here is an answer that does not answer your question, but that answers your need to push coverage to SonarQube: sonar.javascript.lcov.reportPaths accepts multiple paths, separated by a comma. You don't need to merge your LCOV files. SonarQube will merge them for you.

Sign up to request clarification or add additional context in comments.

Comments

1

The LCOV Result Manager npm package seems like a good fit there.

From reading the source code, that's responsible of parsing the arguments (lcov-result-merger/bin/lcov-result-merger.js), I'd say you're 100% correct guessing it only accepts one argument for specifying the input files:

const args = yargs(hideBin(process.argv)).command(
  '* <pattern> [outFile] [options]'

The yargs there is a Node.js library for parsing command line arguments.

So the above code means you have to pass exactly one argument for your input files.

This is also reflected in the main 14 lines of code of the package, that take the single pattern argument (of TypeScript type "string") and have the fast-glob Node.js library evaluate it as glob pattern.

(That limitation is indeed kind of weird for a tool whose purpose is to always process multiple input files.)

Given you're restricted to pass only one input argument, and that argument may be any glob pattern, you could try to catch both of your lcov.info files with this: **/coverage/lcov.info.

The pattern that you tried seems to be valid, too (although the double **/ is redundant).

Are there any helpful logs when running the merge-coverage script?

For debugging you could run the merge-coverage script and look into the merged lcov.info for whether it contains test file names from both projects.

Comments

1

Yet another choice is to use the lcov tool itself to merge reports.

lcov -o mergedReport.info -a firstSegement.info -a secondSegment.info ...

There are a lot of options to munge and display the data in various ways. See the man pages.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.