【问题标题】:SonarQube with Jest and react - Coverage on 0 New Lines to coverSonarQube with Jest and react - 覆盖 0 条新线路
【发布时间】:2020-09-24 09:55:03
【问题描述】:

我已将 Jest 与 SonarQube 集成,SonarQube 执行失败并引发以下错误,

解析通用测试执行报告“**/reports/test-reporter.xml”时出错。查看 SonarQube 文档以了解预期的 XML 格式。

并且在 SonarQube 仪表板中获得“覆盖 0 个新行的覆盖范围”

下面是我的声纳和 package.json 配置

sonar.projectKey=projectname
sonar.projectVersion=1.0
sonar.sourceEncoding=UTF-8
sonar.branch.name=branchname

sonar.sources=**/src
sonar.tests=**/src/__test__

sonar.test.inclusions=**/src/__test__/*.spec.js
sonar.coverage.exclusions=**/src/__test__/__snapshots__/**
sonar.exclusions=**/src/assets/*

sonar.javascript.lcov.reportPaths=**/output/coverage/jest/lcov.info
sonar.testExecutionReportPaths=**/reports/test-reporter.xml



 "jest": {
    "verbose" :true,
    "notify": true,
    "testRegex": "((\\.|/*.)(spec))\\.js?$",
    "moduleNameMapper": {
      "^.+\\.(css|less|scss|sass)$": "identity-obj-proxy"
    },
    "moduleDirectories": ["node_modules", "src"],
    "transformIgnorePatterns": [
      "node_modules/(?!@agm)"
    ],
    "testResultsProcessor": "jest-sonar-reporter",
    "automock": false,
    "collectCoverage":true,
    "coverageReporters": [
      "text",
      "lcov"
    ],
    "reporters": [
      "default"
    ]
  },

  "jestSonar": {
    "sonar56x": true,
    "reportPath": "reports",
    "reportFile": "test-reporter.xml",
    "indent": 4

  },

请就此向我提出建议。 TIA。

【问题讨论】:

    标签: reactjs unit-testing jestjs sonarqube sonarqube-scan


    【解决方案1】:

    请注意,分支或 pr 分析中的 sonarqube 仅显示差异。因此,当您在那里没有代码更改时,它不会向您显示覆盖率信息。 Code and details of code coverage not showing in SonarCloud for .Net solution 很好地解释了这一点。

    【讨论】:

    • 感谢@Simon,合并到主覆盖率后,SonarQube 中显示...但在 CDAnalytics 中仍显示单元测试覆盖率 0.0%。请让我知道为此需要做什么。
    • 我鼓励您让扫描仪将更多信息放入日志中。不确定您使用的是哪种扫描仪。但扫描仪很安静,会告诉你很多。l
    【解决方案2】:

    确保文件

    sonar.javascript.lcov.reportPaths=\**/output/coverage/jest/lcov.info
    sonar.testExecutionReportPaths=**/reports/test-reporter.xml
    

    对声纳可见。

    就我而言,它有助于解决问题。

    【讨论】:

      猜你喜欢
      • 2019-01-10
      • 1970-01-01
      • 2021-05-09
      • 2022-07-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-03
      • 1970-01-01
      • 2018-05-07
      相关资源
      最近更新 更多