Skip to content

Commit

Permalink
Fix: Throw better error when watch parameters are invalid (fixes #1002)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddprrt authored and phated committed Dec 31, 2017
1 parent a27311c commit 0f4776b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ 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 ' +
'a function (optionally generated by using gulp.parallel ' +
'or gulp.series)');
}

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 a function (optionally generated by using gulp.parallel or gulp.series)');
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 a function (optionally generated by using gulp.parallel or gulp.series)');
done();
}
});

});
});

0 comments on commit 0f4776b

Please sign in to comment.