How to upload karma test report to sonar?

試著忘記壹切 提交于 2019-12-13 06:09:50

问题


I have karma configured which gives me coverage report perfectly fine.
It gives me in lcov format. Referring to this http://docs.sonarqube.org/display/PLUG/JavaScript+Coverage+Results+Import
lcov report can be uploaded to sonar.

I have installed the plugin in sonar. My project builds through ant scripts so i have added

<property name="sonar.javascript.lcov.reportPath" value="/lcov.info"/>

I read on some blogs that lcov needs to be corrected so that sonar can understand it. I am done with it.
So lcov gets generated and is in the correct format.

For some reason the sonar is unable to find my lcov report and does not parse the report. I checked my path it is correct.
Am I missing on something ? Any help would be appreciated.


回答1:


lcov.info may have incorrect file paths. Other tools like coveralls work fine and sonar expects the relative path. Here is how my lcov.info looked. /source/app/simplebind/child.component.ts was incorrect and sonarqube expected src/app/simplebind/child.component.ts

TN:
SF:/source/app/simplebind/child.component.ts
FN:11,(anonymous_3)
FN:17,ChildComponent
FN:22,(anonymous_5)
FNF:3
FNH:3
FNDA:1,(anonymous_3)
FNDA:3,ChildComponent
FNDA:1,(anonymous_5)
DA:1,1
DA:3,1
DA:11,1

Use following command to replace the file path in lcov.info. You can execute it after gulp build from your jenkins shell.

sed -i -- 's/\/source/src/g' report/remap/lcov.info

Works fine for Angular2 Typescript Sonar plugin as well. https://github.com/Pablissimo/SonarTsPlugin




回答2:


You will have to add a property called <sonar.javascript.lcov.reportPath> for sonar to identify lcov file. This property should point to the location of the lcov.info file.

And ensure javascript plugin is installed in sonar server.




回答3:


The path of your LCOV report is set to /lcov.info which looks like an absolute path: is your report really located at the root of your file system? If your LCOV report is not at the root of the file system but at the root of your project, then the path of the LCOV report should be lcov.info, not /lcov.info.




回答4:


If you are using typescript change sonar.typescript.lcov.reportPaths



来源:https://stackoverflow.com/questions/37164545/how-to-upload-karma-test-report-to-sonar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!