- SonarQube Enterprise Edition v10.6
- Helm
- Typescript/Javascript repositories that uses jest test framework to generate coverage reports
Hello there!
When scanning a repository for code coverage I want the conditional coverage metric to closely if not match exactly what the branch coverage is reflecting from within the lcov.info coverage report. At times there are discrepancies between the lcov.info report generated by jest and the results displayed in SonarQube that results in the failure of the quality gate.
The line coverage matches up everytime, however we are noticing that condition coverage from SonarQube does not match the branch coverage that displays in the lcov.info.
One prime example is that the lcov.info files shows 100% coveraged in both line and function for a single file but in SonarQube for the conditional coverage is displaying 37.50%. Note our repositories combine multiple coverage reports that are combined into a single lcov.info file before the sonar scan begins
cat coverage/*info > lcov.info
1.) I would like to understand why we are seeing a discrepancy from the conditional coverage
2.) have an understanding of how the conditional coverage is determined when dealing with 2 or more coverage reports. Because we’ve executed a test with just submitting the unit test to sonar and didn’t see any issues, so this looks to be due to merging the reports into a single file.
3.) would it be best to submit the coverage reports separately in order receive correct results ?
Below I’ve attached the source code file that is showing the discrepency
import { AppEnvs, ContentfulEnvs } from 'lib/constants';
const contentfulEnvs = Object.values(ContentfulEnvs);
type ContentfulEnv = typeof contentfulEnvs[number];
export function getContentfulEnv(): ContentfulEnv {
const appEnv = process.env.APP_ENV;
if (appEnv === AppEnvs.PROD) {
return ContentfulEnvs.MASTER;
}
if (appEnv === AppEnvs.STAGE) {
return ContentfulEnvs.STAGE;
}
if (appEnv === AppEnvs.DEV) {
return ContentfulEnvs.DEV;
}
return ContentfulEnvs.DEVELOPMENT;
}
Thank you!