How to scan when we have multiple lcov.info files in a UI project

  • which versions are you using : SonarQube 8
  • what are you trying to achieve: I am having multiple angular library projects, and each of them are run separately for the code coverage. So the coverage paths look like this
    reports/coverage/**/lcov.info

The ** I put because I have multiple folders each for my angular libraries.

How can I make sonar scan multiple lcov.info files

sonar.javascript.lcov.reportPaths=$(System.DefaultWorkingDirectory)/$(ProjectFolder)/reports/coverage/**/lcov.info

Above is what I tried. But then the scanner says it can not find any lcov.info

Hi @mukund26 ,

Welcome to SonarSource Community! :sonarsource:

Are you using SonarQube 4? Please upgrade to the latest version of SonarQube and try again. Yes, SonarQube can handle multiple lcov.info files. If it fails again, please run Sonar scanner analysis with sonar.verbose=true analysis parameer and share logs here.

Sorry. I was using sonar server 8.9
The azure devops yml task version I was using was 4. The verbose mode logs are here.

07:34:57.205 DEBUG: Not enough content in ‘flare.docs/projects/we-skeleton-loader/src/index.ts’ to have CPD blocks, it will not be part of the duplication detection
07:34:57.206 DEBUG: ‘flare.docs/projects/we-skeleton-loader/src/flare-skeleton-loader/flare-skeleton-loader.ts’ generated metadata with charset ‘UTF-8’
07:34:57.364 INFO: 499/499 source files have been analyzed
07:34:57.364 INFO: Sensor TypeScript analysis [javascript] (done) | time=60172ms
07:34:57.364 INFO: Sensor JavaScript/TypeScript Coverage [javascript]
07:34:57.365 INFO: Analysing [D:\work\75\s\flare.docs\reports\coverage\ng-outer-click\lcov.info, D:\work\75\s\flare.docs\reports\coverage\components\lcov.info]
07:34:57.398 DEBUG: Problem during processing LCOV report: can’t save DA data for line 613 of coverage report file (java.lang.IllegalArgumentException: Line with number 34 doesn’t belong to file group-base.component.ts).
07:34:57.398 DEBUG: Problem during processing LCOV report: can’t save DA data for line 661 of coverage report file (java.lang.IllegalArgumentException: Line with number 13 doesn’t belong to file control-group-content-template.directive.ts).
07:34:57.398 DEBUG: Problem during processing LCOV report: can’t save DA data for line 662 of coverage report file (java.lang.IllegalArgumentException: Line with number 16 doesn’t belong to file control-group-content-template.directive.ts).
07:34:57.398 DEBUG: Problem during processing LCOV report: can’t save DA data for line 663 of coverage report file (java.lang.IllegalArgumentException: Line with number 19 doesn’t belong to file control-group-content-template.directive.ts).
07:34:57.399 DEBUG: Problem during processing LCOV report: can’t save DA data for line 718 of coverage report file (java.lang.IllegalArgumentException: Line with number 13 doesn’t belong to file control-group-footer-template.directive.ts).
07:34:57.399 DEBUG: Problem during processing LCOV report: can’t save DA data for line 719 of coverage report file (java.lang.IllegalArgumentException: Line with number 16 doesn’t belong to file control-group-footer-template.directive.ts).
07:34:57.488 WARN: Could not resolve 1 file paths in [D:\work\75\s\flare.docs\reports\coverage\ng-outer-click\lcov.info, D:\work\75\s\flare.docs\reports\coverage\components\lcov.info]

When I use the ** wildcard, this is what I get

Sensor JavaScript/TypeScript Coverage [javascript]
08:15:11.845 WARN: No coverage information will be saved because LCOV file cannot be found.
08:15:11.845 WARN: Provided LCOV file path: ***D:\work\102\s/flare.docs/reports/coverage/**/lcov.info. Seek file with path: D:\work\102\s\flare.docs\reports\coverage\**\lcov.info***
08:15:11.845 WARN: No coverage information will be saved because all LCOV files cannot be found.
08:15:11.845 INFO: Sensor JavaScript/TypeScript Coverage [javascript] (done) | time=1ms

Hi @mukund26 ,

Can you try setting sonar.javascript.lcov.reportPaths=**/lcov.info instead?

Also, is your project a mono-repo?

I get this then

Provided LCOV file path: **\lcov.info. Seek file with path: D:\work\75\s**\lcov.info

