简体   繁体   English

SonarQube始终为Javascript项目显示0.0%的代码覆盖率

[英]SonarQube always displays 0.0% code coverage for Javascript project

I am new to SonarQube, and am trying to use it with a Javascript project, on Windows. 我是SonarQube的新手,并且正在Windows上尝试将其与Javascript项目一起使用。 I've followed the doc as best I can and am successfully seeing the static code analysis sonar does. 我已尽最大努力关注该文档,并且成功地看到了静态代码分析声纳的功能。

I am using JsTestDriver for my unit tests, and producing a code coverage report file. 我将JsTestDriver用于单元测试,并生成代码覆盖率报告文件。 I see the test results in SonarQube, but the code coverage is always reported as 0.0%. 我在SonarQube中看到了测试结果,但是代码覆盖率始终报告为0.0%。 If I don't specify a code coverage report file, or specify a file name that doesn't exist, the code coverage block in my dashboard does not display at all, so I know Sonar is seeing the file in some sense. 如果我没有指定代码覆盖率报告文件,或者没有指定不存在的文件名,则仪表板中的代码覆盖率块根本不会显示,因此我知道Sonar在某种程度上看到了该文件。 I have run jGenHtml against the file and it produces correct HTML output, with the results I expect, so I know the file has content and is formatted correctly. 我已经对该文件运行了jGenHtml,它会产生正确的HTML输出以及预期的结果,因此我知道该文件包含内容并且格式正确。

I have specified the location for these files in my Javascript plugin settings. 我已经在Javascript插件设置中指定了这些文件的位置。 As indicated by the doc and some forum posts I found, I used the relative directory path test/results for the actual unit test results (which show up fine) and the relative file name test/results/code-coverage.dat for the coverage report. 正如我在文档和一些论坛文章中所指出的,我将相对目录路径test / results用于实际的单元测试结果(显示得很好),并使用相对文件名test / results / code-coverage.dat进行了覆盖。报告。 I've also tried specifying the file as an absolute path, but it didn't help. 我也尝试将文件指定为绝对路径,但没有帮助。

Any insight would be appreciated. 任何见识将不胜感激。

This is working now, thanks to the suggestion comment from David RACODON. 感谢David RACODON的建议,现在该方法正在起作用。

It seems my code coverage report contains file paths that look like this: 看来我的代码覆盖率报告包含如下所示的文件路径:

SF:H:\\perforce_workspaces\\atlasjs_main\\.\\test\\lib\\jquery-1.8.2.js SF:H:\\ perforce_workspaces \\ atlasjs_main \\。\\ test \\ lib \\ jquery-1.8.2.js

I edited the file to remove the \\.\\ bit in the middle, and now Sonar is able to import the file. 我编辑了文件以删除中间的\\。\\位,现在Sonar可以导入文件了。

The sample project's coverage report does not have this in its paths, and I note that I have been using a slightly newer verson of jsTestDriver than the sample app. 该示例项目的覆盖率报告的路径中没有此内容,我注意到,我使用的jsTestDriver版本比示例应用程序要新。 I am using 1.3.5, while the sample app comes with 1.3.4.b. 我正在使用1.3.5,而示例应用程序随附1.3.4.b。 I don't know if they changed the output format between revisions of the coverage plugin, or if this is something specific with my project. 我不知道他们是否在coverage插件的修订版之间更改了输出格式,或者这是否与我的项目有关。 In any event, I should be able to figure out a way to prevent or remove the offending characters. 无论如何,我应该能够找到一种方法来防止或删除令人反感的字符。

Note that jgenhtml was able to read my file just fine with the extraneoud \\.\\ so this seems to be an issue with Sonar being very picky. 请注意,jgenhtml能够使用多余的\\。\\很好地读取我的文件,因此Sonar非常挑剔,这似乎是一个问题。

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

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