title: Gulp: target to debug mocha tests
body: <p>I have a set of <a href="http://gulpjs.com/">gulp.js</a> targets for running my mocha tests that work like a charm running through <a href="https://github.com/sindresorhus/gulp-mocha">gulp-mocha</a>. Question: how do I debug my mocha tests running through gulp? I would like to use something like <a href="https://github.com/node-inspector/node-inspector">node-inspector</a> to set break points in my src and test files to see what's going on. I am already able to accomplish this by calling node directly:</p>
  
  <pre><code>node --debug-brk node_modules/gulp/bin/gulp.js test
  </code></pre>
  
  <p>But I'd prefer a gulp target that wraps this for me, e.g.:</p>
  
  <pre><code>gulp.task('test-debug', 'Run unit tests in debug mode', function (cb) {
     // todo?
  });
  </code></pre>
  
  <p>Ideas? I want to avoid a <code>bash</code> script or some other separate file since I'm trying to create a reusable <code>gulpfile</code> with targets that are usable by someone who doesn't know gulp.</p>
  
  <p>Here is my current <code>gulpfile.js</code></p>
  
  <pre><code>// gulpfile.js
  var gulp = require('gulp'),
    mocha = require('gulp-mocha'),
    gutil = require('gulp-util'),
    help = require('gulp-help');
  
  help(gulp); // add help messages to targets
  
  var exitCode = 0;
  
  // kill process on failure
  process.on('exit', function () {
    process.nextTick(function () {
      var msg = "gulp '" + gulp.seq + "' failed";
      console.log(gutil.colors.red(msg));
      process.exit(exitCode);
    });
  });
  
  function testErrorHandler(err) {
    gutil.beep();
    gutil.log(err.message);
    exitCode = 1;
  }
  
  gulp.task('test', 'Run unit tests and exit on failure', function () {
    return gulp.src('./lib/*/test/**/*.js')
      .pipe(mocha({
        reporter: 'dot'
      }))
      .on('error', function (err) {
        testErrorHandler(err);
        process.emit('exit');
      });
  });
  
  gulp.task('test-watch', 'Run unit tests', function (cb) {
    return gulp.src('./lib/*/test/**/*.js')
      .pipe(mocha({
        reporter: 'min',
        G: true
      }))
      .on('error', testErrorHandler);
  });
  
  gulp.task('watch', 'Watch files and run tests on change', function () {
    gulp.watch('./lib/**/*.js', ['test-watch']);
  });
  </code></pre>