8000 Fix: Throw better error when watch parameters are invalid (fixes #1002) · gulpjs/gulp@409f19a · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 409f19a

Browse files
ddprrtphated
authored andcommitted
Fix: Throw better error when watch parameters are invalid (fixes #1002)
1 parent 98b9504 commit 409f19a

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ Gulp.prototype.src = vfs.src;
1313
Gulp.prototype.dest = vfs.dest;
1414
Gulp.prototype.symlink = vfs.symlink;
1515
Gulp.prototype.watch = function(glob, opt, task) {
16+
if (typeof opt === 'string' || typeof task === 'string' ||
17+
Array.isArray(opt) || Array.isArray(task)) {
18+
throw new Error('watching ' + glob + ': watch task has to be ' +
19+
'a function (optionally generated by using gulp.parallel ' +
20+
'or gulp.series)');
21+
}
22+
1623
if (typeof opt === 'function') {
1724
task = opt;
1825
opt = null;

test/watch.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,5 +126,29 @@ describe('gulp', function() {
126126
updateTempFile(tempFile);
127127
});
128128

129+
it('should throw an error: passed parameter (string) is not a function', function(done) {
130+
var tempFile = path.join(outpath, 'empty.txt');
131+
132+
createTempFile(tempFile);
133+
try {
134+
gulp.watch(tempFile, 'task1');
135+
} catch (err) {
136+
err.message.should.equal('watching ' + tempFile + ': watch task has to be a function (optionally generated by using gulp.parallel or gulp.series)');
137+
done();
138+
}
139+
});
140+
141+
it('should throw an error: passed parameter (array) is not a function', function(done) {
142+
var tempFile = path.join(outpath, 'empty.txt');
143+
144+
createTempFile(tempFile);
145+
try {
146+
gulp.watch(tempFile, ['task1']);
147+
} catch (err) {
148+
err.message.should.equal('watching ' + tempFile + ': watch task has to be a function (optionally generated by using gulp.parallel or gulp.series)');
149+
done();
150+
}
151+
});
152+
129153
});
130154
});

0 commit comments

Comments
 (0)
0