No coverage information when using Jest and jest-sonar-reporter

  • CI system used: Travis CI
  • Languages of the repository: Javascript and Typescript
  • Error observed:
    After configuring jest and sonar-project.properties, the PR with the changes show No coverage information either of the PR (to be expected) or for the estimated coverage after merge.
    image
    When checking the logs I found the following things:

INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: ‘sonar.coverage.jacoco.xmlReportPaths’ is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
INFO: No report imported, no coverage information will be imported by JaCoCo XML Report Importer

INFO: Parsing /home/travis/…/test-report.xml
INFO: Imported test execution data for 4 files
INFO: Sensor Generic Test Executions Report (done) | time=80ms

INFO: ------------- Run sensors on project
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=2ms

I can’t seem to find any logs related to sonar.javascript.lcov.reportPaths

My configuration is as follows:

jest.config.js
“collectCoverage”: true,
“collectCoverageFrom”: [
“src/**/*.(tsx|ts)”
],
“testResultsProcessor”: “jest-sonar-reporter”,

sonar-project.properties
sonar.javascript.lcov.reportPaths=./coverage/lcov.info
sonar.testExecutionReportPaths=test-report.xml
sonar.tests=src

If someone could lend a hand I would really appreciate it.
Thanks,
Meyer

Hello,

You don’t need jest-sonar-reporter, this is third party module that we don’t maintain. The expected format of coverage files is lcov which Jest is able to generate by itself. So you just need to make sure lcov is part of your coverageReporters Jest setting.

Then you should make sure that you have in your sonar-project.properties the sonar.javascript.lcov.reportPaths setting that point to your coverage report. You can also specify in Jest where the coverage report is generated with the coverageDirectory setting.

So as long as your lcov file is correctly generated and available at the place specified in the sonar.javascript.lcov.reportPaths settings it should work fine.

1 Like

Thank you, I will try what you suggest and report back!

1 Like

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