From 8de7b2a9fed83281bfe96f7e76a5a5036ec11c34 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Wed, 20 May 2020 07:34:05 +0200 Subject: [PATCH] Fix: Avoid false positive reporting of sync tasks on errors (fixes #162) (#204) --- lib/versioned/^4.0.0/log/sync-task.js | 8 +++++- .../gulpfiles/gulpfile-parallel-failure.js | 18 +++++++++++++ test/non-completing-tasks.js | 27 +++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/gulpfiles/gulpfile-parallel-failure.js diff --git a/lib/versioned/^4.0.0/log/sync-task.js b/lib/versioned/^4.0.0/log/sync-task.js index 08b78d44..fb95b0b1 100644 --- a/lib/versioned/^4.0.0/log/sync-task.js +++ b/lib/versioned/^4.0.0/log/sync-task.js @@ -35,12 +35,18 @@ function clear(e) { delete tasks[e.uid]; } +function clearAll() { + tasks = {}; +} + function logSyncTask(gulpInst) { process.once('exit', warn); gulpInst.on('start', start); gulpInst.on('stop', clear); - gulpInst.on('error', clear); + // When not running in --continue mode, we need to clear everything on error to avoid + // false positives. + gulpInst.on('error', process.env.UNDERTAKER_SETTLE === 'true' ? clear : clearAll); } module.exports = logSyncTask; diff --git a/test/fixtures/gulpfiles/gulpfile-parallel-failure.js b/test/fixtures/gulpfiles/gulpfile-parallel-failure.js new file mode 100644 index 00000000..c5c2079c --- /dev/null +++ b/test/fixtures/gulpfiles/gulpfile-parallel-failure.js @@ -0,0 +1,18 @@ +'use strict'; + +var gulp = require('gulp'); + +function noop(cb) { + cb(); +} + +function errorFunction(cb) { + cb(new Error('Error!')); +} + +function notCompleting1() { + // Callback is not called +} + +gulp.task('default', gulp.parallel(errorFunction, noop)); +gulp.task('broken', gulp.parallel(errorFunction, noop, notCompleting1)); diff --git a/test/non-completing-tasks.js b/test/non-completing-tasks.js index afc36337..e7a521e3 100644 --- a/test/non-completing-tasks.js +++ b/test/non-completing-tasks.js @@ -33,4 +33,31 @@ describe('sync-task', function() { done(); }); }); + + it('should not log false positive in case of parallel failure', function(done) { + runner({ verbose: false }) + .gulp('--gulpfile ./test/fixtures/gulpfiles/gulpfile-parallel-failure.js') + .run(function(err, stdout) { + expect(stdout).toExclude('The following tasks did not complete:'); + done(); + }); + }); + + it('should not log false positive in case of parallel failure in continue mode', function(done) { + runner({ verbose: false }) + .gulp('--continue --gulpfile ./test/fixtures/gulpfiles/gulpfile-parallel-failure.js') + .run(function(err, stdout) { + expect(stdout).toExclude('The following tasks did not complete:'); + done(); + }); + }); + + it('should log non-completing task alongside a failure in continue mode', function(done) { + runner({ verbose: false }) + .gulp('--continue --gulpfile ./test/fixtures/gulpfiles/gulpfile-parallel-failure.js broken') + .run(function(err, stdout) { + expect(stdout).toInclude('The following tasks did not complete: broken, notCompleting1\n'); + done(); + }); + }); });