SonarQube coverage mismatch when merging multiple lcov files in an Nx project

Hello,

I’m working in an Nx monorepo with multiple Nx Angular projects. One of my projects, named button, has two coverage reports: one generated by Jest and the other by Cypress. Both generate lcov.info files, which are reported to SonarQube using the following command:

sonar.javascript.lcov.reportPaths=coverage/lcov.info,cypress-coverage/lcov.info

When running these tests locally, the Jest coverage for button.component.ts shows as 86%, while the Cypress coverage is 93.02%. However, in SonarQube, the coverage for button.component.ts appears as 84.3%.

I was expecting the coverage to be at least 86%, so I would like to understand why there’s this discrepancy.

I’ve noticed a few other similar queries in the forum like this

Does anyone know what could be causing this? Enclosing the reports.
button-coverages.zip (55.3 KB)

Hi,

Welcome to the community!

This dusty-but-still-relevant blog post may help. Do you have files that are ignored locally by your coverage engines?

 
Ann

Hello,

Thank you for the response!
Here’s another section of my sonar.scanner.properties file:

sonar.inclusions=**/*.component.ts
sonar.test.inclusions=**/*.spec.ts,**/*.cy.ts

I’m specifically interested in the coverage metrics for button.component.ts. This file is not excluded by either coverage engine locally, and the metrics for it are included in the attached zip file.

However, when analyzed in SonarQube, it seems like the coverage reports for this single file aren’t being aggregated as expected. It almost appears that my Cypress coverage report is being ignored for this specific file.

Do you know why this would happen?

Hi,

Can you share your analysis log?

The analysis / scanner log is what’s output from the analysis command. Hopefully, the log you provide - redacted as necessary - will include that command as well.

This guide will help you find them.

 
Thx,
Ann