简体   繁体   English

在TeamCity上为Karma配置代码覆盖率报告

[英]Configuring code coverage report for Karma on TeamCity

We are setting up TeamCity to run our jasmine tests using node and karma. 我们正在设置TeamCity以使用节点和业力来运行我们的茉莉花测试。

The tests run fine and results are reported under the "Tests" tab in TeamCity. 测试运行正常,并在TeamCity的“测试”选项卡下报告结果。

However we would like to report code coverage in TeamCity (and even set Build Failure Conditions on the level). 但是,我们想在TeamCity中报告代码覆盖率(甚至在级别上设置构建失败条件)。

I have installed the karma-coverage module 我已经安装了业力覆盖模块

npm install karma-coverage --save-dev

And tried to configure it in karma.conf.js by adding 并尝试通过添加在karma.conf.js配置它

preprocessors: {
 'myProject/Scripts/app/**/*.js': 'coverage'
},

reporters: ['progress', 'coverage'],

When karma is run, no errors are reported, and lots of files are created below the folder coverage , including a very nicely formatted code coverage report in index.html 运行karma时,不会报告任何错误,并且会在文件夹coverage创建大量文件,包括index.html格式良好的代码覆盖率报告

But nothing new shows up in TeamCity. 但TeamCity中没有任何新内容。 No "Code Coverage" tab. 没有“代码覆盖率”选项卡。

How do I configure karma to produce reports that show up in TeamCity? 如何配置karma以生成显示在TeamCity中的报告?

Perhaps I can use set coverageReporter to something appropriate, but what? 也许我可以使用set coverageReporter来适当的东西,但是什么? This setting makes no difference: 此设置没有区别:

coverageReporter: {
    type : 'html',
    dir : 'coverage/'
},

Bonus question: how do I set Build Failure Conditions on the karma reported code coverage? 奖金问题:如何在业力报告的代码覆盖率上设置构建失败条件?

The easiest way to get TeamCity to recognize your coverage report is to output a build artifact that contains that nice html coverage report. 让TeamCity识别您的覆盖率报告的最简单方法是输出包含该html覆盖率报告的构建工件。

Edit the configuration settings for your build and under Artifact Paths add something like: 编辑构建的配置设置,并在Artifact Paths下添加如下内容:

coverage/** => coverage.zip

TeamCity will recognize the coverage.zip artifact if it finds the index.html file in the root and will add a Code Coverage tab to each build. 如果在根目录中找到index.html文件并且将为每个构建添加代码覆盖率选项卡,TeamCity将识别coverage.zip工件。

Source: https://confluence.jetbrains.com/pages/viewpage.action?pageId=74847395#HowTo...-ImportcoverageresultsinTeamCity (Teamcity version 9.x) 资料来源: https ://confluence.jetbrains.com/pages/viewpage.action pageId = 74847395#HowTo...-ImportcoverageresultsinTeamCity(Teamcity version 9.x)

In my case the report was successfully generated into coverage.zip , but the code coverage tab wasn't visible in build report. 在我的例子中,报告已成功生成到coverage.zip ,但代码覆盖率选项卡在构建报告中不可见。

I had to manually add the report tab in Project Settings and provide a full path to the index.html file 我不得不在“项目设置”中手动添加报告选项卡,并提供index.html文件的完整路径

在此输入图像描述

Don't know, if the sequence is important, and shouldn't you use [] brackets at preprocessors entries? 不知道,如果序列很重要,你不应该在预处理器条目中使用[]括号吗?

Try the following: 请尝试以下方法:

reporters: ['progress', 'coverage'],

preprocessors: {
 'myProject/Scripts/app/**/*.js': ['coverage']
},

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

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