Skip to content

Commit

Permalink
Cloned input arrays to prevent modification of passed-in values, foun…
Browse files Browse the repository at this point in the history
  • Loading branch information
OverZealous committed Nov 19, 2014
1 parent c8e8a60 commit e36a606
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ function verifyTaskSets(gulp, taskSets, skipArrays) {
}

function runSequence(gulp) {
var taskSets = Array.prototype.slice.call(arguments, 1),
// Slice and dice the input to prevent modification of parallel arrays.
var taskSets = Array.prototype.slice.call(arguments, 1).map(function(task) {
return Array.isArray(task) ? task.slice() : task;
}),
callBack = typeof taskSets[taskSets.length-1] === 'function' ? taskSets.pop() : false,
currentTaskSet,

Expand Down
8 changes: 8 additions & 0 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ describe('runSequence', function() {
})
});

describe('Input Array Handling', function() {
it('should not modify passed-in parallel task arrays', function() {
var taskArray = ['task1', 'task2'];
runSequence(taskArray);
taskArray.should.eql(['task1', 'task2']);
});
});

describe('Asynchronous Tasks', function() {
it('should run a single task', function() {
task1.shouldPause = true;
Expand Down

0 comments on commit e36a606

Please sign in to comment.