[英]Code Coverage Sonar Qube for my React Javascript
The following is what I have for Coverage for my React JavaScript application.以下是我的 React JavaScript 应用程序的覆盖范围。 I am getting coverage locally with running
npm test
, but not reported in SonarQube. Can someone help me with what I am missing?我通过运行
npm test
在本地获得覆盖,但未在 SonarQube 中报告。有人可以帮助我解决我所缺少的问题吗?
Gradle 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/app,src/main/webapapp/appName/src"
property "sonar.exclusions", "src/main/webapp/appName/src/assests/**"
// Where to find tests file, also src
property "sonar.tests", "src/main/java/com/company/app,src/main/webapp/appName/src"
// But we get specific here
// We do not 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 test log
property "sonar.javascript.lcov.reportPaths", "src/main/webapp/appName/coverage/lcov.info"
//property "sonar.testExecutionReportPaths", "src/main/webapp/appName/coverage-final.json // does not work
sonar-project.properties声纳项目.properties
# Source
sonar.sources=src
# Where to find tests file, also src
sonar.tests=src
# But we get specific here
# We do not 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
#sonar.testExecutionReportPaths=coverage/jest/testlog.xml
package.json 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"
},
...... removed for brevity
The jest-sonar-reporter
package is old and hasn't been updated in 4 years. jest-sonar-reporter
package 很旧,4 年没更新了。 It has issues with paths not working as intended and failing to be reported.它存在路径未按预期工作且未报告的问题。
I have updated the plugin and republished it under @casualbot/jest-sonar-reporter
to fix this functionality as well as add other features for the community.我已经更新了插件并在
@casualbot/jest-sonar-reporter
下重新发布它以修复此功能并为社区添加其他功能。
Ex:前任:
package.json
{
...,
"jest": {
"rootDir": ".",
"testResultsProcessor": "@casualbot/jest-sonar-reporter"
},
"@casualbot/jest-sonar-reporter": {
"suiteName": "jest tests",
"outputDirectory": "coverage",
"outputName": "jest-report.xml",
"uniqueOutputName": "false",
"classNameTemplate": "{classname}-{title}",
"titleTemplate": "{classname}-{title}",
"ancestorSeparator": " › ",
"usePathForSuiteName": "true",
"relativePaths": "true"
}
}
Disclosure: I am the developer of the plugin.披露:我是插件的开发者。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.