Skip to content

Commit f57134a

Browse files
barbogastphated
authored andcommitted
Fix: Exit with code 1 when incomplete tasks are detected on node 0.11+ (ref gulpjs/gulp#2081) (#145)
1 parent 1ba6095 commit f57134a

File tree

6 files changed

+55
-2
lines changed

6 files changed

+55
-2
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ function warn() {
1616
return tasks[key];
1717
}).join(', ');
1818

19+
process.exitCode = 1;
20+
1921
log.warn(
2022
ansi.red('The following tasks did not complete:'),
2123
ansi.cyan(taskNames)

test/expected/flags-tasks-json.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +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":[]}]}]}]}
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":"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":[]}]}]}]}

test/expected/flags-tasks-simple.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ test3
44
test4
55
test5
66
test6
7+
test7
8+
test8
79
default

test/expected/flags-tasks.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ gulp-cli/test/fixtures/gulpfiles
2525
│ ├── errorFunction
2626
│ └── anon
2727
├── test5
28-
└── test6
28+
├── test6
29+
├── test7
30+
└── test8

test/fixtures/gulpfiles/gulpfile.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ function errorFunction() {
2020
function anon(cb) {
2121
cb();
2222
}
23+
24+
function notCompleting1() {
25+
// Callback is not called
26+
}
27+
28+
function notCompleting2() {
29+
// Callback is not called
30+
}
31+
2332
described.description = 'description';
2433

2534
gulp.task('test1', gulp.series(noop));
@@ -28,5 +37,7 @@ gulp.task('test3', gulp.series(described));
2837
gulp.task('test4', gulp.series(errorFunction, anon));
2938
gulp.task('test5', delayed);
3039
gulp.task('test6', noop);
40+
gulp.task('test7', notCompleting1);
41+
gulp.task('test8', notCompleting2);
3142

3243
gulp.task('default', gulp.series('test1', 'test3', noop));

test/non-completing-tasks.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict';
2+
3+
var expect = require('expect');
4+
var eraseTime = require('gulp-test-tools').eraseTime;
5+
var runner = require('gulp-test-tools').gulpRunner;
6+
7+
8+
describe('sync-task', function() {
9+
it('should return error code 1 if any tasks did not complete', function(done) {
10+
// The exit code is set to 1 by setting process.exitCode = 1 which is only supported from nodejs 0.11 on
11+
if (process.version.slice(0, 5) === 'v0.10') {
12+
this.skip();
13+
}
14+
15+
runner({ verbose: false })
16+
.chdir('test/fixtures/gulpfiles')
17+
.gulp('test6 test7 test8')
18+
.run(function(err) {
19+
expect(err).toNotEqual(null);
20+
expect(err.code).toEqual(1);
21+
done();
22+
});
23+
});
24+
25+
it('should log tasks which did not complete', function(done) {
26+
runner({ verbose: false })
27+
.chdir('test/fixtures/gulpfiles')
28+
.gulp('test6 test7 test8')
29+
.run(function(err, stdout) {
30+
var lines = stdout.split('\n');
31+
expect(lines.length).toEqual(8);
32+
expect(eraseTime(lines[5])).toEqual('The following tasks did not complete: test7, test8');
33+
done();
34+
});
35+
});
36+
});

0 commit comments

Comments
 (0)