我安装了 grunt 插件 grunt-template-jasmine-istanbul
npm install grunt-template-jasmine-istanbul --save-dev
并添加到 Gruntfile.js 如下:
coverage: {
src: ['app/scripts/**/*.js'],
options: {
specs: ['test/**/*.js'],
template: require('grunt-template-jasmine-istanbul'),
templateOptions: {
coverage: 'test/coverage/coverage.json',
report: [
{type:'html',options: {dir: 'test/coverage/html'}},
{type:'text',options: {dir: 'test/coverage/text'}},
{type:'text'},
],
thresholds: {
lines: 75,
statements: 75,
branches: 75,
functions: 90
}
}
}
},
但是在运行测试时,它显示以下警告并且在测试/覆盖文件夹中没有报告:
my@computer:/share/angularjs-gs$ grunt test:coverage
Running "coverage" task
Warning: "dir" option is required. Use --force to continue.
Aborted due to warnings.
我还创建了 test/coverage/html 和 test/converage/text 文件夹。我还查看了插件作者的代码,但找不到任何解决方案:https ://github.com/maenu/grunt-template-jasmine-istanbul-example/blob/connect/Gruntfile.js