Skip to content

Commit ac28ac3

Browse files
committed
fix(gulp): continue watching when tasks throw
Closes #1915
1 parent 8aa3fcf commit ac28ac3

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

tools/build/watch.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function watch(globs, opts, tasks) {
4949
watcher.close = function() {
5050
if (timeoutId !== null) clearTimeout(timeoutId);
5151
close();
52-
}
52+
};
5353

5454
var eventsRecorded = 0; // Number of events recorded
5555
var timeoutId = null; // If non-null, event capture window is open
@@ -75,13 +75,15 @@ function watch(globs, opts, tasks) {
7575
}
7676

7777
function tasksDone(err) {
78-
if (err) throw err;
7978
if (eventsRecorded) {
8079
// eventsRecorded has increased during the run, run again on the next turn
8180
timeoutId = setTimeout(invokeCallback, 0);
8281
} else {
8382
timeoutId = null;
8483
}
84+
if (!useRunSequence && err) {
85+
console.log('Watch task error:', err.toString());
86+
}
8587
}
8688
}
8789

tools/build/watch.spec.js

+22
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,28 @@ describe('watch()', function() {
7272
});
7373

7474

75+
it('should continue to trigger callbacks if task throws', function() {
76+
var calls = 0;
77+
spyOn(console, 'log');
78+
function cb(done) {
79+
calls += 1;
80+
if (calls === 1) throw new Error('oops!');
81+
done();
82+
}
83+
84+
var watcher = watch('./$$fake_path/**/*', { delay: 10 }, cb);
85+
86+
watcher._emit('change', './$$fake_path/test1.txt');
87+
timeout.flush();
88+
expect(calls).toBe(1);
89+
expect(console.log).toHaveBeenCalledWith('Watch task error:', 'Error: oops!');
90+
91+
watcher._emit('change', './$$fake_path/test2.txt');
92+
timeout.flush();
93+
expect(calls).toBe(2);
94+
});
95+
96+
7597
it('should cancel pending callback if FSWatcher is closed', function() {
7698
var cb = jasmine.createSpy('callback');
7799
var watcher = watch('./$$fake_path/**/*', { delay: 10 }, cb);

0 commit comments

Comments
 (0)