Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
122
rated 0 times [  123] [ 1]  / answers: 1 / hits: 11359  / 11 Years ago, thu, february 6, 2014, 12:00:00

I may be missing something extremely obvious but I can't get gulp-mocha to catch errors, causing my gulp watch task to end everytime I have a failing test.



It's a very simple set up:



gulp.task(watch, [build], function () {
gulp.watch([paths.scripts, paths.tests], [test]);
});

gulp.task(test, function() {
return gulp.src(paths.tests)
.pipe(mocha({ reporter: spec }).on(error, gutil.log));
});


Alternatively, putting the handler on the entire stream also gives the same problem:



gulp.task(test, function() {
return gulp.src(paths.tests)
.pipe(mocha({ reporter: spec }))
.on(error, gutil.log);
});


I've also tried using plumber, combine and gulp-batch to no avail, so I guess I'm overlooking something trivial.



Gist: http://gist.github.com/RoyJacobs/b518ebac117e95ff1457


More From » mocha.js

 Answers
2

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.


[#47992] Wednesday, February 5, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ellisw

Total Points: 625
Total Questions: 92
Total Answers: 88

Location: Kazakhstan
Member since Mon, Sep 26, 2022
2 Years ago
ellisw questions
Mon, Aug 23, 21, 00:00, 3 Years ago
Fri, Nov 20, 20, 00:00, 4 Years ago
Sat, Jun 20, 20, 00:00, 4 Years ago
Tue, Apr 21, 20, 00:00, 4 Years ago
;