gpt4 book ai didi

reactjs - React 和 Jest 的 Sonarqube 覆盖配置

转载 作者:行者123 更新时间:2023-12-03 13:40:36 25 4
gpt4 key购买 nike

我在配置 sonarqube 时遇到问题,无法与 React + Jest 正常工作。

我的配置:

my_moudle.sonar.projectBaseDir=front_appmy_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 文件夹指向测试文件夹,因为我在同一项目文件夹的 tests 文件夹中为每个组件设置了一组测试。感谢 SonarJS,我的项目有了适当的覆盖率,但我不知道为什么我在覆盖率度量指标中看不到大量的单元测试。任何经过检查的配置将不胜感激。

谢谢,倒刺

最佳答案

SonarJS 不负责单元测试报告,( Relevant FAQ entry )导入单元测试报告是SonarQube的责任。

我已经成功地通过以下设置做到了这一点。

首先我们需要将 jest 结果转换为 sonar consumable format 。为此,我使用了以下 npm 模块:jest-sonar-reporter .

我的package.json的片段:

"devDependencies": {
...
"jest": "^21.1.0",
"jest-sonar-reporter": "^1.3.0",
...
},
"jestSonar": {
"sonar56x": true,
"reportPath": "testResults",
"reportFile": "sonar-report.xml",
"indent": 4
}

您现在需要告诉 jest 使用此模块作为处理器,并告诉 Sonar 扫描仪使用此模块生成的文件。官方文档中有说明。

如果您使用的是 create-react-app/react-scripts,您可能需要一些额外的步骤,因为它们不会公开所有配置。

您需要将 package.json 中 scripts block 中的测试条目修改为:

"test": "react-scripts test --env=jsdom --testResultsProcessor ./node_modules/jest-sonar-reporter/index.js

关于reactjs - React 和 Jest 的 Sonarqube 覆盖配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51657821/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com