Consider this simple async gulp task (this is obviously not a real-life task but nicely illustrates a general problem of marking async tests as failed):
gulp.task('foo', function (done) {
setTimeout(function () {
//HERE: how to fail the gulp run and have it exit wit non-zero status?
}, 1000);
});
I would like to know how to mark the foo task as failed so Gulp aborts the build and return non-zero exit code status to the shell. The things I've tried:
done(1) - finishes the task but gulp exists with code 0done(new Error(fail)) - finishes the task but gulp exists with code 0throw new Error(fail) - does the trick but is seems "a bit brutal"What would be an idiomatic way of marking such an async task as failed?
It turned out to be a bug in the gulp itself that was fixed in the version 3.8.4 via https://github.com/gulpjs/gulp/commit/d8d7542f58046f15d88795e3c48f952f54a02c3c
Starting from 3.8.4 one can write:
gulp.task('foo', function (done) {
setTimeout(function () {
done('error');
}, 1000);
});
and have gulp properly exiting process with the return status 1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With