Skip to content

Commit 2155560

Browse files
memoryholeOverZealous
authored andcommittedSep 19, 2017
handle orchestration aborted events (#97)
Handle orchestration aborted events
1 parent 066b8c6 commit 2155560

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed
 

‎index.js

+18
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ function runSequence(gulp) {
5454
var callBack = typeof taskSets[taskSets.length - 1] === 'function' ? taskSets.pop() : false;
5555
var currentTaskSet;
5656

57+
var finished;
58+
5759
if(options().ignoreUndefinedTasks) {
5860
// ignore missing tasks
5961
taskSets = filterArray(taskSets)
@@ -67,8 +69,12 @@ function runSequence(gulp) {
6769
}
6870

6971
function finish(e) {
72+
if(finished) return;
73+
finished = true;
74+
7075
gulp.removeListener('task_stop', onTaskEnd);
7176
gulp.removeListener('task_err', onError);
77+
gulp.removeListener('err', onGulpError);
7278

7379
var error;
7480
if(e && e.err) {
@@ -96,6 +102,17 @@ function runSequence(gulp) {
96102
}
97103
}
98104

105+
function onGulpError(e) {
106+
// In the case that you call gulp.stop after a successful run,
107+
// we will not recieve a task_err or task_stop event. This callback
108+
// will finish the run sequence execution in case of an 'orchestration aborted'
109+
// even coming from gulp's global error handler. That event is fired in when
110+
// gulp.stop is called.
111+
if(e.message === 'orchestration aborted') {
112+
finish(e);
113+
}
114+
};
115+
99116
function runNextSet() {
100117
if(taskSets.length) {
101118
var command = taskSets.shift();
@@ -113,6 +130,7 @@ function runSequence(gulp) {
113130

114131
gulp.on('task_stop', onTaskEnd);
115132
gulp.on('task_err', onError);
133+
gulp.on('err', onGulpError);
116134

117135
runNextSet();
118136
}

‎test/main.js

+35-1
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,40 @@ describe('runSequence', function() {
260260

261261
called.should.eql(true);
262262
})
263+
264+
it('should pass error if gulp execution halted in second execution', function(done) {
265+
var stopTask = gulp.task('stopTask', function() {
266+
if(stopTask.shouldStop) {
267+
gulp.stop();
268+
}
269+
});
270+
271+
stopTask.shouldStop = false;
272+
273+
var outerTask = gulp.task('outerTask', function(cb) {
274+
runSequence('task2', ['stopTask', 'task3'], function(err) {
275+
if(stopTask.shouldStop) {
276+
try {
277+
should(err).be.ok;
278+
err.message.should.equal('orchestration aborted');
279+
} catch(e) {
280+
cb();
281+
return done(e);
282+
}
283+
cb();
284+
done();
285+
} else {
286+
cb();
287+
}
288+
});
289+
});
290+
291+
gulp.start('outerTask', function() {
292+
stopTask.shouldStop = true;
293+
task3.shouldPause = true;
294+
gulp.start('outerTask');
295+
});
296+
})
263297
});
264298

265299
describe('Options', function() {
@@ -275,4 +309,4 @@ describe('runSequence', function() {
275309
});
276310
});
277311

278-
});
312+
});

0 commit comments

Comments
 (0)
Please sign in to comment.