我在配置 sonarqube 时遇到问题,无法与 React + Jest 一起正常工作。
我的配置:
my_moudle.sonar.projectBaseDir=front_app
my_module.sonar.javascript.file.suffixes=.js,.jsx
my_module.sonar.tests=src
my_module.sonar.test.inclusions=**/__tests__/** my_module.sonar.javascript.lcov.reportPaths=coverage/lcov.info
目前我将 src 文件夹指向为测试文件夹,因为我在同一项目文件夹中的测试文件夹中为每个组件设置了一组测试。感谢 SonarJS,我对我的项目有适当的覆盖,但我不知道为什么我看不到覆盖度量指标中的单元测试数量。任何检查的配置将不胜感激。
谢谢,巴布
我一直在尝试找出如何用Jest单元测试和.net单元测试填充SonarQube。
我有SQ 6.7的本地版本以及Javascript和C#插件的所有最新版本。
关于Jest,我有声纳的Jest记者来导出test-report.xml文件,并且还生成了lcov.info文件。
SonarQube能够读取lcov,并且看到覆盖率%,但是无论我设置为包含/排除还是测试路径,它都不会显示与源文件关联的测试。
文件结构为所有.js,而.test.js与每个模块位于同一目录中。
为我指明正确方向的任何帮助,或者遇到或克服此问题的其他人,将不胜感激。
我使用 jest-sonar-reporter 进行覆盖,如下所示:
包.json
{
"name": "app",
"version": "1.0.0",
"description": "The task runner packages for Gulp",
"main": "gulpfile.js",
"scripts": {
...
"test": "jest --coverage",
...
},
"devDependencies": {
...
"jest": "26.0.1",
"jest-sonar-reporter": "2.0.0",
...
},
"jest": {
...
"collectCoverage": true,
"testResultsProcessor": "jest-sonar-reporter"
},
"jest-junit": {
"suiteName": "jest tests",
...
}
}
Run Code Online (Sandbox Code Playgroud)
我在npm run test后生成了 test-report.xml 文件,如下所示:
测试报告.xml
<?xml version="1.0" encoding="UTF-8"?>
<testExecutions version="1">
<file path="<path to>\AreaList.test.jsx">
<testCase name="Description 1 " duration="6"/>
</file>
<file path="<path to>\selectors.search.test.js">
<testCase name="Description 2 " duration="2"/> …Run Code Online (Sandbox Code Playgroud)