简体   繁体   English

Sonarqube从Karma Coverage LCOV文件使用默认绝对路径将默认coverage设置为0

[英]Sonarqube default coverage to 0 from Karma Coverage LCOV file with absolute pathjs

Sonar does not retrieve the coverage information for my project when paths are absolute in my lcov file. 当lcov文件中的路径为绝对路径时,Sonar不会检索我的项目的coverage信息。 For the file: 对于文件:

TN:
SF:/mnt/vg01-data01/jenkins/<jenkins.myhost.com>/jenkins_home/workspace/<job1>/src/app.js
FN:,(anonymous_0)
FN:,(anonymous_1)
FNF:2
FNH:2
FNDA:1,(anonymous_0)
FNDA:2,(anonymous_1)
DA:3,1
DA:4,1
DA:6,1
DA:7,1
DA:8,1
DA:9,1
DA:11,1
DA:18,1
DA:19,1
DA:22,2
DA:27,1
LF:11
LH:11
BRF:0
BRH:0
end_of_record
....

I get the following warnings: 我收到以下警告:

...
05:06:27.565 INFO: Analysing [/srv/jenkins/<jenkins.myhost.com>/jenkins_home/workspace/<job1>/coverage/lcov.info]
05:06:27.574 DEBUG: Default value of zero will be saved for file: src/app.js
05:06:27.574 DEBUG: Because was not present in LCOV report.
05:06:27.578 DEBUG: Default value of zero will be saved for file: src/app.spec.js
05:06:27.578 DEBUG: Because was not present in LCOV report.
05:06:27.579 DEBUG: Default value of zero will be saved for file: src/js/form/form.ctrl.js
05:06:27.579 DEBUG: Because was not present in LCOV report.
05:06:27.580 DEBUG: Default value of zero will be saved for file: src/js/form/form.module.js
05:06:27.580 DEBUG: Because was not present in LCOV report.
05:06:27.581 DEBUG: Default value of zero will be saved for file: src/js/success/success.ctrl.js

...

However, by default karma (and istambul) are generating file with absolute paths. 但是,默认情况下,业力(和istambul)会生成具有绝对路径的文件。

If I change the paths to make them relative, sonarqube reports the coverage correctly. 如果我更改路径使其相对,则sonarqube会正确报告覆盖范围。 However, I must ensure a "lcov patch" script is always run before reporting to sonar. 但是,在向声纳报告之前,我必须确保始终运行“ lcov补丁”脚本。

Does sonar support absolute paths? 声纳是否支持绝对路径? What are other teams doing for this issue? 其他团队正在做什么呢? These are the versions I am using: 这些是我正在使用的版本:

  • karma@1.3.0 & karma-coverage@1.1.1 karma@1.3.0和karma-coverage@1.1.1
  • sonar 6.1 and JavaScript plguin 2.14 声纳6.1和JavaScript plguin 2.14

Update : I replaced the file and log I see with the exact ones from the jobs (I still must change the name of the host and job for security reasons.) 更新 :我用作业中的确切文件替换了我看到的文件和日志(出于安全原因,我仍然必须更改主机和作业的名称。)

Update March 2016 : I have sent a Pull Request to Istambul to enable to generate lcov file with relative paths. 2016年3月更新 :我已经向Istambul发送了Pull请求,以生成具有相对路径的lcov文件。 I expect this to solve this issue https://github.com/gotwarlost/istanbul/pull/771 我希望这可以解决这个问题https://github.com/gotwarlost/istanbul/pull/771

The SonarQube JavaScript plugin should be able to handle both relative and absolute paths in LCOV files. SonarQube JavaScript插件应该能够处理LCOV文件中的相对路径和绝对路径。 However, it seems that your setup is incorrect. 但是,看来您的设置不正确。 Your LCOV file refers to file paths in a given directory: 您的LCOV文件引用给定目录中的文件路径:

SF:/home/mrincon/work/git/promoter-app-client/src/app.js

And based on the logs of your analysis, it seems that your analysis is run in another directory: 根据您的分析日志,您的分析似乎在另一个目录中运行:

Analysing [/srv/jenkins/master/jenkins_home/workspace/job1/coverage/lcov.info]

Maybe you generated the LCOV file on one machine and run the analysis on another... In the end, SonarQube can't match the paths contained in the LCOV file with the files which are analysed. 也许您在一台机器上生成了LCOV文件,然后在另一台机器上运行了分析...最后,SonarQube无法将LCOV文件中包含的路径与被分析的文件进行匹配。

You should either: 您应该:

  • generate the LCOV report and run the SonarQube analysis from the same directory, 生成LCOV报告并从同一目录运行SonarQube分析,
  • or have your LCOV file contain only relative paths. 或者您的LCOV文件仅包含相对路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM