fix(gulp): continue watching when tasks throw

Closes #1915
This commit is contained in:
Brian Ford 2015-05-18 17:48:41 -07:00
parent 8aa3fcfb63
commit ac28ac324d
2 changed files with 26 additions and 2 deletions

View File

@ -49,7 +49,7 @@ function watch(globs, opts, tasks) {
watcher.close = function() {
if (timeoutId !== null) clearTimeout(timeoutId);
close();
}
};
var eventsRecorded = 0; // Number of events recorded
var timeoutId = null; // If non-null, event capture window is open
@ -75,13 +75,15 @@ function watch(globs, opts, tasks) {
}
function tasksDone(err) {
if (err) throw err;
if (eventsRecorded) {
// eventsRecorded has increased during the run, run again on the next turn
timeoutId = setTimeout(invokeCallback, 0);
} else {
timeoutId = null;
}
if (!useRunSequence && err) {
console.log('Watch task error:', err.toString());
}
}
}

View File

@ -72,6 +72,28 @@ describe('watch()', function() {
});
it('should continue to trigger callbacks if task throws', function() {
var calls = 0;
spyOn(console, 'log');
function cb(done) {
calls += 1;
if (calls === 1) throw new Error('oops!');
done();
}
var watcher = watch('./$$fake_path/**/*', { delay: 10 }, cb);
watcher._emit('change', './$$fake_path/test1.txt');
timeout.flush();
expect(calls).toBe(1);
expect(console.log).toHaveBeenCalledWith('Watch task error:', 'Error: oops!');
watcher._emit('change', './$$fake_path/test2.txt');
timeout.flush();
expect(calls).toBe(2);
});
it('should cancel pending callback if FSWatcher is closed', function() {
var cb = jasmine.createSpy('callback');
var watcher = watch('./$$fake_path/**/*', { delay: 10 }, cb);