Test Coverage using jest-sonar-reporter not shown in UI

Hi there,

I’m using SonarQube Community Edition 8.3.1, I have a Javascript based code and when execute the npm test (jest --coverage) is creating the coverage files, however when setting the ‘sonar.javascript.lcov.reportPaths=coverage/lcov.info’ is not displaying the coverage % in the UI, here are my details about the environment

jest

1- npm i -D jest-sonar-reporter
2- npm i jest

sonar-project.properties

sonar.projectKey=sonar-jest-test
sonar.sources=src
sonar.tests=tests
sonar.javascript.lcov.reportPaths=coverage/lcov.info
sonar.testExecutionReportPaths=test-report.xml

package.json

{

  • “name”: “xxxxx”,*
  • “version”: “1.0.0”,*
  • “description”: “”,*
  • “main”: “src/index.js”,*
  • “scripts”: {*
  • “test”: “jest --coverage”*
  • },*
  • “repository”: {*
  • “type”: “git”,*
  • “url”: “xxxxxxxxxx”*
  • },*
  • “author”: “”,*
  • “license”: “ISC”,*
  • “jest”: {*
  • “testResultsProcessor”: “jest-sonar-reporter”*
  • }*
    }

coverage folder
image

+ cat coverage/lcov.info
TN:
SF:tests/sum.js
FN:1,sum
FNF:1
FNH:1
FNDA:1,sum
DA:2,1
DA:5,1
LF:2
LH:2
BRF:0
BRH:0
end_of_record

Project in UI

Can you please help on address where can be the issue, or a guide about best practices on unit testing for javascript using Jest?

Appreciate your comments,
Regards

I found the root cause, this might help to someone with the same issue

I added “collectCoverage”: true inside my package.json and that generated the coverage folder with the lcov.info file

Final package.json

{
“name”: “jest-sonar”,
“version”: “1.0.0”,
“description”: “”,
“main”: “src/index.js”,
“scripts”: {
“test”: “jest --coverage”
},
“author”: “”,
“license”: “ISC”,
“jest”: {
“collectCoverage”: true,
“testResultsProcessor”: “jest-sonar-reporter”
}
}

Finally, inside sonar-project.properties the sonar.javascript.lcov.reportPaths=coverage/lcov.info works fine and the coverage was shown in the UI

Thanks,
Regards

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.