如何为grunt.registerTask指定istanbul选项

时间:2014-03-05 14:51:08

标签: node.js gruntjs mocha istanbul

我能够运行伊斯坦布尔给我一份关于我的摩卡测试用例报道的报告,如下所示,

./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运行它?

0 个答案:

没有答案