Mocha-Gulp JUnit Reporter: illegal operation on a directory, unlink

Hi All,

Trying to get a really nice CircleCI setup for a series of Node.JS modules. I’m following the instructions for importing test results into CircleCI, using gulp-mocha. Getting the following error in CircleCI

[20:24:11] Finished 'test' after 66 ms

events.js:141
      throw er; // Unhandled 'error' event
      ^
Error: EISDIR: illegal operation on a directory, unlink '/tmp/circle-junit.wxZdE3I'
    at Error (native)
    at Object.fs.unlinkSync (fs.js:932:18)
    at MochaJUnitReporter.<anonymous> (/home/ubuntu/domuso-loginclient/node_modules/mocha-junit-reporter/index.js:104:10)
    at emitNone (events.js:72:20)
    at Runner.emit (events.js:166:7)
    at start (/home/ubuntu/domuso-loginclient/node_modules/gulp-mocha/node_modules/mocha/lib/runner.js:783:10)
    at Runner.run (/home/ubuntu/domuso-loginclient/node_modules/gulp-mocha/node_modules/mocha/lib/runner.js:811:5)
    at Mocha.run (/home/ubuntu/domuso-loginclient/node_modules/gulp-mocha/node_modules/mocha/lib/mocha.js:502:17)
    at Domain.<anonymous> (/home/ubuntu/domuso-loginclient/node_modules/gulp-mocha/index.js:56:20)
    at Domain.run (domain.js:228:14)
    at Stream.<anonymous> (/home/ubuntu/domuso-loginclient/node_modules/gulp-mocha/index.js:54:5)
    at _end (/home/ubuntu/domuso-loginclient/node_modules/gulp-mocha/node_modules/through/index.js:65:9)
    at Stream.stream.end (/home/ubuntu/domuso-loginclient/node_modules/gulp-mocha/node_modules/through/index.js:74:5)
    at DestroyableTransform.onend (/home/ubuntu/domuso-loginclient/node_modules/gulp/node_modules/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:523:10)
    at DestroyableTransform.g (events.js:260:16)
    at emitNone (events.js:72:20)
npm ERR! Test failed.  See above for more details.

npm test returned exit code 1

Here’s the gulpfile.js

/**
 * From https://github.com/SBoudrias/gulp-istanbul.
 *
 * Created by timfulmer on 7/20/16.
 */
var gulp=require('gulp'),
  istanbul=require('gulp-istanbul'),
  mocha=require('gulp-mocha'),
  testDir=process.env.CIRCLE_TEST_REPORTS || './reports/junit/test-results.xml',
  coverageDir=process.env.CIRCLE_ARTIFACTS || './reports/coverage';
gulp.task('pre-test',() => {
  return gulp.src(['lib/**/*.js', 'index.js'])
    .pipe(istanbul())
    .pipe(istanbul.hookRequire());
});
gulp.task('test',['pre-test'],() => {
    gulp.src(['test/**/*.js'])
      .pipe(mocha({
        reporter:'mocha-junit-reporter',
        reporterOptions:{
          mochaFile:testDir
        }
      }))
      .pipe(mocha({
        reporter:'spec',
        reporterOptions:{
          mochaFile:testDir
        }
      }))
      .pipe(istanbul.writeReports({
        dir:coverageDir,
        reporters:['lcov','text-summary'],
        reportOpts:{dir:coverageDir}
      }))
      .pipe(istanbul.enforceThresholds({thresholds:{global:100}}));
});