Skip to content

Commit

Permalink
checking for watch parameters, fixes #1002
Browse files Browse the repository at this point in the history
  • Loading branch information
ddprrt authored and phated committed Jun 1, 2015
1 parent 2259369 commit 9ca708b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ Gulp.prototype.src = vfs.src;
Gulp.prototype.dest = vfs.dest;
Gulp.prototype.symlink = vfs.symlink;
Gulp.prototype.watch = function(glob, opt, task) {
if (typeof opt === 'string' || typeof task === 'string' ||
Array.isArray(opt) || Array.isArray(task)) {
throw new Error('watching ' + glob + ': watch task has to be ' +
'gulp.series, gulp.parallel or a function');
}

if (typeof opt === 'function') {
task = opt;
opt = null;
Expand Down
24 changes: 24 additions & 0 deletions test/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,29 @@ describe('gulp', function() {
updateTempFile(tempFile);
});

it('should throw an error: passed parameter (string) is not a function', function(done) {
var tempFile = path.join(outpath, 'empty.txt');

createTempFile(tempFile);
try {
gulp.watch(tempFile, 'task1');
} catch (err) {
err.message.should.equal('watching ' + tempFile + ': watch task has to be gulp.series, gulp.parallel or a function');
done();
}
});

it('should throw an error: passed parameter (array) is not a function', function(done) {
var tempFile = path.join(outpath, 'empty.txt');

createTempFile(tempFile);
try {
gulp.watch(tempFile, ['task1']);
} catch (err) {
err.message.should.equal('watching ' + tempFile + ': watch task has to be gulp.series, gulp.parallel or a function');
done();
}
});

});
});

0 comments on commit 9ca708b

Please sign in to comment.