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 1 commit
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
12 changes: 12 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,11 @@ function runSequence(gulp) {
}

function finish(e) {
if (finished) return;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finished appears to never be set.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, please match the style of this codebase, no spaces between language keywords (if, catch, etc) and the parentheses.


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 +101,12 @@ function runSequence(gulp) {
}
}

function onGulpError(e) {
if (e.message === 'orchestration aborted') {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove space

finish(e);
}
};

function runNextSet() {
if(taskSets.length) {
var command = taskSets.shift();
Expand All @@ -113,6 +124,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) {
const stopTask = gulp.task('stopTask', function() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To ensure backwards compatibility, since this codebase is older, let's leave this as a var. (I struggle with it too, since I've been writing const and let for quite a while now.)

if (stopTask.shouldStop) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's several spaces between the keywords and parentheses in here.

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() {
});
});

});
});