【问题标题】:Grunt-Mocha-Test BlanketJS CoverageGrunt-Mocha-Test BlanketJS 覆盖范围
【发布时间】:2014-08-19 21:31:59
【问题描述】:

我正在尝试使用 GruntJS 的 grunt-mocha-test 插件设置代码覆盖率。我关注了this guide,在“生成覆盖”部分下。

但是,运行 grunt 会生成一个 coverage.html 报告,该报告仅涵盖已运行的测试文件……而不是我的其他代码。

所以:

  1. 有人知道问题出在哪里吗?理想情况下,我不想使用另一个 grunt 插件。
  2. 如何过滤我的所有/test/** 文件以使其不包含在覆盖率报告中?

我的普通 mocha 测试通过 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'
                }
            }
        },

这是毯子js包装器:

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 只是上面的一个变量,用于保存我要运行的测试数组。

【问题讨论】:

    标签: node.js gruntjs mocha.js blanket.js


    【解决方案1】:

    如果有人来过这里,我已经使用如下配置解决了这个问题:

    /*
    * 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
    });
    

    关键点是“data-cover-never”选项,它指定根据模式过滤掉的内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-31
      • 1970-01-01
      • 2015-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-11
      相关资源
      最近更新 更多