Skip to content

Commit

Permalink
Fix: Avoid false positive reporting of sync tasks on errors (fixes #162
Browse files Browse the repository at this point in the history
…) (#204)
  • Loading branch information
stof authored and phated committed May 20, 2020
1 parent 8570b0c commit d827191
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/versioned/^4.0.0-alpha.1/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function execute(opts, env, config) {

var gulpInst = require(env.modulePath);
logEvents(gulpInst);
logSyncTask(gulpInst);
logSyncTask(gulpInst, opts);

// This is what actually loads up the gulpfile
var exported = require(env.configPath);
Expand Down
2 changes: 1 addition & 1 deletion lib/versioned/^4.0.0-alpha.2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function execute(opts, env, config) {

var gulpInst = require(env.modulePath);
logEvents(gulpInst);
logSyncTask(gulpInst);
logSyncTask(gulpInst, opts);

// This is what actually loads up the gulpfile
var exported = require(env.configPath);
Expand Down
2 changes: 1 addition & 1 deletion lib/versioned/^4.0.0/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function execute(opts, env, config) {

var gulpInst = require(env.modulePath);
logEvents(gulpInst);
logSyncTask(gulpInst);
logSyncTask(gulpInst, opts);

// This is what actually loads up the gulpfile
var exported = require(env.configPath);
Expand Down
10 changes: 8 additions & 2 deletions lib/versioned/^4.0.0/log/sync-task.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,18 @@ function clear(e) {
delete tasks[e.uid];
}

function logSyncTask(gulpInst) {
function clearAll() {
tasks = {};
}

function logSyncTask(gulpInst, opts) {

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', opts.continue ? clear : clearAll);
}

module.exports = logSyncTask;
18 changes: 18 additions & 0 deletions test/fixtures/gulpfiles/gulpfile-parallel-failure.js
Original file line number Diff line number Diff line change
@@ -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));
27 changes: 27 additions & 0 deletions test/non-completing-tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});

0 comments on commit d827191

Please sign in to comment.