diff --git a/index.js b/index.js index 4674f81..a46d513 100644 --- a/index.js +++ b/index.js @@ -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); @@ -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."); } diff --git a/test/main.js b/test/main.js index af9f14e..b91f5d8 100644 --- a/test/main.js +++ b/test/main.js @@ -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); @@ -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(); - }); }); }); \ No newline at end of file