pocesar/grunt-mocha-istanbul

Issues with istanbulOptions

Closed this issue · 4 comments

Here is my config:

        isparta: {
            src: [
                'public/js/**/__tests__/**/*.es6'
            ],
            options: {
                scriptPath: require.resolve('isparta/bin/isparta'),
                mochaOptions: ['-r babel/register', '-R dot', '--recursive'],
                istanbulOptions: ['--include="**/*.es6"'],
                reportFormats: ['text']
            }

When I add the istanbulOptions and run the task it never completes. When I remove it it works fine (though it's missing that crucial flag). When I run with --verbose it outputs a command, which when run in the shell works as expected.

.....

Now I'm pretty sure this isn't your fault. I tried passing the arguments you give to grunt.util.spawn to node directly in this way:

var out = spawn(cmd, args, {
    env: process.env,
    cwd: process.cwd()
});

And in fact it didn't work. It still showed a 1 on the exit code, but the stdout and stderr reported nothing.

When I switched this to use child_process.execSync it worked totally normal as expected.

      var out = require('child_process').execSync(cmd + ' ' + args.join(' '), {
          env: process.env,
          cwd: process.cwd()
          // stdio: options.quiet ? 'ignore' : 'inherit'
      });

Any chance I'm defining the options incorrectly or does node's spawn have an issue with the -- for separating arguments?

usually, you need to separate anything that has a space in it. so it would become

        isparta: {
            src: [
                'public/js/**/__tests__/**/*.es6'
            ],
            options: {
                scriptPath: require.resolve('isparta/bin/isparta'),
                mochaOptions: ['-r','babel/register', '-R','dot', '--recursive'],
                istanbulOptions: ['--include','**/*.es6'],
                reportFormats: ['text']
            }

let me know if works for you. it's a known (broken) feature of child_process spawn

Great idea, but sadly no that didn't magically fix it.

Here's a stack-trace and some debugging info I get (not much help):

{ '0': [Error],
  '1': { stdout: '', stderr: '', code: 1, toString: [Function] },
  '2': 1 }

Error
    at callDone (/Users/jamuferguson/dev/paypal/p2pnodeweb/node_modules/grunt-legacy-util/index.js:159:56)
    at ChildProcess.<anonymous> (/Users/jamuferguson/dev/paypal/p2pnodeweb/node_modules/grunt-legacy-util/index.js:198:5)
    at ChildProcess.emit (events.js:110:17)
    at maybeClose (child_process.js:1015:16)
    at Process.ChildProcess._handle.onexit (child_process.js:1087:5)

try this instead

        isparta: {
            src: [
                'public/js/**/__tests__/**/*.es6'
            ],
            options: {
                scriptPath: require.resolve('isparta/bin/isparta'),
                mochaOptions: ['-r','babel/register', '-R','dot', '--recursive'],
                istanbulOptions: ['--include=**/*.es6'],
                reportFormats: ['text']
            }

if you try to call it directly from command line, does it work? (without using grunt)

like ./node_modules/isparta/bin/isparta --include=**/*.es6 -- mocha -r babel/register -R dot --recursive public/js/**/__tests__/**/*.es6

yay you figured it out (p.s your earlier one worked as well) (i hadn't followed it carefully enough)