3
votes

I have written some unit tests in jest. All of them are successful. Able to view test coverage report generated by jestenter image description here

But my sonarqube dashboard always shows 0% on coverage but unit tests are being detected.

enter image description here

I am using jest-sonar-reporter for sonar consumable format generation of reports.

This is my sonar properties file

sonar.projectKey=skyflow-app
sonar.projectName=Skyflow App
sonar.host.url = http://localhost:9000
sonar.projectVersion=1.0
sonar.sourceEncoding=UTF-8
sonar.sources=src
sonar.exclusions=**/node_modules/**,**/*.spec.ts, **/*.stories.tsx
sonar.tests=src
sonar.test.inclusions=**/*.test.tsx,**/*.test.ts
sonar.test.exclusions=**/*.stories.tsx
sonar.ts.tslintconfigpath=tslint.json
sonar.testExecutionReportPaths=testResults/sonar-report.xml
# sonar.coverageReportPaths = coverage/lcov.info
sonar.javascript.lcov.reportPaths = coverage/lcov.info

Please let me know where i am going wrong.

2
did you define sonar.language=js and sonar.profile= - Thanh Nguyen Van
and what's output error when you build ? - Thanh Nguyen Van

2 Answers

4
votes

A dumb mistake from myside.

Replacing sonar.javascript.lcov.reportPaths with sonar.typescript.lcov.reportPaths solved the issue.

-1
votes

can you share console output of the jenkins job?

in my case, jenkins cannot find the coverage report and got log in console output like this :

15:26:37  [ERROR] Coverage report '/home/jenkins/workspace/microservices-pipelines/xxx/target/jacoco.exec' could not be read/imported. Error: {}
15:26:37  java.lang.IllegalStateException: Failed to parse JaCoCo XML report: /home/jenkins/workspace/microservices-pipelines/xxx/target/jacoco.exec