Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle orchestration aborted events #97

Merged
merged 5 commits into from Sep 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions index.js
Expand Up @@ -54,6 +54,8 @@ function runSequence(gulp) {
var callBack = typeof taskSets[taskSets.length - 1] === 'function' ? taskSets.pop() : false;
var currentTaskSet;

var finished;

if(options().ignoreUndefinedTasks) {
// ignore missing tasks
taskSets = filterArray(taskSets)
Expand All @@ -67,8 +69,12 @@ function runSequence(gulp) {
}

function finish(e) {
if(finished) return;
finished = true;

gulp.removeListener('task_stop', onTaskEnd);
gulp.removeListener('task_err', onError);
gulp.removeListener('err', onGulpError);

var error;
if(e && e.err) {
Expand Down Expand Up @@ -96,6 +102,17 @@ function runSequence(gulp) {
}
}

function onGulpError(e) {
// In the case that you call gulp.stop after a successful run,
// we will not recieve a task_err or task_stop event. This callback
// will finish the run sequence execution in case of an 'orchestration aborted'
// even coming from gulp's global error handler. That event is fired in when
// gulp.stop is called.
if(e.message === 'orchestration aborted') {
finish(e);
}
};

function runNextSet() {
if(taskSets.length) {
var command = taskSets.shift();
Expand All @@ -113,6 +130,7 @@ function runSequence(gulp) {

gulp.on('task_stop', onTaskEnd);
gulp.on('task_err', onError);
gulp.on('err', onGulpError);

runNextSet();
}
Expand Down
36 changes: 35 additions & 1 deletion test/main.js
Expand Up @@ -260,6 +260,40 @@ describe('runSequence', function() {

called.should.eql(true);
})

it('should pass error if gulp execution halted in second execution', function(done) {
var stopTask = gulp.task('stopTask', function() {
if(stopTask.shouldStop) {
gulp.stop();
}
});

stopTask.shouldStop = false;

var outerTask = gulp.task('outerTask', function(cb) {
runSequence('task2', ['stopTask', 'task3'], function(err) {
if(stopTask.shouldStop) {
try {
should(err).be.ok;
err.message.should.equal('orchestration aborted');
} catch(e) {
cb();
return done(e);
}
cb();
done();
} else {
cb();
}
});
});

gulp.start('outerTask', function() {
stopTask.shouldStop = true;
task3.shouldPause = true;
gulp.start('outerTask');
});
})
});

describe('Options', function() {
Expand All @@ -275,4 +309,4 @@ describe('runSequence', function() {
});
});

});
});