0

我安装了 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

4

1 回答 1

0

我找到了,必须用 jasmine 包装覆盖对象,这可能是作为 jasmine 插件使用的覆盖,但 spec 和 src 属性似乎是多余的。

  jasmine: {
    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-summary'}
                ],
                thresholds: {
                    lines: 75,
                    statements: 75,
                    branches: 75,
                    functions: 90
                }
            }
        }
于 2014-05-18T16:56:02.333 回答