08:45:31.030 WARN: No coverage information will be saved because all LCOV files cannot be found.

08:45:31.030 INFO: Sensor JavaScript/TypeScript Coverage [javascript] (done) | time=1ms

My project is a monorepo. With several angular libraries. The PR decoration for the sonar is also not working.

Does anyone has any idea about this?

Hi @mukund26 ,

I think you have run into this issue: Support wildcards for coverage report paths · Issue #578 · SonarSource/SonarJS · GitHub Please confirm if this is the case. This issue will be fixed in SonarJS 8.3, which will release in SonarQube 9.1.

We are using sonar server 8.9.1. When can we expect 9.1?

It is planned for late-September 2021.

You can simply use this command to merge multiple lcov.info files into one until this feature is live:

npm test (part1)
cd coverage && mv lcov.info lcov_1.info
npm test (part2)
cd coverage && mv lcov.info lcov_2.info
npx lcov-result-merger 'coverage/lcov_*.info' 'coverage/lcov.info'
3 Likes

Wildcards for sonar.javascript.lcov.reportPaths do not appear to work for me.
The one above is the only solution for TypeScript with parallel test runs.

Hi @Roberto_Carboni, thank you for providing feedback. Can you give more details of what didn’t work and what worked? I can notify our dev team once I get more details and we can improve it.

Also, was this on SonarQube (what version?) or SonarCloud?

1 Like

Hi Joe, thank you for your kind reply.
I’ll try to provide as much info as possible.
PRODUCT: SonarCloud
CI: CircleCI
I have a folder containing multiple lcov files at /home/circleci/project/apps/core/coverage/lcov/lcov_*.info, where * is a number from 0 to 31. This is the result of parallel test runs on CircleCI. The files are definitely present and contain the correct data, as confirmed by both an ls command and storing them as artefacts. Also, the folder only contains these files.
Setting sonar.javascript.lcov.reportPaths=/home/circleci/project/apps/core/coverage/lcov/lcov_*.info
results in:
INFO: No LCOV files were found using /home/circleci/project/apps/core/coverage/lcov/lcov_*.info.
Setting sonar.javascript.lcov.reportPaths=/home/circleci/project/apps/core/coverage/lcov/*
results in:
INFO: No LCOV files were found using /home/circleci/project/apps/core/coverage/lcov/*.
Creating lcov_* folders each containing a single lcov.info file and using a directory wildcard like
sonar.javascript.lcov.reportPaths=/home/circleci/project/apps/core/coverage/**/lcov.info
also results in
INFO: No LCOV files were found using /home/circleci/project/apps/core/coverage/**/lcov.info.
The only way I seem to be able to make SonarCloud work is to combine all lcov_*.info files in a single lcov.info using lcov-result-merger and set
sonar.javascript.lcov.reportPaths=/home/circleci/project/apps/core/coverage/lcov/lcov.info.
The problem with this approach is that coverage is wrong, as lcov-result-merger does not appear to work properly. Also, it’s a 3rd party, open-source library maintained by a small group of volunteers and I would avoid relying on it.

1 Like

I recommend you try this setting:

sonar.javascript.lcov.reportPaths= **/lcov_*.info

This tools is helpful to test: https://globster.xyz/

Hey @Joe thank you for the tip, that worked!
SonarCloud is finding the files, but the reported coverage is wrong (32.7% against ~70% we get running locally). This is the same result we got when aggregating the reports ourselves using lcov-report-merger.
I am currently looking into this, it would be very useful if you could confirm that other instances of a similar setup are working as expected on your side.

1 Like

How did you get 70%? Can you explain how you got that value?

Let’s try this: find an example of where coverage is incorrect in one of your source code files. You can use the SonarCloud UI to easily find where coverage doesn’t match your expectations or check the HTML report output of your coverage tool and visually check there.

Also consider the point made here: C#/VB.NET: SonarQube and SonarCloud support Branch/Condition Coverage data

Since SonarQube 8.3, the code coverage for .NET projects now takes into account the branch/condition coverage in addition to the line coverage. The coverage of your projects may decrease to be closer to reality, and it can impact your Quality Gate.

Alternatively, if you can share your entire project and pipeline with me (you can share privately if you want) so I can reproduce the issue or if you can share the HTML reports with the LCOV reports, that will be helpful.