From fabfd907354ad9783965a5cc2ed43117066ef5cb Mon Sep 17 00:00:00 2001 From: Benjamin Arbogast Date: Sat, 13 Jan 2018 18:54:26 +0100 Subject: [PATCH 1/7] Return exit code 1 when incomplete tasks are detected --- lib/versioned/^4.0.0/log/sync-task.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/versioned/^4.0.0/log/sync-task.js b/lib/versioned/^4.0.0/log/sync-task.js index 1932e89c..b46f6658 100644 --- a/lib/versioned/^4.0.0/log/sync-task.js +++ b/lib/versioned/^4.0.0/log/sync-task.js @@ -1,6 +1,7 @@ 'use strict'; var log = require('gulplog'); +var process = require('process'); var ansi = require('../../../shared/ansi'); var tasks = {}; @@ -16,6 +17,8 @@ function warn() { return tasks[key]; }).join(', '); + process.exitCode = 1; + log.warn( ansi.red('The following tasks did not complete:'), ansi.cyan(taskNames) From 74b167d5ff91f2ee73a8cd902eb3af2f11080d9d Mon Sep 17 00:00:00 2001 From: Benjamin Arbogast Date: Wed, 17 Jan 2018 08:43:30 +0100 Subject: [PATCH 2/7] Don't require process --- lib/versioned/^4.0.0/log/sync-task.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/versioned/^4.0.0/log/sync-task.js b/lib/versioned/^4.0.0/log/sync-task.js index b46f6658..08b78d44 100644 --- a/lib/versioned/^4.0.0/log/sync-task.js +++ b/lib/versioned/^4.0.0/log/sync-task.js @@ -1,7 +1,6 @@ 'use strict'; var log = require('gulplog'); -var process = require('process'); var ansi = require('../../../shared/ansi'); var tasks = {}; From e84bfc671a015eb1054ece81c315d87f34331866 Mon Sep 17 00:00:00 2001 From: Benjamin Arbogast Date: Wed, 17 Jan 2018 08:44:38 +0100 Subject: [PATCH 3/7] Add test case for sync-task.js --- test/expected/flags-tasks-json.json | 2 +- test/expected/flags-tasks-simple.txt | 2 ++ test/expected/flags-tasks.txt | 4 +++- test/fixtures/gulpfiles/gulpfile.js | 11 +++++++++++ test/lib/sync-task.js | 22 ++++++++++++++++++++++ 5 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 test/lib/sync-task.js diff --git a/test/expected/flags-tasks-json.json b/test/expected/flags-tasks-json.json index a9842b7e..2bbe3f2c 100644 --- a/test/expected/flags-tasks-json.json +++ b/test/expected/flags-tasks-json.json @@ -1 +1 @@ -{"label":"gulp-cli/test/fixtures/gulpfiles","nodes":[{"label":"test1","type":"task","nodes":[{"label":"","type":"function","branch":true,"nodes":[{"label":"noop","type":"function","nodes":[]}]}]},{"label":"test2","type":"task","nodes":[{"label":"","type":"function","branch":true,"nodes":[{"label":"test1","type":"task","nodes":[{"label":"","type":"function","branch":true,"nodes":[{"label":"noop","type":"function","nodes":[]}]}]},{"label":"noop","type":"function","nodes":[]}]}]},{"label":"test3","type":"task","nodes":[{"label":"","type":"function","branch":true,"nodes":[{"label":"described","type":"function","nodes":[]}]}]},{"label":"test4","type":"task","nodes":[{"label":"","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":"","type":"function","branch":true,"nodes":[{"label":"test1","type":"task","nodes":[{"label":"","type":"function","branch":true,"nodes":[{"label":"noop","type":"function","nodes":[]}]}]},{"label":"test3","type":"task","nodes":[{"label":"","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":"","type":"function","branch":true,"nodes":[{"label":"noop","type":"function","nodes":[]}]}]},{"label":"test2","type":"task","nodes":[{"label":"","type":"function","branch":true,"nodes":[{"label":"test1","type":"task","nodes":[{"label":"","type":"function","branch":true,"nodes":[{"label":"noop","type":"function","nodes":[]}]}]},{"label":"noop","type":"function","nodes":[]}]}]},{"label":"test3","type":"task","nodes":[{"label":"","type":"function","branch":true,"nodes":[{"label":"described","type":"function","nodes":[]}]}]},{"label":"test4","type":"task","nodes":[{"label":"","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":"","type":"function","branch":true,"nodes":[{"label":"test1","type":"task","nodes":[{"label":"","type":"function","branch":true,"nodes":[{"label":"noop","type":"function","nodes":[]}]}]},{"label":"test3","type":"task","nodes":[{"label":"","type":"function","branch":true,"nodes":[{"label":"described","type":"function","nodes":[]}]}]},{"label":"noop","type":"function","nodes":[]}]}]}]} diff --git a/test/expected/flags-tasks-simple.txt b/test/expected/flags-tasks-simple.txt index 94ac6fcf..753dbd5d 100644 --- a/test/expected/flags-tasks-simple.txt +++ b/test/expected/flags-tasks-simple.txt @@ -4,4 +4,6 @@ test3 test4 test5 test6 +test7 +test8 default diff --git a/test/expected/flags-tasks.txt b/test/expected/flags-tasks.txt index 2d940b2e..5100075b 100644 --- a/test/expected/flags-tasks.txt +++ b/test/expected/flags-tasks.txt @@ -25,4 +25,6 @@ gulp-cli/test/fixtures/gulpfiles │ ├── errorFunction │ └── anon ├── test5 -└── test6 +├── test6 +├── test7 +└── test8 diff --git a/test/fixtures/gulpfiles/gulpfile.js b/test/fixtures/gulpfiles/gulpfile.js index c4baaf27..24cbbd5b 100644 --- a/test/fixtures/gulpfiles/gulpfile.js +++ b/test/fixtures/gulpfiles/gulpfile.js @@ -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)); @@ -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)); diff --git a/test/lib/sync-task.js b/test/lib/sync-task.js new file mode 100644 index 00000000..6919488a --- /dev/null +++ b/test/lib/sync-task.js @@ -0,0 +1,22 @@ +'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 log tasks which did not complete', function(done) { + runner({ verbose: false }) + .chdir('test/fixtures/gulpfiles') + .gulp('test6 test7 test8') + .run(function(err, stdout) { + expect(err).toNotEqual(null); + expect(err.code).toEqual(1); + + var lines = stdout.split('\n'); + expect(lines.length).toEqual(8); + expect(eraseTime(lines[5])).toEqual('The following tasks did not complete: test7, test8'); + done(); + }); + }); +}); From 0aade92dab08a0478d96ecf68cdfedcc031ba4cc Mon Sep 17 00:00:00 2001 From: Benjamin Arbogast Date: Fri, 19 Jan 2018 07:48:39 +0100 Subject: [PATCH 4/7] Disable test for exit code if nodejs < 0.11.0 --- package.json | 3 ++- test/lib/sync-task.js | 25 +++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 246250f3..e149e6eb 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,8 @@ "marked-man": "^0.1.3", "mocha": "^3.2.0", "nyc": "^10.0.0", - "rimraf": "^2.6.1" + "rimraf": "^2.6.1", + "sver-compat": "^1.5.0" }, "keywords": [ "build", diff --git a/test/lib/sync-task.js b/test/lib/sync-task.js index 6919488a..5371d6bc 100644 --- a/test/lib/sync-task.js +++ b/test/lib/sync-task.js @@ -1,18 +1,39 @@ 'use strict'; var expect = require('expect'); +var Semver = require('sver-compat').Semver; var eraseTime = require('gulp-test-tools').eraseTime; var runner = require('gulp-test-tools').gulpRunner; + +function nodeDoesNotNodeSupportExitCode() { + var currentVersion = new Semver(process.versions.node); + var minimalVersion = new Semver('0.11.0'); + return currentVersion.lt(minimalVersion); +} + describe('sync-task', function() { - it('should log tasks which did not complete', function(done) { + it('should return error code 1 if any tasks did not complete', function(done) { + var this_ = this; runner({ verbose: false }) .chdir('test/fixtures/gulpfiles') .gulp('test6 test7 test8') - .run(function(err, stdout) { + .run(function(err) { + if (nodeDoesNotNodeSupportExitCode()) { + // The exit code is set to 1 by setting process.exitCode = 1 which is only supported from nodejs 0.11 on + this_.skip(); + } 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'); From b4bbee2b1811e80f69c54fae5ee268e57f327025 Mon Sep 17 00:00:00 2001 From: Benjamin Arbogast Date: Mon, 22 Jan 2018 20:53:13 +0100 Subject: [PATCH 5/7] Change detection of nodejs version to work without adding a new dependency --- package.json | 3 +-- test/lib/sync-task.js | 17 +++++------------ 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index e149e6eb..246250f3 100644 --- a/package.json +++ b/package.json @@ -64,8 +64,7 @@ "marked-man": "^0.1.3", "mocha": "^3.2.0", "nyc": "^10.0.0", - "rimraf": "^2.6.1", - "sver-compat": "^1.5.0" + "rimraf": "^2.6.1" }, "keywords": [ "build", diff --git a/test/lib/sync-task.js b/test/lib/sync-task.js index 5371d6bc..afc36337 100644 --- a/test/lib/sync-task.js +++ b/test/lib/sync-task.js @@ -1,28 +1,21 @@ 'use strict'; var expect = require('expect'); -var Semver = require('sver-compat').Semver; var eraseTime = require('gulp-test-tools').eraseTime; var runner = require('gulp-test-tools').gulpRunner; -function nodeDoesNotNodeSupportExitCode() { - var currentVersion = new Semver(process.versions.node); - var minimalVersion = new Semver('0.11.0'); - return currentVersion.lt(minimalVersion); -} - describe('sync-task', function() { it('should return error code 1 if any tasks did not complete', function(done) { - var this_ = this; + // 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) { - if (nodeDoesNotNodeSupportExitCode()) { - // The exit code is set to 1 by setting process.exitCode = 1 which is only supported from nodejs 0.11 on - this_.skip(); - } expect(err).toNotEqual(null); expect(err.code).toEqual(1); done(); From 107c1fc40d203e7a2fb20d2f45c079253459a415 Mon Sep 17 00:00:00 2001 From: Benjamin Arbogast Date: Mon, 22 Jan 2018 20:56:10 +0100 Subject: [PATCH 6/7] Move test file from test/lib to test --- test/{lib => }/sync-task.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/{lib => }/sync-task.js (100%) diff --git a/test/lib/sync-task.js b/test/sync-task.js similarity index 100% rename from test/lib/sync-task.js rename to test/sync-task.js From f566b8be38457b534cd0175d35ab1e47ec038d9f Mon Sep 17 00:00:00 2001 From: Benjamin Arbogast Date: Mon, 22 Jan 2018 21:45:04 +0100 Subject: [PATCH 7/7] Rename test/sync-task.js to test/non-completing-tasks.js --- test/{sync-task.js => non-completing-tasks.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/{sync-task.js => non-completing-tasks.js} (100%) diff --git a/test/sync-task.js b/test/non-completing-tasks.js similarity index 100% rename from test/sync-task.js rename to test/non-completing-tasks.js