From e9f1863a61074722af281c7bc79b98b859baa553 Mon Sep 17 00:00:00 2001 From: sttk Date: Sun, 8 Apr 2018 13:20:54 +0900 Subject: [PATCH 1/5] Suppress logging when `--tasks-json` flag is specified --- lib/shared/log/to-console.js | 2 +- test/flags-tasks-json.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/shared/log/to-console.js b/lib/shared/log/to-console.js index 2c290f0d..4a166946 100644 --- a/lib/shared/log/to-console.js +++ b/lib/shared/log/to-console.js @@ -32,7 +32,7 @@ function toConsole(log, opts) { // Return immediately if logging is // not desired. - if (opts.tasksSimple || opts.silent) { + if (opts.tasksSimple || opts.tasksJson || opts.silent) { // Keep from crashing process when silent. log.on('error', noop); return; diff --git a/test/flags-tasks-json.js b/test/flags-tasks-json.js index b4182ccc..72f0505f 100644 --- a/test/flags-tasks-json.js +++ b/test/flags-tasks-json.js @@ -19,7 +19,6 @@ describe('flag: --tasks-json', function() { function cb(err, stdout, stderr) { expect(err).toEqual(null); expect(stderr).toEqual(''); - stdout = skipLines(stdout, 1); expect(JSON.parse(stdout)).toEqual(expected); done(err); } From dd581f57c383a6ada1e62da991c99fcc0898164d Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Wed, 13 Mar 2019 14:01:37 -0700 Subject: [PATCH 2/5] Fix: Suppress logs for --help and --version --- index.js | 16 +++---- lib/shared/log/to-console.js | 2 +- test/config-flags-gulpfile.js | 13 +++--- .../config/flags/gulpfile/autoload/.gulp.json | 1 - .../gulpfiles/gulpfile-babel.babel.js | 43 +++++++++++++++++++ test/flags-help.js | 14 ++++++ test/flags-tasks-json.js | 12 ++++++ test/flags-tasks-simple.js | 13 ++++++ test/flags-version.js | 19 +++++++- 9 files changed, 114 insertions(+), 19 deletions(-) create mode 100644 test/fixtures/gulpfiles/gulpfile-babel.babel.js diff --git a/index.js b/index.js index cf884aef..e1cb3223 100644 --- a/index.js +++ b/index.js @@ -61,9 +61,6 @@ var usage = var parser = yargs.usage(usage, cliOptions); var opts = parser.argv; -// Set up event listeners for logging temporarily. -toConsole(log, opts); - cli.on('require', function(name) { log.info('Requiring external module', ansi.magenta(name)); }); @@ -85,7 +82,6 @@ cli.on('respawn', function(flags, child) { log.info('Respawned to PID:', pid); }); - function run() { cli.prepare({ cwd: opts.cwd, @@ -93,13 +89,15 @@ function run() { require: opts.require, completion: opts.completion, }, function(env) { - var cfgLoadOrder = ['home', 'cwd']; var cfg = loadConfigFiles(env.configFiles['.gulp'], cfgLoadOrder); opts = mergeConfigToCliFlags(opts, cfg); env = mergeConfigToEnvFlags(env, cfg); env.configProps = cfg; + // Set up event listeners for logging again after configuring. + toConsole(log, opts); + cli.execute(env, handleArguments); }); } @@ -117,18 +115,16 @@ function handleArguments(env) { process.env.UNDERTAKER_SETTLE = 'true'; } - // Set up event listeners for logging again after configuring. - toConsole(log, opts); - if (opts.help) { parser.showHelp(console.log); exit(0); } + // Anything that needs to print outside of the logging mechanism should use console.log if (opts.version) { - log.info('CLI version', cliVersion); + console.log('CLI version', cliVersion); if (env.modulePackage && typeof env.modulePackage.version !== 'undefined') { - log.info('Local version', env.modulePackage.version); + console.log('Local version', env.modulePackage.version); } exit(0); } diff --git a/lib/shared/log/to-console.js b/lib/shared/log/to-console.js index 4a166946..05103710 100644 --- a/lib/shared/log/to-console.js +++ b/lib/shared/log/to-console.js @@ -32,7 +32,7 @@ function toConsole(log, opts) { // Return immediately if logging is // not desired. - if (opts.tasksSimple || opts.tasksJson || opts.silent) { + if (opts.tasksSimple || opts.tasksJson || opts.help || opts.version || opts.silent) { // Keep from crashing process when silent. log.on('error', noop); return; diff --git a/test/config-flags-gulpfile.js b/test/config-flags-gulpfile.js index 6f6af20b..bac65e84 100644 --- a/test/config-flags-gulpfile.js +++ b/test/config-flags-gulpfile.js @@ -100,11 +100,14 @@ describe('config: flags.gulpfile', function() { function cb(err, stdout, stderr) { expect(err).toEqual(null); expect(stderr).toEqual(''); - expect(eraseTime(stdout)).toEqual( - 'Requiring external module babel-register\n' + - 'clean!\n' + - 'build!\n' + - ''); + + var requiring = eraseTime(headLines(stdout, 1)); + expect(requiring).toEqual('Requiring external module babel-register'); + var clean = eraseTime(headLines(stdout, 1, 4)); + expect(clean).toEqual('clean!'); + var build = eraseTime(headLines(stdout, 1, 7)); + expect(build).toEqual('build!'); + done(err); } }); diff --git a/test/fixtures/config/flags/gulpfile/autoload/.gulp.json b/test/fixtures/config/flags/gulpfile/autoload/.gulp.json index fba4be3c..0d5c0009 100644 --- a/test/fixtures/config/flags/gulpfile/autoload/.gulp.json +++ b/test/fixtures/config/flags/gulpfile/autoload/.gulp.json @@ -1,6 +1,5 @@ { "flags": { - "silent": true, "gulpfile": "other_folder/gulpfile-exports.babel.js" } } diff --git a/test/fixtures/gulpfiles/gulpfile-babel.babel.js b/test/fixtures/gulpfiles/gulpfile-babel.babel.js new file mode 100644 index 00000000..24cbbd5b --- /dev/null +++ b/test/fixtures/gulpfiles/gulpfile-babel.babel.js @@ -0,0 +1,43 @@ +'use strict'; + +var gulp = require('gulp'); + +function noop(cb) { + cb(); +} + +function described(cb) { + cb(); +} + +function delayed(cb) { + setTimeout(cb, 100); +} + +function errorFunction() { + throw new Error('Error!'); +} +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)); +gulp.task('test2', gulp.series('test1', noop)); +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/flags-help.js b/test/flags-help.js index f9dcad0a..e781665b 100644 --- a/test/flags-help.js +++ b/test/flags-help.js @@ -44,4 +44,18 @@ describe('flag: --help', function() { } }); + it('avoids printing "Requiring external module *"', function(done) { + runner({ verbose: false }) + .gulp('--help --gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js') + .run(cb); + + function cb(err, stdout, stderr) { + expect(err).toEqual(null); + expect(stderr).toEqual(''); + stdout = eraseFirstSpace(stdout); + expect(stdout).toEqual(outputText); + done(err); + } + }); + }); diff --git a/test/flags-tasks-json.js b/test/flags-tasks-json.js index 72f0505f..da3d3319 100644 --- a/test/flags-tasks-json.js +++ b/test/flags-tasks-json.js @@ -47,4 +47,16 @@ describe('flag: --tasks-json', function() { } }); + it('avoids printing "Requiring external module *"', function(done) { + runner({ verbose: false }) + .gulp('--tasks-json --gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js') + .run(cb); + + function cb(err, stdout, stderr) { + expect(err).toEqual(null); + expect(stderr).toEqual(''); + expect(JSON.parse(stdout)).toEqual(expected); + done(err); + } + }); }); diff --git a/test/flags-tasks-simple.js b/test/flags-tasks-simple.js index cf6de089..b2e8ba25 100644 --- a/test/flags-tasks-simple.js +++ b/test/flags-tasks-simple.js @@ -23,4 +23,17 @@ describe('flag: --tasks-simple', function() { } }); + it('avoids printing "Requiring external module *"', function(done) { + runner({ verbose: false }) + .gulp('--tasks-simple --gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js') + .run(cb); + + function cb(err, stdout, stderr) { + expect(err).toEqual(null); + expect(stderr).toEqual(''); + expect(stdout).toEqual(outputText); + done(err); + } + }); + }); diff --git a/test/flags-version.js b/test/flags-version.js index f768f8bb..39244e10 100644 --- a/test/flags-version.js +++ b/test/flags-version.js @@ -2,7 +2,6 @@ var expect = require('expect'); var runner = require('gulp-test-tools').gulpRunner; -var eraseTime = require('gulp-test-tools').eraseTime; var cliVersion = require('../package.json').version; var gulpVersion = require('gulp/package.json').version; @@ -17,7 +16,23 @@ describe('flag: --version', function() { function cb(err, stdout, stderr) { expect(err).toEqual(null); expect(stderr).toEqual(''); - stdout = eraseTime(stdout); + expect(stdout).toEqual( + 'CLI version ' + cliVersion + '\n' + + 'Local version ' + gulpVersion + '\n' + + '' + ); + done(err); + } + }); + + it('avoids printing "Requiring external module *"', function(done) { + runner({ verbose: false }) + .gulp('--version --gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js') + .run(cb); + + function cb(err, stdout, stderr) { + expect(err).toEqual(null); + expect(stderr).toEqual(''); expect(stdout).toEqual( 'CLI version ' + cliVersion + '\n' + 'Local version ' + gulpVersion + '\n' + From 9870c8b7c357e851f5019135412bd0a7f1f34f81 Mon Sep 17 00:00:00 2001 From: sttk Date: Sat, 16 Mar 2019 11:21:03 +0900 Subject: [PATCH 3/5] Scaffold: Change an eslint rule --- .eslintrc | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc b/.eslintrc index 5155060d..ea9ec781 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,6 +1,7 @@ { "extends": "gulp", "rules": { + "max-len": [1, 90], "max-statements": [1, 40], "no-console": "off" } From 5754479d6b62d6188e418b1cdde14cc021b9bfd0 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Mon, 18 Mar 2019 11:59:39 -0700 Subject: [PATCH 4/5] Fix: Double the timeout on some tests for old node --- test/flags-tasks-json.js | 3 +++ test/flags-tasks-simple.js | 3 +++ 2 files changed, 6 insertions(+) diff --git a/test/flags-tasks-json.js b/test/flags-tasks-json.js index da3d3319..242ffd26 100644 --- a/test/flags-tasks-json.js +++ b/test/flags-tasks-json.js @@ -48,6 +48,9 @@ describe('flag: --tasks-json', function() { }); it('avoids printing "Requiring external module *"', function(done) { + // Double the timeout for old node versions + this.timeout(10000); + runner({ verbose: false }) .gulp('--tasks-json --gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js') .run(cb); diff --git a/test/flags-tasks-simple.js b/test/flags-tasks-simple.js index b2e8ba25..2e90853d 100644 --- a/test/flags-tasks-simple.js +++ b/test/flags-tasks-simple.js @@ -24,6 +24,9 @@ describe('flag: --tasks-simple', function() { }); it('avoids printing "Requiring external module *"', function(done) { + // Double the timeout for old node versions + this.timeout(10000); + runner({ verbose: false }) .gulp('--tasks-simple --gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js') .run(cb); From 42aaf189fe81487ed2d7912b3073d8d90d6792da Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Mon, 18 Mar 2019 12:29:54 -0700 Subject: [PATCH 5/5] Fix: Actually disable because babel is infinitely slow --- test/flags-tasks-json.js | 4 ++-- test/flags-tasks-simple.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/flags-tasks-json.js b/test/flags-tasks-json.js index 242ffd26..364779ff 100644 --- a/test/flags-tasks-json.js +++ b/test/flags-tasks-json.js @@ -48,8 +48,8 @@ describe('flag: --tasks-json', function() { }); it('avoids printing "Requiring external module *"', function(done) { - // Double the timeout for old node versions - this.timeout(10000); + // Disable the timeout for old node versions + this.timeout(0); runner({ verbose: false }) .gulp('--tasks-json --gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js') diff --git a/test/flags-tasks-simple.js b/test/flags-tasks-simple.js index 2e90853d..a44bd91c 100644 --- a/test/flags-tasks-simple.js +++ b/test/flags-tasks-simple.js @@ -24,8 +24,8 @@ describe('flag: --tasks-simple', function() { }); it('avoids printing "Requiring external module *"', function(done) { - // Double the timeout for old node versions - this.timeout(10000); + // Disable the timeout for old node versions + this.timeout(0); runner({ verbose: false }) .gulp('--tasks-simple --gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js')