You need to ignore ‘error’ and always emit ‘end’ to make ‘gulp.watch’ work.
function handleError(err) {
console.log(err.toString());
this.emit('end');
}
gulp.task("test", function() {
return gulp.src(paths.tests)
.pipe(mocha({ reporter: "spec" })
.on("error", handleError));
});
This makes ‘gulp test’ to always return ‘0’ which is problematic for Continuous Integration, but I think we have no choice at this time.