From 2d8a320c834e615478d418256cc0d7b010bc8c84 Mon Sep 17 00:00:00 2001 From: Takayuki Sato Date: Sun, 21 Apr 2019 00:26:14 +0900 Subject: [PATCH] Build: Improve tests and raise coverage (#190) --- .gitignore | 1 + index.js | 15 ++- lib/shared/ansi.js | 2 + lib/shared/config/env-flags.js | 3 +- lib/shared/exit.js | 1 + lib/shared/get-blacklist.js | 4 + lib/shared/log/blacklist-error.js | 1 + lib/shared/log/tasks.js | 2 + lib/shared/log/to-console.js | 1 + lib/versioned/^4.0.0/format-error.js | 1 + lib/versioned/^4.0.0/log/events.js | 2 + lib/versioned/^4.0.0/log/get-task.js | 2 + test/config-flags-log-level.js | 112 +++++++----------- test/config-flags-node-flags.js | 45 +++++++ test/execution-errors.js | 83 +++++++++++++ .../config/flags/logLevel/L/gulpfile.js | 7 ++ .../config/flags/logLevel/LL/gulpfile.js | 7 ++ .../config/flags/logLevel/LLL/gulpfile.js | 7 ++ .../config/flags/logLevel/gulpfile.js | 7 ++ .../config/flags/nodeFlags/null/.gulp.js | 7 ++ .../config/flags/nodeFlags/null/gulpfile.js | 6 + .../config/flags/nodeFlags/undefined/.gulp.js | 7 ++ .../flags/nodeFlags/undefined/gulpfile.js | 6 + .../errors/bad-gulp-version/gulpfile.js | 0 .../node_modules/gulp/index.js | 0 .../node_modules/gulp/package.json | 15 +++ test/fixtures/errors/package.json | 15 +++ .../gulpfiles/gulpfile-dedup-errorlog.js | 7 ++ .../{packages => verify}/invalid-package.json | 0 .../{packages => verify}/package.json | 0 .../{packages => verify}/valid-package.json | 0 test/flags-tasks-json.js | 19 +++ test/flags-verify.js | 12 +- test/flags-version.js | 25 +++- 34 files changed, 334 insertions(+), 88 deletions(-) create mode 100644 test/execution-errors.js create mode 100644 test/fixtures/config/flags/logLevel/L/gulpfile.js create mode 100644 test/fixtures/config/flags/logLevel/LL/gulpfile.js create mode 100644 test/fixtures/config/flags/logLevel/LLL/gulpfile.js create mode 100644 test/fixtures/config/flags/logLevel/gulpfile.js create mode 100644 test/fixtures/config/flags/nodeFlags/null/.gulp.js create mode 100644 test/fixtures/config/flags/nodeFlags/null/gulpfile.js create mode 100644 test/fixtures/config/flags/nodeFlags/undefined/.gulp.js create mode 100644 test/fixtures/config/flags/nodeFlags/undefined/gulpfile.js create mode 100644 test/fixtures/errors/bad-gulp-version/gulpfile.js create mode 100644 test/fixtures/errors/bad-gulp-version/node_modules/gulp/index.js create mode 100644 test/fixtures/errors/bad-gulp-version/node_modules/gulp/package.json create mode 100644 test/fixtures/errors/package.json create mode 100644 test/fixtures/gulpfiles/gulpfile-dedup-errorlog.js rename test/fixtures/{packages => verify}/invalid-package.json (100%) rename test/fixtures/{packages => verify}/package.json (100%) rename test/fixtures/{packages => verify}/valid-package.json (100%) diff --git a/.gitignore b/.gitignore index f2f8f37a..3b569a93 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .DS_Store *.log node_modules +!test/fixtures/errors/bad-gulp-version/node_modules/ build *.node components diff --git a/index.js b/index.js index 686583df..9a7e66f6 100644 --- a/index.js +++ b/index.js @@ -70,6 +70,7 @@ cli.on('requireFail', function(name, error) { ansi.yellow('Failed to load external module'), ansi.magenta(name) ); + /* istanbul ignore else */ if (error) { log.warn(ansi.yellow(error.toString())); } @@ -122,20 +123,20 @@ function handleArguments(env) { // Anything that needs to print outside of the logging mechanism should use console.log if (opts.version) { - console.log('CLI version', cliVersion); - if (env.modulePackage && typeof env.modulePackage.version !== 'undefined') { - console.log('Local version', env.modulePackage.version); - } + console.log('CLI version:', cliVersion); + console.log('Local version:', env.modulePackage.version || 'Unknown'); exit(0); } if (opts.verify) { var pkgPath = opts.verify !== true ? opts.verify : 'package.json'; + /* istanbul ignore else */ if (path.resolve(pkgPath) !== path.normalize(pkgPath)) { pkgPath = path.join(env.cwd, pkgPath); } log.info('Verifying plugins in ' + pkgPath); return getBlacklist(function(err, blacklist) { + /* istanbul ignore if */ if (err) { return logBlacklistError(err); } @@ -147,10 +148,12 @@ function handleArguments(env) { } if (!env.modulePath) { + /* istanbul ignore next */ var missingNodeModules = fs.existsSync(path.join(env.cwd, 'package.json')) && !fs.existsSync(path.join(env.cwd, 'node_modules')); + /* istanbul ignore next */ var missingGulpMessage = missingNodeModules ? 'Local modules not found in' @@ -159,6 +162,7 @@ function handleArguments(env) { ansi.red(missingGulpMessage), ansi.magenta(tildify(env.cwd)) ); + /* istanbul ignore next */ var installCommand = missingNodeModules ? 'npm install' @@ -186,9 +190,10 @@ function handleArguments(env) { var range = findRange(env.modulePackage.version, ranges); if (!range) { - return log.error( + log.error( ansi.red('Unsupported gulp version', env.modulePackage.version) ); + exit(1); } // Load and execute the CLI version diff --git a/lib/shared/ansi.js b/lib/shared/ansi.js index e3b0d3a4..d5030fa0 100644 --- a/lib/shared/ansi.js +++ b/lib/shared/ansi.js @@ -5,6 +5,7 @@ var supportsColor = require('color-support'); var hasColors = colorize(); +/* istanbul ignore next */ module.exports = { red: hasColors ? colors.red : noColor, green: hasColors ? colors.green : noColor, @@ -31,6 +32,7 @@ function colorize() { return false; } + /* istanbul ignore if */ if (hasFlag('color')) { return true; } diff --git a/lib/shared/config/env-flags.js b/lib/shared/config/env-flags.js index 0e18bf9b..a5a4abd7 100644 --- a/lib/shared/config/env-flags.js +++ b/lib/shared/config/env-flags.js @@ -34,11 +34,10 @@ function mergeConfigToEnvFlags(env, config, cliOpts) { return [].concat(envInfo.value, configInfo.value); } + /* istanbul ignore else */ if (envInfo.keyChain === 'nodeFlags') { return [].concat(configInfo.value || []); } - - return configInfo.value; } } diff --git a/lib/shared/exit.js b/lib/shared/exit.js index 0591e1ed..9d619c32 100644 --- a/lib/shared/exit.js +++ b/lib/shared/exit.js @@ -2,6 +2,7 @@ // Fix stdout truncation on windows function exit(code) { + /* istanbul ignore next */ if (process.platform === 'win32' && process.stdout.bufferSize) { process.stdout.once('drain', function() { process.exit(code); diff --git a/lib/shared/get-blacklist.js b/lib/shared/get-blacklist.js index ca4006b1..31258be5 100644 --- a/lib/shared/get-blacklist.js +++ b/lib/shared/get-blacklist.js @@ -19,6 +19,7 @@ function parse(str, cb) { try { cb(null, JSON.parse(str)); } catch (err) { + /* istanbul ignore next */ cb(new Error('Invalid Blacklist JSON.')); } } @@ -28,6 +29,7 @@ function getBlacklist(cb) { https.get(url, onRequest); function onRequest(res) { + /* istanbul ignore if */ if (res.statusCode !== 200) { // TODO: Test different status codes return cb(new Error('Request failed. Status Code: ' + res.statusCode)); @@ -39,6 +41,7 @@ function getBlacklist(cb) { } function onCollect(err, result) { + /* istanbul ignore if */ if (err) { return cb(err); } @@ -47,6 +50,7 @@ function getBlacklist(cb) { } function onParse(err, blacklist) { + /* istanbul ignore if */ if (err) { return cb(err); } diff --git a/lib/shared/log/blacklist-error.js b/lib/shared/log/blacklist-error.js index 396436ac..b0355b2d 100644 --- a/lib/shared/log/blacklist-error.js +++ b/lib/shared/log/blacklist-error.js @@ -5,6 +5,7 @@ var log = require('gulplog'); var ansi = require('../ansi'); var exit = require('../exit'); +/* istanbul ignore next */ function logBlacklistError(err) { log.error(ansi.red('Error: failed to retrieve plugins black-list')); log.error(err.message); // Avoid duplicating for each version diff --git a/lib/shared/log/tasks.js b/lib/shared/log/tasks.js index 93451ac5..0b76b088 100644 --- a/lib/shared/log/tasks.js +++ b/lib/shared/log/tasks.js @@ -60,6 +60,7 @@ function getNodeFactory(getTask, entryObserver) { }, taskNode: function(node) { + /* istanbul ignore next */ var task = getTask(node.label) || {}; var newNode = { @@ -74,6 +75,7 @@ function getNodeFactory(getTask, entryObserver) { if (flag.length === 0) { return; } + /* istanbul ignore next */ var opt = { label: flag, desc: typeof task.flags[flag] === 'string' ? task.flags[flag] : '', diff --git a/lib/shared/log/to-console.js b/lib/shared/log/to-console.js index 05103710..43650af1 100644 --- a/lib/shared/log/to-console.js +++ b/lib/shared/log/to-console.js @@ -2,6 +2,7 @@ var fancyLog = require('fancy-log'); +/* istanbul ignore next */ function noop() {} // The sorting of the levels is diff --git a/lib/versioned/^4.0.0/format-error.js b/lib/versioned/^4.0.0/format-error.js index b0f13889..3d8a7718 100644 --- a/lib/versioned/^4.0.0/format-error.js +++ b/lib/versioned/^4.0.0/format-error.js @@ -1,6 +1,7 @@ 'use strict'; // Format orchestrator errors +/* istanbul ignore next */ function formatError(e) { if (!e.error) { return e.message; diff --git a/lib/versioned/^4.0.0/log/events.js b/lib/versioned/^4.0.0/log/events.js index 625054fb..1f6e7b16 100644 --- a/lib/versioned/^4.0.0/log/events.js +++ b/lib/versioned/^4.0.0/log/events.js @@ -12,6 +12,7 @@ function logEvents(gulpInst) { var loggedErrors = []; gulpInst.on('start', function(evt) { + /* istanbul ignore next */ // TODO: batch these // so when 5 tasks start at once it only logs one time with all 5 var level = evt.branch ? 'debug' : 'info'; @@ -20,6 +21,7 @@ function logEvents(gulpInst) { gulpInst.on('stop', function(evt) { var time = prettyTime(evt.duration); + /* istanbul ignore next */ var level = evt.branch ? 'debug' : 'info'; log[level]( 'Finished', '\'' + ansi.cyan(evt.name) + '\'', diff --git a/lib/versioned/^4.0.0/log/get-task.js b/lib/versioned/^4.0.0/log/get-task.js index 62891192..1b158714 100644 --- a/lib/versioned/^4.0.0/log/get-task.js +++ b/lib/versioned/^4.0.0/log/get-task.js @@ -16,6 +16,7 @@ function getDescription(task) { if (typeof task.description === 'string') { return task.description; } + /* istanbul ignore else */ if (typeof task.unwrap === 'function') { var origFn = task.unwrap(); if (typeof origFn.description === 'string') { @@ -29,6 +30,7 @@ function getFlags(task) { if (isObject(task.flags)) { return task.flags; } + /* istanbul ignore else */ if (typeof task.unwrap === 'function') { var origFn = task.unwrap(); if (isObject(origFn.flags)) { diff --git a/test/config-flags-log-level.js b/test/config-flags-log-level.js index 2b28c143..c3c20918 100644 --- a/test/config-flags-log-level.js +++ b/test/config-flags-log-level.js @@ -3,14 +3,18 @@ var expect = require('expect'); var path = require('path'); var eraseTime = require('gulp-test-tools').eraseTime; +var headLines = require('gulp-test-tools').headLines; var runner = require('gulp-test-tools').gulpRunner; describe('config: flag.logLevel', function() { describe('log level 3 by default', function() { + var gulp = runner({ verbose: false }) + .basedir(path.join(__dirname, 'fixtures/config/flags/logLevel')) + .gulp; + it('Should output error log', function(done) { - runner({ verbose: false }) - .gulp('--gulpfile x') + gulp('--gulpfile x') .run(function(err, stdout, stderr) { expect(err).toNotEqual(null); expect(stdout).toEqual(''); @@ -20,34 +24,25 @@ describe('config: flag.logLevel', function() { }); it('Should output warn log', function(done) { - var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', - 'invalid-package.json'); - - runner({ verbose: false }) - .gulp('--verify', packageJsonPath) + gulp('--require', 'mymodule') .run(function(err, stdout, stderr) { - expect(err).toNotEqual(null); - expect(eraseTime(stdout)).toEqual( - 'Verifying plugins in ' + packageJsonPath + '\n' + - 'Blacklisted plugins found in this project:\n' + - 'gulp-blink: deprecated. use \`blink` instead.\n'); + expect(err).toEqual(null); expect(stderr).toEqual(''); + expect(headLines(eraseTime(stdout), 2)).toMatch( + 'Failed to load external module mymodule\n' + + 'Error: Cannot find module \'mymodule\' from \''); done(); }); }); it('Should output info log', function(done) { - var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', - 'valid-package.json'); - - runner({ verbose: false }) - .gulp('--verify', packageJsonPath) + gulp('--harmony') .run(function(err, stdout, stderr) { expect(err).toEqual(null); - expect(eraseTime(stdout)).toEqual( - 'Verifying plugins in ' + packageJsonPath + '\n' + - 'There are no blacklisted plugins in this project\n'); expect(stderr).toEqual(''); + expect(headLines(eraseTime(stdout), 2)).toMatch( + 'Node flags detected: --harmony\n' + + 'Respawned to PID: '); done(err); }); }); @@ -69,27 +64,21 @@ describe('config: flag.logLevel', function() { }); it('Should output warn log', function(done) { - var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', - 'invalid-package.json'); - - gulp('--verify', packageJsonPath) + gulp('--require', 'mymodule') .run(function(err, stdout, stderr) { - expect(err).toNotEqual(null); - expect(stdout).toEqual(''); + expect(err).toEqual(null); + expect(stderr).toEqual(''); expect(stderr).toEqual(''); done(); }); }); it('Should output info log', function(done) { - var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', - 'valid-package.json'); - - gulp('--verify', packageJsonPath) + gulp('--harmony') .run(function(err, stdout, stderr) { expect(err).toEqual(null); - expect(stdout).toEqual(''); expect(stderr).toEqual(''); + expect(stdout).toEqual(''); done(err); }); }); @@ -111,29 +100,23 @@ describe('config: flag.logLevel', function() { }); it('Should output warn log', function(done) { - var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', - 'invalid-package.json'); - - gulp('--verify', packageJsonPath) + gulp('--require', 'mymodule') .run(function(err, stdout, stderr) { - expect(err).toNotEqual(null); - expect(eraseTime(stdout)).toEqual( - 'Blacklisted plugins found in this project:\n' + - 'gulp-blink: deprecated. use \`blink` instead.\n'); + expect(err).toEqual(null); expect(stderr).toEqual(''); + expect(eraseTime(stdout)).toMatch( + 'Failed to load external module mymodule\n' + + 'Error: Cannot find module \'mymodule\' from \''); done(); }); }); it('Should output info log', function(done) { - var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', - 'valid-package.json'); - - gulp('--verify', packageJsonPath) + gulp('--harmony') .run(function(err, stdout, stderr) { expect(err).toEqual(null); - expect(stdout).toEqual(''); expect(stderr).toEqual(''); + expect(stdout).toEqual(''); done(err); }); }); @@ -155,32 +138,25 @@ describe('config: flag.logLevel', function() { }); it('Should output warn log', function(done) { - var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', - 'invalid-package.json'); - - gulp('--verify', packageJsonPath) + gulp('--require', 'mymodule') .run(function(err, stdout, stderr) { - expect(err).toNotEqual(null); - expect(eraseTime(stdout)).toEqual( - 'Verifying plugins in ' + packageJsonPath + '\n' + - 'Blacklisted plugins found in this project:\n' + - 'gulp-blink: deprecated. use \`blink` instead.\n'); + expect(err).toEqual(null); expect(stderr).toEqual(''); + expect(headLines(eraseTime(stdout), 2)).toMatch( + 'Failed to load external module mymodule\n' + + 'Error: Cannot find module \'mymodule\' from \''); done(); }); }); it('Should output info log', function(done) { - var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', - 'valid-package.json'); - - gulp('--verify', packageJsonPath) + gulp('--harmony') .run(function(err, stdout, stderr) { expect(err).toEqual(null); - expect(eraseTime(stdout)).toEqual( - 'Verifying plugins in ' + packageJsonPath + '\n' + - 'There are no blacklisted plugins in this project\n'); expect(stderr).toEqual(''); + expect(headLines(eraseTime(stdout), 2)).toMatch( + 'Node flags detected: --harmony\n' + + 'Respawned to PID: '); done(err); }); }); @@ -192,10 +168,7 @@ describe('config: flag.logLevel', function() { .basedir(path.join(__dirname, 'fixtures/config/flags/logLevel/LLL')) .gulp; - var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', - 'valid-package.json'); - - gulp('-L', '--verify', packageJsonPath) + gulp('-L', '--require', 'mymodule') .run(function(err, stdout, stderr) { expect(err).toEqual(null); expect(stdout).toEqual(''); @@ -209,16 +182,13 @@ describe('config: flag.logLevel', function() { .basedir(path.join(__dirname, 'fixtures/config/flags/logLevel/L')) .gulp; - var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', - 'valid-package.json'); - - gulp('-LLL', '--verify', packageJsonPath) + gulp('-LLL', '--harmony') .run(function(err, stdout, stderr) { expect(err).toEqual(null); - expect(eraseTime(stdout)).toEqual( - 'Verifying plugins in ' + packageJsonPath + '\n' + - 'There are no blacklisted plugins in this project\n'); expect(stderr).toEqual(''); + expect(headLines(eraseTime(stdout), 2)).toMatch( + 'Node flags detected: --harmony\n' + + 'Respawned to PID: '); done(err); }); }); diff --git a/test/config-flags-node-flags.js b/test/config-flags-node-flags.js index 0aaa2685..ac05dbb3 100644 --- a/test/config-flags-node-flags.js +++ b/test/config-flags-node-flags.js @@ -7,7 +7,9 @@ var fixturesDir = path.join(__dirname, 'fixtures/config'); var runner = require('gulp-test-tools').gulpRunner().basedir(fixturesDir); var headLines = require('gulp-test-tools').headLines; +var skipLines = require('gulp-test-tools').skipLines; var eraseTime = require('gulp-test-tools').eraseTime; +var eraseLapse = require('gulp-test-tools').eraseLapse; describe('config: nodeFlags', function() { @@ -67,4 +69,47 @@ describe('config: nodeFlags', function() { done(err); } }); + + it('Should not respawn when a node flag is specified to undefined', function(done) { + runner + .chdir('flags/nodeFlags/undefined') + .gulp() + .run(cb); + + function cb(err, stdout, stderr) { + expect(err).toEqual(null); + expect(stderr).toEqual(''); + + stdout = eraseLapse(eraseTime(stdout)); + expect(headLines(stdout, 1)).toMatch('Using gulpfile '); + expect(skipLines(stdout, 1)).toEqual( + 'Starting \'default\'...\n' + + 'Default\n' + + 'Finished \'default\' after ?\n' + + ''); + done(err); + } + }); + + it('Should not respawn when a node flag is specified to null', function(done) { + runner + .chdir('flags/nodeFlags/null') + .gulp() + .run(cb); + + function cb(err, stdout, stderr) { + expect(err).toEqual(null); + expect(stderr).toEqual(''); + + stdout = eraseLapse(eraseTime(stdout)); + expect(headLines(stdout, 1)).toMatch('Using gulpfile '); + expect(skipLines(stdout, 1)).toEqual( + 'Starting \'default\'...\n' + + 'Default\n' + + 'Finished \'default\' after ?\n' + + ''); + done(err); + } + }); + }); diff --git a/test/execution-errors.js b/test/execution-errors.js new file mode 100644 index 00000000..cf4a50ad --- /dev/null +++ b/test/execution-errors.js @@ -0,0 +1,83 @@ +'use strict'; + +var expect = require('expect'); +var eraseTime = require('gulp-test-tools').eraseTime; +var eraseLapse = require('gulp-test-tools').eraseLapse; +var runner = require('gulp-test-tools').gulpRunner; +var path = require('path'); +var os = require('os'); +var tildify = require('../lib/shared/tildify'); + +describe('execution error', function() { + + it('should output an error if a task is not defined', function(done) { + runner({ verbose: false }) + .chdir('test/fixtures/gulpfiles') + .gulp('a') + .run(function(err, stdout, stderr) { + expect(err).toNotEqual(null); + expect(err.code).toEqual(1); + expect(eraseTime(stdout)).toMatch('Using gulpfile '); + expect(eraseTime(stderr)).toEqual( + 'Task never defined: a\n' + + 'To list available tasks, try running: gulp --tasks\n'); + done(); + }); + }); + + it('should output an error if gulp version is unsupported', function(done) { + runner({ verbose: false }) + .chdir('test/fixtures/errors/bad-gulp-version') + .gulp() + .run(function(err, stdout, stderr) { + expect(err).toNotEqual(null); + expect(err.code).toEqual(1); + expect(eraseTime(stdout)).toEqual(''); + expect(eraseTime(stderr)).toEqual('Unsupported gulp version\n'); + done(); + }); + }); + + it('should output an error if gulp is not found', function(done) { + runner({ verbose: false }) + .chdir(os.tmpdir()) + .gulp() + .run(function(err, stdout, stderr) { + expect(err).toNotEqual(null); + expect(err.code).toEqual(1); + expect(eraseTime(stdout)).toEqual(''); + stderr = eraseTime(stderr).split(/[\r\n]+/); + expect(stderr[0]).toMatch('Local gulp not found in '); + expect(stderr[1]).toEqual('Try running: npm install gulp'); + done(); + }); + }); + + it('should log a same error once', function(done) { + var dir = path.join(__dirname, 'fixtures/gulpfiles'); + var gulpfileName = 'gulpfile-dedup-errorlog.js'; + runner({ verbose: false }) + .chdir(dir) + .gulp('--gulpfile', gulpfileName) + .run(function(err, stdout, stderr) { + expect(err).toNotEqual(null); + expect(err.code).toEqual(1); + stdout = eraseLapse(eraseTime(stdout)); + expect(stdout).toEqual( + 'Using gulpfile ' + tildify(path.join(dir, gulpfileName)) + '\n' + + 'Starting \'default\'...\n' + + 'Starting \'b\'...\n' + + 'Starting \'a\'...\n' + + ''); + stderr = eraseLapse(eraseTime(stderr)).split(/[\r\n]+/); + var n = stderr.length; + expect(stderr[0]).toEqual('\'a\' errored after ?'); + expect(stderr[1]).toEqual('Error: Task \'a\' failed!'); + expect(stderr[n - 3]).toEqual('\'b\' errored after ?'); + expect(stderr[n - 2]).toEqual('\'default\' errored after ?'); + expect(stderr[n - 1]).toEqual(''); + done(); + }); + }); +}); + diff --git a/test/fixtures/config/flags/logLevel/L/gulpfile.js b/test/fixtures/config/flags/logLevel/L/gulpfile.js new file mode 100644 index 00000000..42466b03 --- /dev/null +++ b/test/fixtures/config/flags/logLevel/L/gulpfile.js @@ -0,0 +1,7 @@ +'use strict'; + +var gulp = require('gulp'); + +gulp.task('default', function(done) { + done(); +}); diff --git a/test/fixtures/config/flags/logLevel/LL/gulpfile.js b/test/fixtures/config/flags/logLevel/LL/gulpfile.js new file mode 100644 index 00000000..42466b03 --- /dev/null +++ b/test/fixtures/config/flags/logLevel/LL/gulpfile.js @@ -0,0 +1,7 @@ +'use strict'; + +var gulp = require('gulp'); + +gulp.task('default', function(done) { + done(); +}); diff --git a/test/fixtures/config/flags/logLevel/LLL/gulpfile.js b/test/fixtures/config/flags/logLevel/LLL/gulpfile.js new file mode 100644 index 00000000..42466b03 --- /dev/null +++ b/test/fixtures/config/flags/logLevel/LLL/gulpfile.js @@ -0,0 +1,7 @@ +'use strict'; + +var gulp = require('gulp'); + +gulp.task('default', function(done) { + done(); +}); diff --git a/test/fixtures/config/flags/logLevel/gulpfile.js b/test/fixtures/config/flags/logLevel/gulpfile.js new file mode 100644 index 00000000..42466b03 --- /dev/null +++ b/test/fixtures/config/flags/logLevel/gulpfile.js @@ -0,0 +1,7 @@ +'use strict'; + +var gulp = require('gulp'); + +gulp.task('default', function(done) { + done(); +}); diff --git a/test/fixtures/config/flags/nodeFlags/null/.gulp.js b/test/fixtures/config/flags/nodeFlags/null/.gulp.js new file mode 100644 index 00000000..1b0bdfb1 --- /dev/null +++ b/test/fixtures/config/flags/nodeFlags/null/.gulp.js @@ -0,0 +1,7 @@ +'use strict'; + +module.exports = { + flags: { + nodeFlags: null, + }, +}; diff --git a/test/fixtures/config/flags/nodeFlags/null/gulpfile.js b/test/fixtures/config/flags/nodeFlags/null/gulpfile.js new file mode 100644 index 00000000..b1e4e02a --- /dev/null +++ b/test/fixtures/config/flags/nodeFlags/null/gulpfile.js @@ -0,0 +1,6 @@ +'use strict'; + +exports.default = function(done) { + console.log('Default'); + done(); +}; diff --git a/test/fixtures/config/flags/nodeFlags/undefined/.gulp.js b/test/fixtures/config/flags/nodeFlags/undefined/.gulp.js new file mode 100644 index 00000000..35082449 --- /dev/null +++ b/test/fixtures/config/flags/nodeFlags/undefined/.gulp.js @@ -0,0 +1,7 @@ +'use strict'; + +module.exports = { + flags: { + nodeFlags: undefined, + }, +}; diff --git a/test/fixtures/config/flags/nodeFlags/undefined/gulpfile.js b/test/fixtures/config/flags/nodeFlags/undefined/gulpfile.js new file mode 100644 index 00000000..b1e4e02a --- /dev/null +++ b/test/fixtures/config/flags/nodeFlags/undefined/gulpfile.js @@ -0,0 +1,6 @@ +'use strict'; + +exports.default = function(done) { + console.log('Default'); + done(); +}; diff --git a/test/fixtures/errors/bad-gulp-version/gulpfile.js b/test/fixtures/errors/bad-gulp-version/gulpfile.js new file mode 100644 index 00000000..e69de29b diff --git a/test/fixtures/errors/bad-gulp-version/node_modules/gulp/index.js b/test/fixtures/errors/bad-gulp-version/node_modules/gulp/index.js new file mode 100644 index 00000000..e69de29b diff --git a/test/fixtures/errors/bad-gulp-version/node_modules/gulp/package.json b/test/fixtures/errors/bad-gulp-version/node_modules/gulp/package.json new file mode 100644 index 00000000..dbe8ece4 --- /dev/null +++ b/test/fixtures/errors/bad-gulp-version/node_modules/gulp/package.json @@ -0,0 +1,15 @@ +{ + "name": "gulp", + "description": "Test Package for Testing!", + "version": "1.2.3", + "tags": [ + ], + "files": [ + ], + "licenses": [ + { + "type": "MIT", + "url": "https://raw.githubusercontent.com/gulpjs/gulp/master/LICENSE" + } + ] +} diff --git a/test/fixtures/errors/package.json b/test/fixtures/errors/package.json new file mode 100644 index 00000000..dbe8ece4 --- /dev/null +++ b/test/fixtures/errors/package.json @@ -0,0 +1,15 @@ +{ + "name": "gulp", + "description": "Test Package for Testing!", + "version": "1.2.3", + "tags": [ + ], + "files": [ + ], + "licenses": [ + { + "type": "MIT", + "url": "https://raw.githubusercontent.com/gulpjs/gulp/master/LICENSE" + } + ] +} diff --git a/test/fixtures/gulpfiles/gulpfile-dedup-errorlog.js b/test/fixtures/gulpfiles/gulpfile-dedup-errorlog.js new file mode 100644 index 00000000..a9066b64 --- /dev/null +++ b/test/fixtures/gulpfiles/gulpfile-dedup-errorlog.js @@ -0,0 +1,7 @@ +'use strict'; +var gulp = require('gulp'); +gulp.task('a', function() { + throw new Error('Task \'a\' failed!'); +}); +gulp.task('b', gulp.parallel('a')); +gulp.task('default', gulp.series(gulp.parallel('b'))); diff --git a/test/fixtures/packages/invalid-package.json b/test/fixtures/verify/invalid-package.json similarity index 100% rename from test/fixtures/packages/invalid-package.json rename to test/fixtures/verify/invalid-package.json diff --git a/test/fixtures/packages/package.json b/test/fixtures/verify/package.json similarity index 100% rename from test/fixtures/packages/package.json rename to test/fixtures/verify/package.json diff --git a/test/fixtures/packages/valid-package.json b/test/fixtures/verify/valid-package.json similarity index 100% rename from test/fixtures/packages/valid-package.json rename to test/fixtures/verify/valid-package.json diff --git a/test/flags-tasks-json.js b/test/flags-tasks-json.js index 364779ff..27b043d7 100644 --- a/test/flags-tasks-json.js +++ b/test/flags-tasks-json.js @@ -24,6 +24,25 @@ describe('flag: --tasks-json', function() { } }); + it('prints the task list with the default description', function(done) { + var cwdPath = __dirname; + var gulpfilePath = path.join(__dirname, 'fixtures/gulpfiles/gulpfile.js'); + runner({ verbose: false }) + .gulp('--tasks-json', + '--cwd ', cwdPath, + '--gulpfile ', gulpfilePath) + .run(cb); + + function cb(err, stdout, stderr) { + expect(err).toEqual(null); + expect(stderr).toEqual(''); + var jsonObj = JSON.parse(stdout); + expect(jsonObj.label).toMatch('Tasks for '); + expect(jsonObj.nodes).toEqual(expected.nodes); + done(err); + } + }); + it('writes the task list to file with path', function(done) { var output = path.join(__dirname, '/output/'); rimraf.sync(output); diff --git a/test/flags-verify.js b/test/flags-verify.js index e296b1ff..bb1dcbc9 100644 --- a/test/flags-verify.js +++ b/test/flags-verify.js @@ -9,7 +9,7 @@ describe('flag: --verify', function() { it('dependencies with invalid dependency', function(done) { runner({ verbose: false }) - .gulp('--verify invalid-package.json', '--cwd ./test/fixtures/packages/') + .gulp('--verify invalid-package.json', '--cwd ./test/fixtures/verify/') .run(cb); function cb(err, stdout, stderr) { @@ -18,7 +18,7 @@ describe('flag: --verify', function() { stdout = eraseTime(stdout); expect(stdout).toEqual( 'Verifying plugins in ' + - path.resolve('./test/fixtures/packages/invalid-package.json') + + path.resolve('./test/fixtures/verify/invalid-package.json') + '\n' + 'Blacklisted plugins found in this project:\n' + 'gulp-blink: deprecated. use `blink` instead.\n' + @@ -30,7 +30,7 @@ describe('flag: --verify', function() { it('dependencies with valid dependency', function(done) { runner({ verbose: false }) - .gulp('--verify valid-package.json', '--cwd ./test/fixtures/packages/') + .gulp('--verify valid-package.json', '--cwd ./test/fixtures/verify/') .run(cb); function cb(err, stdout, stderr) { @@ -39,7 +39,7 @@ describe('flag: --verify', function() { stdout = eraseTime(stdout); expect(stdout).toEqual( 'Verifying plugins in ' + - path.resolve('./test/fixtures/packages/valid-package.json') + + path.resolve('./test/fixtures/verify/valid-package.json') + '\n' + 'There are no blacklisted plugins in this project\n' + '' @@ -50,7 +50,7 @@ describe('flag: --verify', function() { it('default args with invalid dependency', function(done) { runner({ verbose: false }) - .gulp('--verify', '--cwd ./test/fixtures/packages/') + .gulp('--verify', '--cwd', path.resolve('./test/fixtures/verify/')) .run(cb); function cb(err, stdout, stderr) { @@ -59,7 +59,7 @@ describe('flag: --verify', function() { stdout = eraseTime(stdout); expect(stdout).toEqual( 'Verifying plugins in ' + - path.resolve('./test/fixtures/packages/package.json') + '\n' + + path.resolve('./test/fixtures/verify/package.json') + '\n' + 'Blacklisted plugins found in this project:\n' + 'gulp-blink: deprecated. use `blink` instead.\n' + '' diff --git a/test/flags-version.js b/test/flags-version.js index 39244e10..9ecfc9fc 100644 --- a/test/flags-version.js +++ b/test/flags-version.js @@ -2,6 +2,7 @@ var expect = require('expect'); var runner = require('gulp-test-tools').gulpRunner; +var os = require('os'); var cliVersion = require('../package.json').version; var gulpVersion = require('gulp/package.json').version; @@ -17,8 +18,8 @@ describe('flag: --version', function() { expect(err).toEqual(null); expect(stderr).toEqual(''); expect(stdout).toEqual( - 'CLI version ' + cliVersion + '\n' + - 'Local version ' + gulpVersion + '\n' + + 'CLI version: ' + cliVersion + '\n' + + 'Local version: ' + gulpVersion + '\n' + '' ); done(err); @@ -34,12 +35,28 @@ describe('flag: --version', function() { expect(err).toEqual(null); expect(stderr).toEqual(''); expect(stdout).toEqual( - 'CLI version ' + cliVersion + '\n' + - 'Local version ' + gulpVersion + '\n' + + 'CLI version: ' + cliVersion + '\n' + + 'Local version: ' + gulpVersion + '\n' + '' ); done(err); } }); + it('should print only CLI version when gulp is not found', function(done) { + runner({ verbose: false }) + .gulp('--version', '--cwd', os.tmpdir()) + .run(cb); + + function cb(err, stdout, stderr) { + expect(err).toEqual(null); + expect(stderr).toEqual(''); + expect(stdout).toEqual( + 'CLI version: ' + cliVersion + '\n' + + 'Local version: Unknown\n' + ); + done(err); + } + }); + });