SonarQube and problem with ReactJS project code coverage

Viewed 1694

I'm trying to understand how SonarQube is handling Code Coverage for ReactJS.

I have created basic Jest test which is executed by a script set in my package.json:

    "test": "react-scripts test --env=jsdom --coverage --testResultsProcessor jest-sonar-reporter",

and has set coverage and reporting as

  "jestSonar": {
    "reportPath": "reports",
    "reportFile": "test-report.xml",
    "indent": 4
  }

Test will pass, coverage folder and report is created as expected. Then I try to run sonar-scanner which has a config as follow:

const sonarqubeScanner = require('sonarqube-scanner');
sonarqubeScanner({
    serverUrl: 'https://sonarqube.myhost.com/',
    options : {
        'sonar.sources': '.',
        'sonar.exclusions' : 'src/**/*.bak.*, src/**/*.bak, src/**/*.orig, **/*.test.*',
        'sonar.inclusions' : 'src/**', 
        'sonar.tests': "./src/__tests__",
        "sonar.test.inclusions": "./src/__tests__/**/*.test.js, ./src/__tests__/*.test.js",
        'sonar.javascript.lcov.reportPaths' : 'coverage/lcov.info',
        "sonar.testExecutionReportPaths": "reports/test-report.xml",
        "sonar.coverage.jacoco.xmlReportPaths" : "reports/test-report.xml"
    }
}, () => {});

SonarQube scan will return SUCCESS but when I will go to the SonarQube dashboard for my project I do not see any updates for the Code Coverage neither Unit Test reported.

Any clue what is going on with it?

0 Answers
Related