From 9ca708b7aa44c4056682d54bc75b711a8ac23b1f Mon Sep 17 00:00:00 2001 From: Stefan Baumgartner Date: Sun, 5 Apr 2015 22:18:25 +0200 Subject: [PATCH] checking for watch parameters, fixes #1002 --- index.js | 6 ++++++ test/watch.js | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/index.js b/index.js index 6969fa141..8c01de350 100644 --- a/index.js +++ b/index.js @@ -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; diff --git a/test/watch.js b/test/watch.js index 335ca771a..f29d1857a 100644 --- a/test/watch.js +++ b/test/watch.js @@ -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(); + } + }); + }); });