SonarQube 与 Jest 单元测试

2023-12-31

我一直在尝试找出如何填充声纳Qube和我的笑话单元测试.net 单元测试.

我有一个本地版本SQ 6.7以及所有最新版本的 Javascript 和 C# 插件。

说到 Jest,我有sonar-jest-reporter https://www.npmjs.com/package/jest-sonar-reporter导出一个test-report.xml文件,并且还具有lcov.info正在生成文件。

SonarQube 能够读取lcov.info我看到覆盖率 %,但无论我设置为多少include/exclude或测试路径,它不会显示与源文件关联的测试。

文件结构全部.js.test.js与每个模块位于同一目录中。

任何帮助我指明正确方向的帮助,或者其他遇到并克服这个问题的人,将不胜感激。


看来我已经找到了让它发挥作用的方法。诀窍是两者兼得sonar.sources and sonar.tests指向同一目录(因为我们在同一目录中有测试和源)然后使用sonar.tests.inclusions将测试文件与模式匹配.test.js or .spec.js扩大。

这是一个示例sonar-project.properties其假设如下:

  1. src/components/Foo/Foo.jsx主要成分。
  2. src/components/Foo/Foo.spec.jsx测试文件。
# 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

现在您的测试文件也会显示出来。

更多信息请点击这里 https://github.com/3dmind/jest-sonar-reporter/issues/23

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

SonarQube 与 Jest 单元测试 的相关文章

随机推荐