Skip to content

Commit

Permalink
fix(watch): handle array of tasks when no options
Browse files Browse the repository at this point in the history
If second parameter is array, assume no options provided.
  • Loading branch information
laurelnaiad committed Mar 29, 2014
1 parent 9f5f997 commit 2faf45f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Gulp.prototype.run = function() {
Gulp.prototype.src = vfs.src;
Gulp.prototype.dest = vfs.dest;
Gulp.prototype.watch = function(glob, opt, fn) {
if (typeof opt === 'function') {
if (typeof opt === 'function' || Array.isArray(opt)) {
fn = opt;
opt = null;
}
Expand Down
38 changes: 38 additions & 0 deletions test/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,43 @@ describe('gulp', function() {
});
});

it('should run many tasks: no options', function(done) {
// arrange
var tempFile = path.join(outpath, 'watch-many-tasks-no-options.txt');
var task1 = 'task1';
var task2 = 'task2';
var task3 = 'task3';
var a = 0;
var timeout = writeTimeout * 2.5;

fs.writeFile(tempFile, tempFileContent, function() {

gulp.task(task1, function() {
a++;
});
gulp.task(task2, function() {
a += 10;
});
gulp.task(task3, function() {
throw new Error("task3 called!");
});

// assert
setTimeout(function() {
a.should.equal(11); // task1 and task2

gulp.reset();
watcher.end();
done();
}, timeout);

// it works if it calls the task
var watcher = gulp.watch(tempFile, [task1,task2]);

// act: change file
writeFileWait(tempFile, tempFileContent+' changed');
});
});

});
});

0 comments on commit 2faf45f

Please sign in to comment.