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 98b9504 commit 409f19a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions index.js
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
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 409f19a

Please sign in to comment.