Skip to content

Commit

Permalink
Adjusted fix for OverZealous#13 to only error if tasks are duplicated…
Browse files Browse the repository at this point in the history
… in parallel, rather than in a series.
  • Loading branch information
OverZealous committed Oct 2, 2014
1 parent e9151cf commit f95f001
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

var colors = require('chalk');

function verifyTaskSets(gulp, taskSets, skipArrays, foundTasks) {
function verifyTaskSets(gulp, taskSets, skipArrays) {
if(taskSets.length === 0) {
throw new Error('No tasks were provided to run-sequence');
}
foundTasks = foundTasks || {};
var foundTasks = {};
taskSets.forEach(function(t) {
var isTask = typeof t === "string",
isArray = !skipArrays && Array.isArray(t);
Expand All @@ -18,7 +18,7 @@ function verifyTaskSets(gulp, taskSets, skipArrays, foundTasks) {
if(isTask && !gulp.hasTask(t)) {
throw new Error("Task "+t+" is not configured as a task on gulp. If this is a submodule, you may need to use require('run-sequence').use(gulp).");
}
if(isTask) {
if(skipArrays && isTask) {
if(foundTasks[t]) {
throw new Error("Task "+t+" is listed more than once. This is probably a typo.");
}
Expand Down
40 changes: 26 additions & 14 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,32 @@ describe('runSequence', function() {
});
});

describe('Duplicate Tasks', function() {
it('should not error if a task is duplicated across tasks-lists', function() {
(function() {
runSequence(['task1', 'task2'], ['task3', 'task1']);
}).should.not.throw();
task1.counter.should.eql(4);
task2.counter.should.eql(2);
task3.counter.should.eql(3);
});

it('should not error if a task is duplicated serially', function() {
(function() {
runSequence('task1', 'task2', 'task1');
}).should.not.throw();
task1.counter.should.eql(3);
task2.counter.should.eql(2);
});

it('should error if a task is duplicated within a parallel array', function() {
(function() {
runSequence(['task1', 'task1'], 'task2');
}).should.throw(/more than once/i);
shouldNotRunAnything();
});
});

function shouldNotRunAnything() {
task1.counter.should.eql(-1);
task2.counter.should.eql(-1);
Expand Down Expand Up @@ -203,20 +229,6 @@ describe('runSequence', function() {
}).should.throw(/not configured/i);
shouldNotRunAnything();
});

it('should error if a task is duplicated', function() {
(function() {
runSequence(['task1', 'task1'], 'task2');
}).should.throw(/more than once/i);
shouldNotRunAnything();
});

it('should error if a task is duplicated across tasks-lists', function() {
(function() {
runSequence(['task1', 'task2'], 'task1');
}).should.throw(/more than once/i);
shouldNotRunAnything();
});
});

});

0 comments on commit f95f001

Please sign in to comment.