SonarQube JS UT覆盖率始终为零。但是,jscoverage.xml导入看起来不错

时间:2017-06-28 06:02:24

标签: jenkins sonarqube mocha sonarqube-scan sonarjs

我正在使用SonarQube 6.3.1并且我正在运行jenkins来创建SonarQube仪表板。 因此,我需要运行jenkins工作来创建js覆盖率报告并导入SonarQube以创建UT覆盖。

通过在Jenkins中设置SonarQube扫描仪,这里是属性:

sonar.projectKey=xxxxxxManagement
sonar.projectName=XXXXXX Management
sonar.projectVersion=1.0

sonar.language=js
sonar.sources=webapp

sonar.sourceEncoding=UTF-8
sonar.javascript.coveragePlugin=jacoco
sonar.javascript.lcov.reportPaths=target/jscoverage/jscoverage.xml
sonar.dynamicAnalysis=reuseReports

sonar.login=admin
sonar.password=admin

在Jenkins中,这是报告路径和报告上下文: report path and context

以下是SonarQube报告: Here is SonarQube report

但是,SonarQube仪表板显示JS UT覆盖率为0

我想知道sonar.javascript.lcov.reportPaths设置是否错误,所以我尝试了很多方法 我试过了:

sonar.javascript.lcov.reportPaths=./target/jscoverage/jscoverage.xml

我也尝试过:

sonar.javascript.lcov.reportPaths=/target/jscoverage/jscoverage.xml

但UT覆盖率始终为零

由于我可以看到正确创建报告,我怀疑导入SonarQube是否失败,但Jenkins控制台中没有显示错误日志。

6/29 从我的调查中添加新的更新, 来自詹金斯日志,

INFO: Analysing [/var/jenkins_home/sharedspace/target/jscoverage/jscoverage.xml]
INFO: Sensor JavaScript Squid Sensor [javascript] (done) | time=1611ms
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=36ms
INFO: Sensor Code Colorizer Sensor
INFO: Sensor Code Colorizer Sensor (done) | time=1ms
INFO: Sensor CPD Block Indexer
INFO: org.sonar.scanner.cpd.deprecated.DefaultCpdBlockIndexer@4644f3d4 is used for js
DEBUG: No CpdMapping for language js
INFO: Sensor CPD Block Indexer (done) | time=0ms
INFO: Calculating CPD for 16 files
DEBUG: Detection of duplications for /var/jenkins_home/sharedspace/webapp/Component.js
DEBUG: Detection of duplications for /var/jenkins_home/sharedspace/webapp/model/util.js
DEBUG: Detection of duplications for /var/jenkins_home/sharedspace/webapp/controller/IncidentDetail.controller.js
DEBUG: Detection of duplications for /var/jenkins_home/sharedspace/webapp/model/formatter.js
DEBUG: Detection of duplications for /var/jenkins_home/sharedspace/webapp/util/Validator.js
DEBUG: Detection of duplications for /var/jenkins_home/sharedspace/webapp/localService/mockserver.js
DEBUG: Detection of duplications for /var/jenkins_home/sharedspace/webapp/controller/Attachments.controller.js
DEBUG: Detection of duplications for /var/jenkins_home/sharedspace/webapp/model/models.js
DEBUG: Detection of duplications for /var/jenkins_home/sharedspace/webapp/controller/HelpRequestOverview.controller.js
DEBUG: Detection of duplications for /var/jenkins_home/sharedspace/webapp/controller/NotFound.controller.js
DEBUG: Detection of duplications for /var/jenkins_home/sharedspace/webapp/controller/ErrorHandler.js
DEBUG: Detection of duplications for /var/jenkins_home/sharedspace/webapp/controller/CreateIncident.controller.js
DEBUG: Detection of duplications for /var/jenkins_home/sharedspace/webapp/controller/BaseController.js
DEBUG: Detection of duplications for /var/jenkins_home/sharedspace/webapp/controller/HelpRequestDetail.controller.js
DEBUG: Detection of duplications for /var/jenkins_home/sharedspace/webapp/controller/HelpRequests.controller.js
DEBUG: Detection of duplications for /var/jenkins_home/sharedspace/webapp/controller/App.controller.js
INFO: CPD calculation finished

从日志中,我们可以看到没有错误消息,所以我在Jenkins Job的Post Steps中添加了shell脚本:

cd target/jscoverage
pwd
vi jscoverage.xml

和Jenkins日志显示:

<coverage files="11" line-rate="0.7357294" lines-covered="348" lines-valid="473"[3;2Htimestamp="1498722804050">
<modules>
<module name="/Component.js" filename="/Component.js" line-rate="0.84210527" lin[6;1Hes-covered="16" lines-valid="19">
<lines>
<line number="1" hits="1"/>
<line number="8" hits="1"/>
<line number="10" hits="1"/>
<line number="24" hits="1"/>
<line number="27" hits="1"/>
<line number="30" hits="1"/>
<line number="32" hits="1"/>
<line number="35" hits="1"/>
<line number="36" hits="1"/>
<line number="39" hits="1"/>
<line number="49" hits="1"/>
<line number="51" hits="1"/>
<line number="61" hits="1"/>
<line number="63" hits="1"/>
<line number="64" hits="1"/>
...

从2条日志中我们可以看到报告看起来很好并且SonarQube可以读取报告,我们可以在xml报告中按文件查看UT封面文件,但UT覆盖率仍为零。

7/3 我添加了依赖

<dependency>
  <groupId>fr.sii.sonar</groupId>
  <artifactId>sonar-coverage-lcov</artifactId>
  <version>2.1.0</version>
</dependency>

并更改了

<sonar.javascript.jscoverage.reportPath>${project.build.directory}/jscoverage/jscoverage.xml</sonar.javascript.jscoverage.reportPath>

从jscoverage.xml到jscoverage。 lcov 但仍然没有工作

1 个答案:

答案 0 :(得分:0)

您尝试导入的报告看起来像xml文件。对于JavaScript,SonarQube支持LCOV格式的报道报告。请参阅文档:https://docs.sonarqube.org/display/PLUG/JavaScript+Coverage+Results+Import

根据您使用的覆盖率工具,可能有选项以LCOV格式生成报告。