我可以运行 istanbul 给我一份关于我的 mocha 测试用例覆盖率的报告,如下所示,
./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- -R spec test/**/*_test.js
现在,我想将它添加为我的 Gruntfile.js 的一部分,这样如果覆盖率低于某个百分比,我可以使我的构建失败。
所以我安装了grunt-istanbul-coverage并在 Gruntfile.js 中添加了以下内容,
grunt.initConfig({
jshint: {
files: ['Gruntfile.js', 'index.js', 'lib/**/*.js'],
options: {
jshintrc: '.jshintrc'
}
},
mochaTest: {
src: ['test/**/*_test.js'],
options: {
globals: ['chai'],
timeout: 6000,
ignoreLeaks: false,
ui: 'bdd',
reporter: 'spec'
}
},
coverage: {
options: {
thresholds: {
'statements': 80,
'branches': 80,
'lines': 80,
'functions': 80
},
dir: 'coverage',
root: 'test'
}
}
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-mocha-test');
grunt.loadNpmTasks('grunt-istanbul-coverage');
grunt.registerTask('test', ['jshint', 'mochaTest']);
grunt.registerTask('codecoverage', ['coverage']);
当我运行grunt codecoverage时,它仅针对顶级测试运行。我如何以及在哪里指定我想用它来运行它mocha -- -R spec test/**/*_test.js
?