SonarQube with Jest and react - Coverage on 0 New Lines to cover

Viewed 5175

I have integrated Jest with SonarQube, SonarQube execution is getting failure throwing the below error,

Error during parsing of generic test execution report '**/reports/test-reporter.xml'. Look at the SonarQube documentation to know the expected XML format.

and in SonarQube dashboard getting " Coverage on 0 New Lines to cover"

enter image description here

below is my sonar and package.json configuration

sonar.projectKey=projectname
sonar.projectVersion=1.0
sonar.sourceEncoding=UTF-8
sonar.branch.name=branchname

sonar.sources=**/src
sonar.tests=**/src/__test__

sonar.test.inclusions=**/src/__test__/*.spec.js
sonar.coverage.exclusions=**/src/__test__/__snapshots__/**
sonar.exclusions=**/src/assets/*

sonar.javascript.lcov.reportPaths=**/output/coverage/jest/lcov.info
sonar.testExecutionReportPaths=**/reports/test-reporter.xml



 "jest": {
    "verbose" :true,
    "notify": true,
    "testRegex": "((\\.|/*.)(spec))\\.js?$",
    "moduleNameMapper": {
      "^.+\\.(css|less|scss|sass)$": "identity-obj-proxy"
    },
    "moduleDirectories": ["node_modules", "src"],
    "transformIgnorePatterns": [
      "node_modules/(?!@agm)"
    ],
    "testResultsProcessor": "jest-sonar-reporter",
    "automock": false,
    "collectCoverage":true,
    "coverageReporters": [
      "text",
      "lcov"
    ],
    "reporters": [
      "default"
    ]
  },

  "jestSonar": {
    "sonar56x": true,
    "reportPath": "reports",
    "reportFile": "test-reporter.xml",
    "indent": 4

  },

Please suggest me on this. TIA.

2 Answers

Make sure the files

sonar.javascript.lcov.reportPaths=\**/output/coverage/jest/lcov.info
sonar.testExecutionReportPaths=**/reports/test-reporter.xml

are visible to Sonar.

In my case, it helped to solve the problem.

Related