最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jestjs - How to merge lcov.info files to make a consolidated coverage report? - Stack Overflow

programmeradmin8浏览0评论

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.

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.

Share Improve this question asked Mar 21 at 20:00 Leonardo Alves MachadoLeonardo Alves Machado 2,83711 gold badges42 silver badges55 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 1

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.

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))mand(
  '* <pattern> [outFile] [options]'

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

  • <x> means that x is required to be there

  • [y] means that y is optional

  • <files...> would mean that you could pass multiple arguments (example)

  • I believe the * at the start is the same as putting $0 there to run a default command if the arguments don't match the specification (the yargs docs are not easy...)

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.

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.

发布评论

评论列表(0)

  1. 暂无评论