3

I'm trying to setup code coverage with with grunt-mocha-test plugin for GruntJS. I have followed this guide, under the section 'Generating Coverage'.

However, running grunt produces a coverage.html report that only has coverage for the test files that were run... not my other code.

So:

  1. Does anyone know what the issue is? Ideally I do not want to use another grunt plugin.
  2. How do I filter all my /test/** files to not be included in the coverage report?

My normal mocha tests run fine via grunt, just the coverage report is the problem.

The documentation for BlanketJS doesn't really help here. Perhaps there is something in the 'options' part when requiring blanker?

Any here is my 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'
                }
            }
        },

And here is the blanketjs wrapper:

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); 

The src: watchFiles.mochaTests is just a variable above holding an array of my tests to run.

anotherdave
  • 6,670
  • 4
  • 31
  • 62
iQ.
  • 3,263
  • 5
  • 33
  • 54

1 Answers1

4

In case someone ever comes here, I had resolved this using a config such as this:

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

The key point is the 'data-cover-never' option that specifies what to filter out based on the pattern.

iQ.
  • 3,263
  • 5
  • 33
  • 54