2

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.

skyboyer
  • 22,209
  • 7
  • 57
  • 64
pushpa
  • 151
  • 1
  • 3
  • 8

2 Answers2

0

be aware that sonarqube in branch or pr analysis only displays the difference. Hence that it will not show you coverage information, when you do not have code changes in there. Code and details of code coverage not showing in SonarCloud for .Net solution explains this very well.

Simon Schrottner
  • 4,146
  • 1
  • 24
  • 36
  • thanks @Simon ,after merging to master coverage is showing up in SonarQube... but in CDAnalytics still its showing Unit test coverage 0.0%. Please let me know what needs to be done for this. – pushpa Jun 10 '20 at 06:00
  • i would encourage you to let the scanner put more information into the log. not sure which scanner you are using. but the scanner is quiet chatty and will tell you a lot.l – Simon Schrottner Jun 10 '20 at 12:48
0

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.

Matei Radu
  • 2,038
  • 3
  • 28
  • 45
Tata E
  • 11
  • 3