The following is what I have for Coverage for my React JavaScript application. I am getting coverage locally with npm test
, but not reported in SonarQube. Can someone help me with what I am missing?
Gradle
// gradle sonar plugin configuration
apply plugin: 'org.sonarqube'
sonarqube {
properties {
property "sonar.projectName", "${project_name}-${version}"
property "sonar.projectKey", "${project_name}-${version}"
property "sonar.sources", "src/main/java/com/company/wcp,src/main/webapp/wcpwave2/src"
property "sonar.exclusions", "src/main/webapp/wcpwave2/src/assets/**"
// Where to find tests file, also src
property "sonar.tests", "src/main/java/com/company/wcp,src/main/webapp/wcpwave2/src"
// But we get specific here
// We don't need to exclude it in sonar.sources because it is automatically taken care of
property "sonar.test.inclusions", "src/**/*.spec.js,src/**/*.spec.jsx,src/**/*.test.js,src/**/*.test.jsx"
// Now specify path of lcov and testlog
property "sonar.javascript.lcov.reportPaths", "src/main/webapp/wcpwave2/coverage/lcov.info"
//property "sonar.testExecutionReportPaths", "src/main/webapp/wcpwave2/coverage/coverage-final.json"
}
}
sonar-project.properties
# Source
sonar.sources=src
# Where to find tests file, also src
sonar.tests=src
# But we get specific here
# We don't need to exclude it in sonar.sources because it is automatically taken care of
sonar.test.inclusions=src/**/*.spec.js,src/**/*.spec.jsx,src/**/*.test.js,src/**/*.test.jsx
# Now specify path of lcov and testlog
sonar.javascript.lcov.reportPaths=coverage/jest/lcov.info
#sonar.testExecutionReportPaths=coverage/jest/testlog.xml
package.json
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "jest --coverage",
"eject": "react-scripts eject"
},
"jest": {
"transform": {
"^.+\\.[t|j]sx?$": "babel-jest"
},
"collectCoverage": true,
"testResultsProcessor":"jest-sonar-reporter"
},
"homepage": "./",
"devDependencies": {
"jest": "^24.9.0",
"jest-junit-reporter": "^1.1.0"
}