Skip to content

Commit d827191

Browse files
stofphated
authored andcommitted
Fix: Avoid false positive reporting of sync tasks on errors (fixes #162) (#204)
1 parent 8570b0c commit d827191

File tree

6 files changed

+56
-5
lines changed

6 files changed

+56
-5
lines changed

lib/versioned/^4.0.0-alpha.1/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function execute(opts, env, config) {
2929

3030
var gulpInst = require(env.modulePath);
3131
logEvents(gulpInst);
32-
logSyncTask(gulpInst);
32+
logSyncTask(gulpInst, opts);
3333

3434
// This is what actually loads up the gulpfile
3535
var exported = require(env.configPath);

lib/versioned/^4.0.0-alpha.2/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function execute(opts, env, config) {
3030

3131
var gulpInst = require(env.modulePath);
3232
logEvents(gulpInst);
33-
logSyncTask(gulpInst);
33+
logSyncTask(gulpInst, opts);
3434

3535
// This is what actually loads up the gulpfile
3636
var exported = require(env.configPath);

lib/versioned/^4.0.0/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function execute(opts, env, config) {
3030

3131
var gulpInst = require(env.modulePath);
3232
logEvents(gulpInst);
33-
logSyncTask(gulpInst);
33+
logSyncTask(gulpInst, opts);
3434

3535
// This is what actually loads up the gulpfile
3636
var exported = require(env.configPath);

lib/versioned/^4.0.0/log/sync-task.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,18 @@ function clear(e) {
3535
delete tasks[e.uid];
3636
}
3737

38-
function logSyncTask(gulpInst) {
38+
function clearAll() {
39+
tasks = {};
40+
}
41+
42+
function logSyncTask(gulpInst, opts) {
3943

4044
process.once('exit', warn);
4145
gulpInst.on('start', start);
4246
gulpInst.on('stop', clear);
43-
gulpInst.on('error', clear);
47+
// When not running in --continue mode, we need to clear everything on error to avoid
48+
// false positives.
49+
gulpInst.on('error', opts.continue ? clear : clearAll);
4450
}
4551

4652
module.exports = logSyncTask;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
3+
var gulp = require('gulp');
4+
5+
function noop(cb) {
6+
cb();
7+
}
8+
9+
function errorFunction(cb) {
10+
cb(new Error('Error!'));
11+
}
12+
13+
function notCompleting1() {
14+
// Callback is not called
15+
}
16+
17+
gulp.task('default', gulp.parallel(errorFunction, noop));
18+
gulp.task('broken', gulp.parallel(errorFunction, noop, notCompleting1));

test/non-completing-tasks.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,31 @@ describe('sync-task', function() {
3333
done();
3434
});
3535
});
36+
37+
it('should not log false positive in case of parallel failure', function(done) {
38+
runner({ verbose: false })
39+
.gulp('--gulpfile ./test/fixtures/gulpfiles/gulpfile-parallel-failure.js')
40+
.run(function(err, stdout) {
41+
expect(stdout).toExclude('The following tasks did not complete:');
42+
done();
43+
});
44+
});
45+
46+
it('should not log false positive in case of parallel failure in continue mode', function(done) {
47+
runner({ verbose: false })
48+
.gulp('--continue --gulpfile ./test/fixtures/gulpfiles/gulpfile-parallel-failure.js')
49+
.run(function(err, stdout) {
50+
expect(stdout).toExclude('The following tasks did not complete:');
51+
done();
52+
});
53+
});
54+
55+
it('should log non-completing task alongside a failure in continue mode', function(done) {
56+
runner({ verbose: false })
57+
.gulp('--continue --gulpfile ./test/fixtures/gulpfiles/gulpfile-parallel-failure.js broken')
58+
.run(function(err, stdout) {
59+
expect(stdout).toInclude('The following tasks did not complete: broken, notCompleting1\n');
60+
done();
61+
});
62+
});
3663
});

0 commit comments

Comments
 (0)