Skip to content

Commit

Permalink
Fix: Exit with code 1 when incomplete tasks are detected on node 0.11…
Browse files Browse the repository at this point in the history
…+ (ref gulpjs/gulp#2081) (#145)
  • Loading branch information
barbogast authored and phated committed Jan 22, 2018
1 parent 1ba6095 commit f57134a
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/versioned/^4.0.0/log/sync-task.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ function warn() {
return tasks[key];
}).join(', ');

process.exitCode = 1;

log.warn(
ansi.red('The following tasks did not complete:'),
ansi.cyan(taskNames)
Expand Down
2 changes: 1 addition & 1 deletion test/expected/flags-tasks-json.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"label":"gulp-cli/test/fixtures/gulpfiles","nodes":[{"label":"test1","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"noop","type":"function","nodes":[]}]}]},{"label":"test2","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"test1","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"noop","type":"function","nodes":[]}]}]},{"label":"noop","type":"function","nodes":[]}]}]},{"label":"test3","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"described","type":"function","nodes":[]}]}]},{"label":"test4","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"errorFunction","type":"function","nodes":[]},{"label":"anon","type":"function","nodes":[]}]}]},{"label":"test5","nodes":[],"type":"task"},{"label":"test6","nodes":[],"type":"task"},{"label":"default","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"test1","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"noop","type":"function","nodes":[]}]}]},{"label":"test3","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"described","type":"function","nodes":[]}]}]},{"label":"noop","type":"function","nodes":[]}]}]}]}
{"label":"gulp-cli/test/fixtures/gulpfiles","nodes":[{"label":"test1","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"noop","type":"function","nodes":[]}]}]},{"label":"test2","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"test1","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"noop","type":"function","nodes":[]}]}]},{"label":"noop","type":"function","nodes":[]}]}]},{"label":"test3","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"described","type":"function","nodes":[]}]}]},{"label":"test4","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"errorFunction","type":"function","nodes":[]},{"label":"anon","type":"function","nodes":[]}]}]},{"label":"test5","nodes":[],"type":"task"},{"label":"test6","nodes":[],"type":"task"},{"label":"test7","nodes":[],"type":"task"},{"label":"test8","nodes":[],"type":"task"},{"label":"default","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"test1","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"noop","type":"function","nodes":[]}]}]},{"label":"test3","type":"task","nodes":[{"label":"<series>","type":"function","branch":true,"nodes":[{"label":"described","type":"function","nodes":[]}]}]},{"label":"noop","type":"function","nodes":[]}]}]}]}
2 changes: 2 additions & 0 deletions test/expected/flags-tasks-simple.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ test3
test4
test5
test6
test7
test8
default
4 changes: 3 additions & 1 deletion test/expected/flags-tasks.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ gulp-cli/test/fixtures/gulpfiles
│ ├── errorFunction
│ └── anon
├── test5
└── test6
├── test6
├── test7
└── test8
11 changes: 11 additions & 0 deletions test/fixtures/gulpfiles/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ function errorFunction() {
function anon(cb) {
cb();
}

function notCompleting1() {
// Callback is not called
}

function notCompleting2() {
// Callback is not called
}

described.description = 'description';

gulp.task('test1', gulp.series(noop));
Expand All @@ -28,5 +37,7 @@ gulp.task('test3', gulp.series(described));
gulp.task('test4', gulp.series(errorFunction, anon));
gulp.task('test5', delayed);
gulp.task('test6', noop);
gulp.task('test7', notCompleting1);
gulp.task('test8', notCompleting2);

gulp.task('default', gulp.series('test1', 'test3', noop));
36 changes: 36 additions & 0 deletions test/non-completing-tasks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

var expect = require('expect');
var eraseTime = require('gulp-test-tools').eraseTime;
var runner = require('gulp-test-tools').gulpRunner;


describe('sync-task', function() {
it('should return error code 1 if any tasks did not complete', function(done) {
// The exit code is set to 1 by setting process.exitCode = 1 which is only supported from nodejs 0.11 on
if (process.version.slice(0, 5) === 'v0.10') {
this.skip();
}

runner({ verbose: false })
.chdir('test/fixtures/gulpfiles')
.gulp('test6 test7 test8')
.run(function(err) {
expect(err).toNotEqual(null);
expect(err.code).toEqual(1);
done();
});
});

it('should log tasks which did not complete', function(done) {
runner({ verbose: false })
.chdir('test/fixtures/gulpfiles')
.gulp('test6 test7 test8')
.run(function(err, stdout) {
var lines = stdout.split('\n');
expect(lines.length).toEqual(8);
expect(eraseTime(lines[5])).toEqual('The following tasks did not complete: test7, test8');
done();
});
});
});

0 comments on commit f57134a

Please sign in to comment.