0

I am using gulp and mocha to run unit tests which is part of a gulp workflow to run my reactjs app. The unit test works:

gulp.task('mocha', function () {
    return gulp
        .src(['test/*.js'])

        .pipe(mocha({
            compilers: {
                js: babel
            }
        })
})

However if the unit test is broken I would like to exit the whole gulp workflow. How can I do this?

bier hier
  • 20,970
  • 42
  • 97
  • 166

2 Answers2

0

You could try to just kill the process and restarting it when you want? Prehaps i do not fully understand your question, if so please ellaborate. In cmd where you run the gulpscript you can press CTRL + C, and than Y to affirm. This stops the current script.

DGRFDSGN
  • 575
  • 1
  • 8
  • 20
0

Mocha runs the tests. Gulp simply groups files, folder locations and pipe invokes mocha with this grouped information. What you are asking for is for a mechanism for mocha to communicate back to gulp the test results instead of its stdout if I read your question correctly. gulp automatically exits when mocha exits but if it does not then either you have a watch task or there is a allback in your gulp file that has not been resolved or this issue - [https://github.com/sindresorhus/gulp-mocha/issues/1][1]

You can use

.on('error', process.exit.bind(process, 1))

to check if the process exits

Or, if it is a callback issue, resolve the call with a done()

gulp.task('taskname', function (done) {
    gulp.src('test/testfile.js')
        .pipe(gulpmocha(),setTimeout(function() {
            done(null);
    }, 5000))
    .on('error', process.exit.bind(process, 1))
});
user2347763
  • 469
  • 2
  • 10