如何设置Karma运行程序代码覆盖率? [英] How to setup Karma runner code coverage?
问题描述
我正在尝试让Karma运行程序在Jenkins构建期间生成cobertura格式的代码覆盖率报告.我可以获取它以生成coverage.xml文件,但实际上它没有任何coverage数据.出现(使用LOG_DEBUG
)覆盖率预处理器未运行.
I am attempting to get Karma runner to generate cobertura formatted code coverage reports during a Jenkins build. I can get it to generate a coverage.xml file, but it does not actually have any coverage data. It appears (using LOG_DEBUG
) that the coverage preprocessor is not running.
我的karma.conf.js
文件中的相关内容是:
The relevant pieces from my karma.conf.js
file are:
files = [
JASMINE,
JASMINE_ADAPTER,
'app/components/angular/angular.js',
'app/components/angular-mocks/angular-mocks.js',
'tmp/scripts/**/*.js',
'tmp/spec/**/*.js'
];
preprocessors = {
'tmp/scripts/**/*.js': 'coverage'
};
// test results reporter to use
// possible values: 'dots', 'progress', 'junit'
reporters = ['dots', 'junit', 'coverage'];
junitReporter = {
outputFile: 'test-results.xml'
};
coverageReporter = {
type: 'cobertura',
dir: 'coverage/',
file: 'coverage.xml'
};
(junit报告生成得很好.)
(The junit report is generating fine.)
推荐答案
显然,业力代码覆盖文档比我想象的要真实.将我的preprocessors
配置更改为
Apparently the karma code coverage documentation was more literal than I thought. Changing my preprocessors
configuration to
preprocessors = {
'**/tmp/scripts/**/*.js': 'coverage'
};
(请注意前面的**/
)做到了.我不确定为什么files
数组和preprocessors
对象的语法不同('tmp/scripts/**/*.js'
与'**/tmp/scripts/**/*.js'
).
(notice the preceding **/
) did the trick. I am not sure why the syntax is different for the files
array and the preprocessors
object ('tmp/scripts/**/*.js'
vs. '**/tmp/scripts/**/*.js'
).
这篇关于如何设置Karma运行程序代码覆盖率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!