Skip to content

Commit

Permalink
Merge pull request #1007 from ddprrt/4.0
Browse files Browse the repository at this point in the history
checking for watch parameters, fixes #1002
  • Loading branch information
phated committed Apr 15, 2015
2 parents 2d61254 + 205af3e commit c98b07a
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 c98b07a

Please sign in to comment.