我正在尝试使用GruntJS的grunt-mocha-test插件设置代码覆盖率。我在“生成覆盖范围”一节下跟随this guide。
但是,运行grunt会生成一个coverage.html报告,该报告仅覆盖已运行的测试文件...而不是我的其他代码。
所以:
/test/**
文件,使其不包含在承保范围报告中?我的正常摩卡测试通过grunt运行良好,只是覆盖率报告是问题。
BlanketJS的文档在这里并没有真正帮助。当需要消隐时,“选项”部分中可能存在某些内容?
这里的任何一个都是我的gruntfile:
mochaTest: {
test: {
src: watchFiles.mochaTests,
options: {
reporter: 'spec',
require: ['server.js', 'app/tests/blanket.js']
}
},
coverage: {
src: watchFiles.mochaTests,
options: {
reporter: 'html-cov',
// use the quiet flag to suppress the mocha console output
quiet: true,
// specify a destination file to capture the mocha
// output (the quiet option does not suppress this)
captureFile: 'coverage.html'
}
}
},
这是blanketjs包装器:
var path = require('path');
var srcDir = path.join(__dirname, '..');
require('blanket')({
// Only files that match the pattern will be instrumented
pattern: srcDir
});
console.log(srcDir);
src: watchFiles.mochaTests
只是一个变量,上面是我要运行的测试数组。
答案 0 :(得分:3)
如果有人来这里,我已经使用这样的配置解决了这个问题:
/*
* This is a wrapper to blanket.js used for grunt mocha tests
*/
var path = require('path');
var srcDir = path.join(__dirname, '..');
var antiFilter = path.join(__dirname, '..', 'tests');
require('blanket')({
// Only files that match the pattern will be instrumented
pattern: srcDir, 'data-cover-never': antiFilter
});
关键是“数据覆盖 - 永不”'选项,指定根据模式过滤掉的内容。