diff --git a/.gitignore b/.gitignore index 3b569a93..9ad73290 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.log node_modules !test/fixtures/errors/bad-gulp-version/node_modules/ +!test/fixtures/config/theming/error/badGulpVersion/node_modules/ build *.node components diff --git a/index.js b/index.js index 1f928acb..e2683894 100644 --- a/index.js +++ b/index.js @@ -21,7 +21,7 @@ var theme = require('./lib/shared/log/theme'); var msgs = require('./lib/shared/log/messages'); var mergeProjectAndUserHomeConfigs = require('./lib/shared/config/merge-configs'); -var overrideEnvFlagsByConfigAndCliOpts = require('./lib/shared/config/env-flags'); +var overrideEnvByConfigAndCliOpts = require('./lib/shared/config/env-config'); // Get supported ranges var ranges = fs.readdirSync(path.join(__dirname, '/lib/versioned/')); @@ -100,7 +100,7 @@ module.exports = run; function onPrepare(env) { var cfg = mergeProjectAndUserHomeConfigs(env); - env = overrideEnvFlagsByConfigAndCliOpts(env, cfg, opts); + env = overrideEnvByConfigAndCliOpts(env, cfg, opts); // Set up event listeners for logging again after configuring. toConsole(log, env.config.flags); @@ -131,7 +131,6 @@ function onExecute(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')); @@ -139,7 +138,6 @@ function onExecute(env) { var hasYarn = fs.existsSync(path.join(env.cwd, 'yarn.lock')); var hasNpm = !hasYarn; - /* istanbul ignore if */ if (missingNodeModules) { log.error(msgs.error.nodeModulesNotFound, tildify(env.cwd), hasYarn, hasNpm); } else { diff --git a/lib/shared/config/env-flags.js b/lib/shared/config/env-config.js similarity index 78% rename from lib/shared/config/env-flags.js rename to lib/shared/config/env-config.js index 59b4d4be..4fc34e54 100644 --- a/lib/shared/config/env-flags.js +++ b/lib/shared/config/env-config.js @@ -5,6 +5,9 @@ var copyProps = require('copy-props'); var mergeCliOpts = require('./cli-flags'); +var theme = require('../log/theme'); +var msgs = require('../log/messages'); + var toEnvFromConfig = { configPath: 'flags.gulpfile', configBase: 'flags.gulpfile', @@ -12,7 +15,7 @@ var toEnvFromConfig = { nodeFlags: 'flags.nodeFlags', }; -function overrideEnvFlags(env, config, cliOpts) { +function overrideEnvConfig(env, config, cliOpts) { cliOpts = mergeCliOpts(cliOpts, config); // This must reverse because `flags.gulpfile` determines 2 different properties @@ -21,10 +24,18 @@ function overrideEnvFlags(env, config, cliOpts) { env.config = { flags: cliOpts, + theme: theme, + msgs: msgs, }; if (config.description) { env.config.description = config.description; } + if (config.theme) { + copyProps(config.theme, env.config.theme); + } + if (config.msgs) { + copyProps(config.msgs, env.config.msgs); + } return env function convert(configInfo, envInfo) { @@ -53,4 +64,4 @@ function overrideEnvFlags(env, config, cliOpts) { } } -module.exports = overrideEnvFlags; +module.exports = overrideEnvConfig; diff --git a/lib/shared/config/merge-configs.js b/lib/shared/config/merge-configs.js index 8202f182..e3c17a81 100644 --- a/lib/shared/config/merge-configs.js +++ b/lib/shared/config/merge-configs.js @@ -5,6 +5,7 @@ var path = require('path'); function mergeConfigs(env) { var cfg = {}; + /* istanbul ignore if */ if (env.configFiles.userHome) { copyConfig(env.config.userHome, cfg, env.configFiles.userHome); } diff --git a/lib/shared/log/messages.js b/lib/shared/log/messages.js index 642f94aa..c4f5937f 100644 --- a/lib/shared/log/messages.js +++ b/lib/shared/log/messages.js @@ -158,7 +158,7 @@ module.exports = { '{IF:{3:has cause}?\n{TIMESTAMP}{ERROR: {4:cause}}}', taskNotFound: - '{TIMESTAMP}{ERROR: Task never defined: {1:task}}\n' + + '{TIMESTAMP}{ERROR: Task never defined: {1:target task}{IF:{2:has similar tasks}? - did you mean? {3:similar tasks}}\n' + '{TIMESTAMP}{ERROR: To list available tasks, try running: gulp --tasks}', failToRun: diff --git a/lib/shared/log/tasks.js b/lib/shared/log/tasks.js index 1a6db4ed..b84791ed 100644 --- a/lib/shared/log/tasks.js +++ b/lib/shared/log/tasks.js @@ -15,7 +15,7 @@ function logTasks(tree, opts, getTask) { var maxDepth = opts.tasksDepth; if (typeof maxDepth !== 'number') { maxDepth = 50; - } else if (maxDepth < 1) { + } else /* istanbul ignore if */ if (maxDepth < 1) { maxDepth = 1; } @@ -38,7 +38,7 @@ function printTaskTree(tree, opts) { tree.nodes.forEach(function(node, idx, arr) { var isLast = idx === arr.length - 1; var w = createTreeLines(node, lines, opts, 1, '', isLast); - maxLabelWidth = Math.max(maxLabelWidth, w || 0); + maxLabelWidth = Math.max(maxLabelWidth, w || /* istanbul ignore next */ 0); }); lines.forEach(function(line) { diff --git a/lib/shared/log/timestamp.js b/lib/shared/log/timestamp.js index 99c71d46..4e9dd9a6 100644 --- a/lib/shared/log/timestamp.js +++ b/lib/shared/log/timestamp.js @@ -1,6 +1,7 @@ 'use strict'; function timestamp(format) { + /* istanbul ignore if */ if (typeof format !== 'string') { return noop; } @@ -42,6 +43,7 @@ function timestamp(format) { return result; } +/* istanbul ignore next */ function noop() { return ""; } diff --git a/lib/shared/log/to-console.js b/lib/shared/log/to-console.js index 9bcf3335..844343aa 100644 --- a/lib/shared/log/to-console.js +++ b/lib/shared/log/to-console.js @@ -16,11 +16,12 @@ var levels = [ ]; function consoleLog(s) { - if (s != null) console.log(s); + if (s) console.log(s); } function consoleError(s) { - if (s != null) console.error(s); + /* istanbul ignore else */ + if (s) console.error(s); } function cleanup(log) { diff --git a/lib/versioned/^3.7.0/index.js b/lib/versioned/^3.7.0/index.js index 7da49d19..77c45b87 100644 --- a/lib/versioned/^3.7.0/index.js +++ b/lib/versioned/^3.7.0/index.js @@ -54,14 +54,14 @@ function execute(env) { } if (opts.tasks) { tree = taskTree(gulpInst.tasks); - tree.label = getTasksDescription(env); + tree.label = getTasksDescription(env, true); return logTasks(tree, opts, function(task) { return gulpInst.tasks[task].fn; }); } if (opts.tasksJson) { tree = taskTree(gulpInst.tasks); - tree.label = getTasksDescription(env); + tree.label = getTasksDescription(env, false); var output = JSON.stringify(copyTree(tree, opts)); diff --git a/lib/versioned/^3.7.0/log/tasks-description.js b/lib/versioned/^3.7.0/log/tasks-description.js index 031ff59e..fe19e397 100644 --- a/lib/versioned/^3.7.0/log/tasks-description.js +++ b/lib/versioned/^3.7.0/log/tasks-description.js @@ -5,14 +5,22 @@ var tildify = require('../../../shared/tildify'); var theme = require('../../../shared/log/theme'); var msgs = require('../../../shared/log/messages'); -function getTasksDescription(env) { +function getTasksDescription(env, isBackslashEscaping) { var desc; if (env.config.description && typeof env.config.description === 'string') { desc = env.config.description; } else { desc = msgs.tasks.gulpfile; } - return format(theme, desc, tildify(env.configPath)); + var gulpfile = tildify(env.configPath); + if (isBackslashEscaping) { + gulpfile = escapeBackslash(gulpfile); + } + return format(theme, desc, gulpfile); +} + +function escapeBackslash(s) { + return s.replace(/\\/g, '\\\\'); } module.exports = getTasksDescription; diff --git a/lib/versioned/^4.0.0-alpha.1/index.js b/lib/versioned/^4.0.0-alpha.1/index.js index 845a1b85..06d700e0 100644 --- a/lib/versioned/^4.0.0-alpha.1/index.js +++ b/lib/versioned/^4.0.0-alpha.1/index.js @@ -55,7 +55,7 @@ function execute(env) { } if (opts.tasks) { tree = {}; - tree.label = getTasksDescription(env); + tree.label = getTasksDescription(env, true); tree.nodes = gulpInst.tree({ deep: true }); return logTasks(tree, opts, function(taskname) { @@ -64,7 +64,7 @@ function execute(env) { } if (opts.tasksJson) { tree = {}; - tree.label = getTasksDescription(env); + tree.label = getTasksDescription(env, false); tree.nodes = gulpInst.tree({ deep: true }); var output = JSON.stringify(copyTree(tree, opts)); @@ -82,9 +82,9 @@ function execute(env) { } }); } catch (err) { - var taskName = checkTaskNotFound(err); - if (taskName) { - log.error(msgs.error.taskNotFound, taskName); + var task = checkTaskNotFound(err); + if (task) { + log.error(msgs.error.taskNotFound, task.target, Boolean(task.similar), task.similar); } else { log.error(msgs.error.failToRun, err.message); } diff --git a/lib/versioned/^4.0.0-alpha.2/index.js b/lib/versioned/^4.0.0-alpha.2/index.js index 058559ae..23a75047 100644 --- a/lib/versioned/^4.0.0-alpha.2/index.js +++ b/lib/versioned/^4.0.0-alpha.2/index.js @@ -57,12 +57,12 @@ function execute(env) { } if (opts.tasks) { tree = gulpInst.tree({ deep: true }); - tree.label = getTasksDescription(env); + tree.label = getTasksDescription(env, true); return logTasks(tree, opts, getTask(gulpInst)); } if (opts.tasksJson) { tree = gulpInst.tree({ deep: true }); - tree.label = getTasksDescription(env); + tree.label = getTasksDescription(env, false); var output = JSON.stringify(copyTree(tree, opts)); @@ -80,9 +80,9 @@ function execute(env) { } }); } catch (err) { - var taskName = checkTaskNotFound(err); - if (taskName) { - log.error(msgs.error.taskNotFound, taskName); + var task = checkTaskNotFound(err); + if (task) { + log.error(msgs.error.taskNotFound, task.target, Boolean(task.similar), task.similar); } else { log.error(msgs.error.failToRun, err.message); } diff --git a/lib/versioned/^4.0.0/index.js b/lib/versioned/^4.0.0/index.js index a46a8cef..cedd4290 100644 --- a/lib/versioned/^4.0.0/index.js +++ b/lib/versioned/^4.0.0/index.js @@ -57,12 +57,12 @@ function execute(env) { } if (opts.tasks) { tree = gulpInst.tree({ deep: true }); - tree.label = getTasksDescription(env); + tree.label = getTasksDescription(env, true); return logTasks(tree, opts, getTask(gulpInst)); } if (opts.tasksJson) { tree = gulpInst.tree({ deep: true }); - tree.label = getTasksDescription(env); + tree.label = getTasksDescription(env, false); var output = JSON.stringify(copyTree(tree, opts)); @@ -80,9 +80,9 @@ function execute(env) { } }); } catch (err) { - var taskName = checkTaskNotFound(err); - if (taskName) { - log.error(msgs.error.taskNotFound, taskName); + var task = checkTaskNotFound(err); + if (task) { + log.error(msgs.error.taskNotFound, task.target, Boolean(task.similar), task.similar); } else { log.error(msgs.error.failToRun, err.message); } diff --git a/lib/versioned/^4.0.0/log/check-task-not-found.js b/lib/versioned/^4.0.0/log/check-task-not-found.js index fb45d7fd..e996f212 100644 --- a/lib/versioned/^4.0.0/log/check-task-not-found.js +++ b/lib/versioned/^4.0.0/log/check-task-not-found.js @@ -1,10 +1,24 @@ 'use strict'; function checkTaskNotFound(err) { - var result = /^Task never defined: +(.*)$/.exec(err.message); - /* istanbul ignore else */ - if (result) { - return result[1]; + /* istanbul ignore if */ + if (!err || !err.message) { + return undefined; + } + var fixed0 = 'Task never defined: '; + var fixed1 = ' - did you mean? '; + + if (err.message.startsWith(fixed0)) { + var target = err.message.slice(fixed0.length); + var similar = undefined; + + var index = target.indexOf(fixed1); + if (index >= 0) { + similar = target.slice(index + fixed1.length); + target = target.slice(0, index); + } + + return { target: target, similar: similar }; } } diff --git a/lib/versioned/^4.0.0/log/tasks-description.js b/lib/versioned/^4.0.0/log/tasks-description.js index 031ff59e..fe19e397 100644 --- a/lib/versioned/^4.0.0/log/tasks-description.js +++ b/lib/versioned/^4.0.0/log/tasks-description.js @@ -5,14 +5,22 @@ var tildify = require('../../../shared/tildify'); var theme = require('../../../shared/log/theme'); var msgs = require('../../../shared/log/messages'); -function getTasksDescription(env) { +function getTasksDescription(env, isBackslashEscaping) { var desc; if (env.config.description && typeof env.config.description === 'string') { desc = env.config.description; } else { desc = msgs.tasks.gulpfile; } - return format(theme, desc, tildify(env.configPath)); + var gulpfile = tildify(env.configPath); + if (isBackslashEscaping) { + gulpfile = escapeBackslash(gulpfile); + } + return format(theme, desc, gulpfile); +} + +function escapeBackslash(s) { + return s.replace(/\\/g, '\\\\'); } module.exports = getTasksDescription; diff --git a/test/config-theme-and-msgs.js b/test/config-theme-and-msgs.js new file mode 100644 index 00000000..89032891 --- /dev/null +++ b/test/config-theme-and-msgs.js @@ -0,0 +1,561 @@ +'use strict'; + +var expect = require('expect'); +var exec = require('child_process').exec; +var path = require('path'); +var fs = require('fs'); +var os = require('os'); + +var tildify = require('../lib/shared/tildify'); + +var baseDir = path.join(__dirname, 'fixtures/config/theming'); +var expectedDir = path.join(__dirname, 'expected/config/theming'); + +var eraseTime = require('./tool/erase-time'); +var eraseLapse = require('./tool/erase-lapse'); +var gulp = require('./tool/gulp-cmd'); + +describe('config: theme.* & msgs.*', function() { + + it('Should change help.usage with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'help/usage'); + var expected =fs.readFileSync(path.join(expectedDir, 'help/usage/help.txt'), 'utf8'); + + var opts = { cwd: cwd }; + exec(gulp('--help'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseTime(stdout)).toEqual(expected); + done(err); + } + }); + + it('Should change help.flags.* with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'help/flags'); + var expected =fs.readFileSync(path.join(expectedDir, 'help/flags/help.txt'), 'utf8'); + + var opts = { cwd: cwd }; + exec(gulp('--help'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseTime(stdout)).toEqual(expected); + done(err); + } + }); + + it('Should change tasks.gulpfile with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'tasks/gulpfile'); + var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); + var expected = '** ' + gulpfile + ' **\n' + + '└── default\n'; + + var opts = { cwd: cwd }; + exec(gulp('--tasks'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(stdout).toEqual(expected); + done(err); + } + }); + + it('Should remove task.gulpfile line output with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'tasks/gulpfile/remove'); + var expected = '└── default\n'; + + var opts = { cwd: cwd }; + exec(gulp('--tasks'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(stdout).toEqual(expected); + done(err); + } + }); + + it('Should change tasks.topTask with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'tasks/topTask'); + var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); + var expected = 'Tasks for ' + gulpfile + '\n' + + '├─┬ **default** This is default task\n' + + '│ │ --ghi …is a flag for default task\n' + + '│ └─┬ \n' + + '│ ├── taskA\n' + + '│ └── taskB\n' + + '├── **taskA** This is task A\n' + + '│ --abc …is a flag for task A\n' + + '└── **taskB** This is task B\n' + + ' --def …is a flag for task B\n'; + + var opts = { cwd: cwd }; + exec(gulp('--tasks'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(stdout).toEqual(expected); + done(err); + } + }); + + it('Should change tasks.option with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'tasks/option'); + var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); + var expected = 'Tasks for ' + gulpfile + '\n' + + '├─┬ default This is default task\n' + + '│ │ **--ghi** » is a flag for default task\n' + + '│ └─┬ \n' + + '│ ├── taskA\n' + + '│ └── taskB\n' + + '├── taskA This is task A\n' + + '│ **--abc** » is a flag for task A\n' + + '└── taskB This is task B\n' + + ' **--def** » is a flag for task B\n'; + + var opts = { cwd: cwd }; + exec(gulp('--tasks'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(stdout).toEqual(expected); + done(err); + } + }); + + it('Should change tasks.childTask with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'tasks/childTask'); + var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); + var expected = 'Tasks for ' + gulpfile + '\n' + + '├─┬ default This is default task\n' + + '│ │ --ghi …is a flag for default task\n' + + '│ └─┬ ****\n' + + '│ ├── **taskA**\n' + + '│ └── **taskB**\n' + + '├── taskA This is task A\n' + + '│ --abc …is a flag for task A\n' + + '└── taskB This is task B\n' + + ' --def …is a flag for task B\n'; + + var opts = { cwd: cwd }; + exec(gulp('--tasks'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(stdout).toEqual(expected); + done(err); + } + }); + + it('Should change tasksJson.gulpfile with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'tasksJson/gulpfile'); + var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); + var expected = JSON.stringify({ + label: '** ' + gulpfile + ' **', + nodes: [{ + label: 'default', + type: 'task', + nodes: [], + }], + }) + '\n'; + + var opts = { cwd: cwd }; + exec(gulp('--tasks-json'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(stdout).toEqual(expected); + done(err); + } + }); + + it('Should change info.preloadBefore with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'info/preloadBefore'); + var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); + var expected = 'PRELOADING **./preload**\n' + + 'Preloaded external module: ./preload\n' + + 'Using gulpfile ' + gulpfile + '\n' + + 'Starting \'default\'...\n' + + 'Finished \'default\' after ?\n'; + + var opts = { cwd: cwd }; + exec(gulp('--preload ./preload'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseLapse(eraseTime(stdout))).toEqual(expected); + done(err); + } + }); + + it('Should change info.preloadSuccess with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'info/preloadSuccess'); + var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); + var expected = 'Preloading external module: ./preload\n' + + 'PRELOADDED **./preload**\n' + + 'Using gulpfile ' + gulpfile + '\n' + + 'Starting \'default\'...\n' + + 'Finished \'default\' after ?\n'; + + var opts = { cwd: cwd }; + exec(gulp('--preload ./preload'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseLapse(eraseTime(stdout))).toEqual(expected); + done(err); + } + }); + + it('Should change info.loaderSuccess with .gulp.*', function(done) { + this.timeout(0); + + var cwd = path.join(baseDir, 'info/loaderSuccess'); + var gulpfile = tildify(path.join(cwd, 'gulpfile.babel.js')); + var expected = 'LOADED **@babel/register**\n' + + 'Using gulpfile ' + gulpfile + '\n' + + 'Starting \'default\'...\n' + + 'Finished \'default\' after ?\n'; + + var opts = { cwd: cwd }; + exec(gulp('-f gulpfile.babel.js'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseLapse(eraseTime(stdout))).toEqual(expected); + done(err); + } + }); + + it('Should change info.respawn with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'info/respawn'); + var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); + var expected = 'RESPAWN BY **--lazy**\n' + + 'Using gulpfile ' + gulpfile + '\n' + + 'Starting \'default\'...\n' + + 'Finished \'default\' after ?\n'; + + var opts = { cwd: cwd }; + exec(gulp('--lazy'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseLapse(eraseTime(stdout))).toEqual(expected); + done(err); + } + }); + + it('Should change info.version with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'info/version'); + var expected = /gulp-cli @@v\d.\d.\d@@ | gulp @@v\d.\d.\d@@\n/; + + var opts = { cwd: cwd }; + exec(gulp('--version'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(stdout).toMatch(expected); + done(err); + } + }); + + it('Should change info.cwdChanged with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'info/cwdChanged'); + var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); + var expected = 'CHANGE CWD TO **' + tildify(cwd) + '**\n' + + 'Using gulpfile ' + gulpfile + '\n' + + 'Starting \'default\'...\n' + + 'Finished \'default\' after ?\n'; + + var opts = { cwd: baseDir }; + exec(gulp('--cwd ' + cwd), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseLapse(eraseTime(stdout))).toEqual(expected); + done(err); + } + }); + + it('Should change info.usingGulpfile with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'info/usingGulpfile'); + var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); + var expected = 'USING GULPFILE **' + gulpfile + '**\n' + + 'Starting \'default\'...\n' + + 'Finished \'default\' after ?\n'; + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseLapse(eraseTime(stdout))).toEqual(expected); + done(err); + } + }); + + it('Should change info.taskStart with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'info/taskStart'); + var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); + var expected = 'Using gulpfile ' + gulpfile + '\n' + + 'START **default**\n' + + 'Finished \'default\' after ?\n'; + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseLapse(eraseTime(stdout))).toEqual(expected); + done(err); + } + }); + + it('Should change info.taskStop with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'info/taskStop'); + var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); + var expected = 'Using gulpfile ' + gulpfile + '\n' + + 'Starting \'default\'...\n' + + 'STOP **default**\n'; + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseTime(stdout)).toEqual(expected); + done(err); + } + }); + + it('Should change warn.preloadFailure with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'warn/preloadFailure'); + var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); + var expected = 'Preloading external module: null-module\n' + + 'FAILED TO PRELOAD **null-module**\n' + + 'Using gulpfile ' + gulpfile + '\n' + + 'Starting \'default\'...\n' + + 'Finished \'default\' after ?\n'; + + var opts = { cwd: cwd }; + exec(gulp('--preload null-module'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseLapse(eraseTime(stdout))).toEqual(expected); + done(err); + } + }); + + it('Should change warn.loaderFailure with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'warn/loaderFailure'); + var expected = 'FAIL TO LOAD **coffeescript/register**\n'; + + var opts = { cwd: cwd }; + exec(gulp('-f gulpfile.coffee'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stderr).not.toEqual(''); + expect(eraseTime(stdout)).toEqual(expected); + done(); + } + }); + + it('Should change warn.taskNotComplete with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'warn/taskNotComplete'); + var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); + var expected = 'Using gulpfile ' + gulpfile + '\n' + + 'Starting \'default\'...\n' + + 'TASK **default** DID NOT COMPLETE\n'; + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stderr).toEqual(''); + expect(eraseTime(stdout)).toEqual(expected); + done(); + } + }); + + it('Should change error.gulpNotFound with .gulp.*', function(done) { + var dir = path.join(baseDir, 'error/gulpNotFound'); + var cwd = os.tmpdir(); + fs.copyFileSync(path.join(dir, '.gulp.js'), path.join(cwd, '.gulp.js')); + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + if (os.platform() === 'darwin') { + cwd = path.join('/private', cwd); + } + var expected = 'GULP NOT FOUND IN **' + cwd + '**\n'; + + function cb(err, stdout, stderr) { + try { + expect(err).not.toBeNull(); + expect(stdout).toEqual(''); + expect(stderr).toEqual(expected); + done(); + } finally { + fs.unlinkSync(path.join(cwd, '.gulp.js')); + } + } + }); + + it('Should change error.nodeModulesNotFound with .gulp.*', function(done) { + var dir = path.join(baseDir, 'error/nodeModulesNotFound'); + var cwd = os.tmpdir(); + fs.copyFileSync(path.join(dir, '.gulp.js'), path.join(cwd, '.gulp.js')); + fs.copyFileSync(path.join(dir, 'package.json'), path.join(cwd, 'package.json')); + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + if (os.platform() === 'darwin') { + cwd = path.join('/private', cwd); + } + var expected = 'LOCAL MODULE NOT FOUND **' + cwd + '**\n'; + + function cb(err, stdout, stderr) { + try { + expect(err).not.toBeNull(); + expect(stdout).toEqual(''); + expect(stderr).toEqual(expected); + done(); + } finally { + fs.unlinkSync(path.join(cwd, '.gulp.js')); + fs.unlinkSync(path.join(cwd, 'package.json')); + } + } + }); + + it('Should change error.gulpfileNotFound with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'error/gulpfileNotFound'); + var expected = 'NO GULPFILE\n'; + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stdout).toEqual(''); + expect(eraseTime(stderr)).toEqual(expected); + done(); + } + }); + + it('Should change error.badGulpVersion with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'error/badGulpVersion'); + var expected = 'BAD GULP VERSION **1.2.3**\n'; + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stdout).toEqual(''); + expect(eraseTime(stderr)).toEqual(expected); + done(); + } + }); + + it('Should change error.taskError with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'error/taskError'); + var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); + var expectedStdout = 'Using gulpfile ' + gulpfile + '\n' + + 'Starting \'default\'...\n'; + var expectedStderr = 'TASK ERROR: **default**\n'; + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(eraseTime(stderr)).toEqual(expectedStderr); + expect(eraseTime(stdout)).toEqual(expectedStdout); + done(); + } + }); + + it('Should change error.taskNotFound with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'error/taskNotFound'); + var gulpfile = tildify(path.join(cwd, 'gulpfile.js')); + var expectedStdout = 'Using gulpfile ' + gulpfile + '\n'; + var expectedStderr = 'TASK IS NOT FOUND: **defaults** SIMILAR ##default##'; + + var opts = { cwd: cwd }; + exec(gulp('defaults'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(eraseTime(stderr)).toMatch(expectedStderr); + expect(eraseTime(stdout)).toEqual(expectedStdout); + done(); + } + }); + + it('Should change error.failToRun with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'error/failToRun'); + var expected = 'FAIL TO RUN\n'; + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stderr).toEqual(expected); + expect(stdout).toEqual(''); + done(); + } + }); + + it('Should change error.noCompletionType with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'error/noCompletionType'); + var expected = 'NO COMPLETION TYPE'; + + var opts = { cwd: cwd }; + exec(gulp('--completion'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stderr).toMatch(expected); + expect(stdout).toEqual(''); + done(); + } + }); + + it('Should change error.unknownCompletionType with .gulp.*', function(done) { + var cwd = path.join(baseDir, 'error/unknownCompletionType'); + var expected = 'GULP COMPLETION TYPE **xxx** IS NOT FOUND\n'; + + var opts = { cwd: cwd }; + exec(gulp('--completion=xxx'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stderr).toEqual(''); + expect(stdout).toEqual(expected); + done(); + } + }); +}); diff --git a/test/execution-errors.js b/test/execution-errors.js index 769832a9..7b2fd1ec 100644 --- a/test/execution-errors.js +++ b/test/execution-errors.js @@ -4,6 +4,7 @@ var expect = require('expect'); var exec = require('child_process').exec; var path = require('path'); var os = require('os'); +var fs = require('fs'); var tildify = require('../lib/shared/tildify'); @@ -29,6 +30,21 @@ describe('execution error', function() { } }); + it('should output an error if a task is not defined but a similar task is found', function(done) { + var opts = { cwd: path.join(__dirname, './fixtures/gulpfiles') }; + exec(gulp('test0'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(err.code).toEqual(1); + expect(eraseTime(stdout)).toMatch('Using gulpfile '); + expect(eraseTime(stderr)).toEqual( + 'Task never defined: test0 - did you mean? test1, test2, test3, test4, test5, test6, test7, test8\n' + + 'To list available tasks, try running: gulp --tasks\n'); + done(); + } + }); + it('should output an error if gulp version is unsupported', function(done) { var opts = { cwd: path.join(__dirname, './fixtures/errors/bad-gulp-version') }; exec(gulp(), opts, cb); @@ -42,7 +58,7 @@ describe('execution error', function() { } }); - it('should output an error if gulp is not found', function(done) { + it('should output an error if gulp is not found (npm)', function(done) { var opts = { cwd: os.tmpdir() }; exec(gulp(), opts, cb); @@ -55,6 +71,79 @@ describe('execution error', function() { } }); + it('should output an error if gulp is not found (yarn)', function(done) { + var cwd = os.tmpdir(); + var yarnOrig= path.join(__dirname, 'fixtures/errors/yarn/yarn.lock'); + var yarnLock = path.join(cwd, 'yarn.lock'); + + fs.copyFileSync(yarnOrig, yarnLock); + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + try { + expect(err).not.toBeNull(); + expect(err.code).toEqual(1); + expect(sliceLines(stderr, 0, 1)).toMatch('Local gulp not found in '); + expect(sliceLines(stderr, 1, 2)).toEqual('Try running: yarn add gulp'); + done(); + } finally { + fs.unlinkSync(yarnLock); + } + } + }); + + it('should output an error if local modules are not found (npm)', function(done) { + var cwd = os.tmpdir(); + var pkgOrig = path.join(__dirname, 'fixtures/errors/package.json'); + var pkgJson = path.join(cwd, 'package.json'); + + fs.copyFileSync(pkgOrig, pkgJson); + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + try { + expect(err).not.toBeNull(); + expect(err.code).toEqual(1); + expect(sliceLines(stderr, 0, 1)).toMatch('Local modules not found in '); + expect(sliceLines(stderr, 1, 2)).toEqual('Try running: npm install'); + done(); + } finally { + fs.unlinkSync(pkgJson); + } + } + }); + + it('should output an error if local modules are not found (yarn)', function(done) { + var cwd = os.tmpdir(); + var pkgOrig = path.join(__dirname, 'fixtures/errors/package.json'); + var pkgJson = path.join(cwd, 'package.json'); + var yarnOrig= path.join(__dirname, 'fixtures/errors/yarn/yarn.lock'); + var yarnLock = path.join(cwd, 'yarn.lock'); + + fs.copyFileSync(pkgOrig, pkgJson); + fs.copyFileSync(yarnOrig, yarnLock); + + var opts = { cwd: cwd }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + try { + expect(err).not.toBeNull(); + expect(err.code).toEqual(1); + expect(sliceLines(stderr, 0, 1)).toMatch('Local modules not found in '); + expect(sliceLines(stderr, 1, 2)).toEqual('Try running: yarn install'); + done(); + } finally { + fs.unlinkSync(pkgJson); + fs.unlinkSync(yarnLock); + } + } + }); + it('should log a same error once', function(done) { var dir = path.join(__dirname, 'fixtures/gulpfiles'); var gulpfileName = 'gulpfile-dedup-errorlog.js'; diff --git a/test/expected/config/theming/help/flags/help.txt b/test/expected/config/theming/help/flags/help.txt new file mode 100644 index 00000000..3fae82da --- /dev/null +++ b/test/expected/config/theming/help/flags/help.txt @@ -0,0 +1,21 @@ + +Usage: gulp [options] tasks + +Options: + -h, --help **HELP** [boolean] + -v, --version **VERSION** [boolean] + --preload **PRELOAD** [string] + -f, --gulpfile **GULPFILE** [string] + --cwd **CWD** [string] + -T, --tasks **TASKS** [boolean] + --tasks-simple **TASKS SIMPLE** [boolean] + --tasks-json **TASKS JSON** + --tasks-depth, --depth **TASKS DEPTH** [number] + --compact-tasks **COMPACT TASKS** [boolean] + --sort-tasks **SORT_TASKS** [boolean] + --color **COLOR** [boolean] + --no-color **NO COLOR** [boolean] + -S, --silent **SILENT** [boolean] + --continue **CONTINUE** [boolean] + --series **SERIES** [boolean] + -L, --log-level **LOG LEVEL** [count] diff --git a/test/expected/config/theming/help/usage/help.txt b/test/expected/config/theming/help/usage/help.txt new file mode 100644 index 00000000..b03f78bd --- /dev/null +++ b/test/expected/config/theming/help/usage/help.txt @@ -0,0 +1,39 @@ +GULP USAGE + +Options: + -h, --help Show this help. [boolean] + -v, --version Print the global and local gulp versions.[boolean] + --preload Will preload a module before running the gulpfile. + This is useful for transpilers but also has other + applications. [string] + -f, --gulpfile Manually set path of gulpfile. Useful if you have + multiple gulpfiles. This will set the CWD to the + gulpfile directory as well. [string] + --cwd Manually set the CWD. The search for the gulpfile, + as well as the relativity of all requires will be + from here. [string] + -T, --tasks Print the task dependency tree for the loaded + gulpfile. [boolean] + --tasks-simple Print a plaintext list of tasks for the loaded + gulpfile. [boolean] + --tasks-json Print the task dependency tree, in JSON format, + for the loaded gulpfile. + --tasks-depth, --depth Specify the depth of the task dependency tree. + [number] + --compact-tasks Reduce the output of task dependency tree by + printing only top tasks and their child tasks. + [boolean] + --sort-tasks Will sort top tasks of task dependency tree. + [boolean] + --color Will force gulp and gulp plugins to display + colors, even when no color support is detected. + [boolean] + --no-color Will force gulp and gulp plugins to not display + colors, even when color support is detected. + [boolean] + -S, --silent Suppress all gulp logging. [boolean] + --continue Continue execution of tasks upon failure.[boolean] + --series Run tasks given on the CLI in series (the default + is parallel). [boolean] + -L, --log-level Set the loglevel. -L for least verbose and -LLLL + for most verbose. -LLL is default. [count] diff --git a/test/fixtures/config/theming/error/badGulpVersion/.gulp.js b/test/fixtures/config/theming/error/badGulpVersion/.gulp.js new file mode 100644 index 00000000..d923bd09 --- /dev/null +++ b/test/fixtures/config/theming/error/badGulpVersion/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + error: { + badGulpVersion: '{TIMESTAMP}BAD GULP VERSION {GulpVer:{1}}', + }, + }, + theme: { + GulpVer: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/error/badGulpVersion/gulpfile.js b/test/fixtures/config/theming/error/badGulpVersion/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/error/badGulpVersion/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/error/badGulpVersion/node_modules/gulp/index.js b/test/fixtures/config/theming/error/badGulpVersion/node_modules/gulp/index.js new file mode 100644 index 00000000..e69de29b diff --git a/test/fixtures/config/theming/error/badGulpVersion/node_modules/gulp/package.json b/test/fixtures/config/theming/error/badGulpVersion/node_modules/gulp/package.json new file mode 100644 index 00000000..dbe8ece4 --- /dev/null +++ b/test/fixtures/config/theming/error/badGulpVersion/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/config/theming/error/failToRun/.gulp.js b/test/fixtures/config/theming/error/failToRun/.gulp.js new file mode 100644 index 00000000..c93d52de --- /dev/null +++ b/test/fixtures/config/theming/error/failToRun/.gulp.js @@ -0,0 +1,8 @@ +module.exports = { + msgs: { + info: null, // To cause failToRun error forcefully + error: { + failToRun: 'FAIL TO RUN', + }, + }, +}; diff --git a/test/fixtures/config/theming/error/failToRun/gulpfile.js b/test/fixtures/config/theming/error/failToRun/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/error/failToRun/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/error/gulpNotFound/.gulp.js b/test/fixtures/config/theming/error/gulpNotFound/.gulp.js new file mode 100644 index 00000000..3d8bb0b4 --- /dev/null +++ b/test/fixtures/config/theming/error/gulpNotFound/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + error: { + gulpNotFound: 'GULP NOT FOUND IN {CwdPath: {1}}', + }, + }, + theme: { + CwdPath: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/error/gulpfileNotFound/.gulp.js b/test/fixtures/config/theming/error/gulpfileNotFound/.gulp.js new file mode 100644 index 00000000..a96938cb --- /dev/null +++ b/test/fixtures/config/theming/error/gulpfileNotFound/.gulp.js @@ -0,0 +1,7 @@ +module.exports = { + msgs: { + error: { + gulpfileNotFound: '{TIMESTAMP}NO GULPFILE', + }, + }, +}; diff --git a/test/fixtures/config/theming/error/noCompletionType/.gulp.js b/test/fixtures/config/theming/error/noCompletionType/.gulp.js new file mode 100644 index 00000000..6817dbf5 --- /dev/null +++ b/test/fixtures/config/theming/error/noCompletionType/.gulp.js @@ -0,0 +1,7 @@ +module.exports = { + msgs: { + error: { + noCompletionType: 'NO COMPLETION TYPE', + }, + }, +}; diff --git a/test/fixtures/config/theming/error/noCompletionType/gulpfile.js b/test/fixtures/config/theming/error/noCompletionType/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/error/noCompletionType/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/error/nodeModulesNotFound/.gulp.js b/test/fixtures/config/theming/error/nodeModulesNotFound/.gulp.js new file mode 100644 index 00000000..2576d4cc --- /dev/null +++ b/test/fixtures/config/theming/error/nodeModulesNotFound/.gulp.js @@ -0,0 +1,12 @@ +var os = require('os'); + +module.exports = { + msgs: { + error: { + nodeModulesNotFound: 'LOCAL MODULE NOT FOUND {Path: {1}}', + }, + }, + theme: { + Path: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/error/nodeModulesNotFound/package.json b/test/fixtures/config/theming/error/nodeModulesNotFound/package.json new file mode 100644 index 00000000..109ec6a8 --- /dev/null +++ b/test/fixtures/config/theming/error/nodeModulesNotFound/package.json @@ -0,0 +1,12 @@ +{ + "name": "nodeModulesNotFound", + "version": "1.0.0", + "description": "", + "main": ".gulp.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC" +} diff --git a/test/fixtures/config/theming/error/taskError/.gulp.js b/test/fixtures/config/theming/error/taskError/.gulp.js new file mode 100644 index 00000000..534a1456 --- /dev/null +++ b/test/fixtures/config/theming/error/taskError/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + error: { + taskError: '{TIMESTAMP}TASK ERROR: {TaskName:{1}}', + }, + }, + theme: { + TaskName: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/error/taskError/gulpfile.js b/test/fixtures/config/theming/error/taskError/gulpfile.js new file mode 100644 index 00000000..eeb90fd6 --- /dev/null +++ b/test/fixtures/config/theming/error/taskError/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + throw new Error('FAIL!'); +} diff --git a/test/fixtures/config/theming/error/taskNotFound/.gulp.js b/test/fixtures/config/theming/error/taskNotFound/.gulp.js new file mode 100644 index 00000000..12545808 --- /dev/null +++ b/test/fixtures/config/theming/error/taskNotFound/.gulp.js @@ -0,0 +1,11 @@ +module.exports = { + msgs: { + error: { + taskNotFound: '{TIMESTAMP}TASK IS NOT FOUND: {TaskName:{1}}{IF:{2}? SIMILAR {SimilarTasks:{3}}}', + }, + }, + theme: { + TaskName: '**{1}**', + SimilarTasks: '##{1}##', + }, +}; diff --git a/test/fixtures/config/theming/error/taskNotFound/gulpfile.js b/test/fixtures/config/theming/error/taskNotFound/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/error/taskNotFound/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/error/unknownCompletionType/.gulp.js b/test/fixtures/config/theming/error/unknownCompletionType/.gulp.js new file mode 100644 index 00000000..0676f0a8 --- /dev/null +++ b/test/fixtures/config/theming/error/unknownCompletionType/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + error: { + unknownCompletionType: 'GULP COMPLETION TYPE {Type: {1}} IS NOT FOUND', + }, + }, + theme: { + Type: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/error/unknownCompletionType/gulpfile.js b/test/fixtures/config/theming/error/unknownCompletionType/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/error/unknownCompletionType/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/help/flags/.gulp.js b/test/fixtures/config/theming/help/flags/.gulp.js new file mode 100644 index 00000000..1a008528 --- /dev/null +++ b/test/fixtures/config/theming/help/flags/.gulp.js @@ -0,0 +1,28 @@ +module.exports = { + msgs: { + help: { + flags: { + help: '{help_desc: HELP}', + version: '{help_desc: VERSION}', + preload: '{help_desc: PRELOAD}', + gulpfile: '{help_desc: GULPFILE}', + cwd: '{help_desc: CWD}', + tasks: '{help_desc: TASKS}', + 'tasks-simple': '{help_desc: TASKS SIMPLE}', + 'tasks-json': '{help_desc: TASKS JSON}', + 'tasks-depth': '{help_desc: TASKS DEPTH}', + 'compact-tasks': '{help_desc: COMPACT TASKS}', + 'sort-tasks': '{help_desc: SORT_TASKS}', + color: '{help_desc: COLOR}', + 'no-color': '{help_desc: NO COLOR}', + silent: '{help_desc: SILENT}', + continue: '{help_desc: CONTINUE}', + series: '{help_desc: SERIES}', + 'log-level': '{help_desc: LOG LEVEL}', + }, + }, + }, + theme: { + help_desc: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/help/usage/.gulp.js b/test/fixtures/config/theming/help/usage/.gulp.js new file mode 100644 index 00000000..f96d44df --- /dev/null +++ b/test/fixtures/config/theming/help/usage/.gulp.js @@ -0,0 +1,7 @@ +module.exports = { + msgs: { + help: { + usage: 'GULP USAGE', + }, + }, +}; diff --git a/test/fixtures/config/theming/info/cwdChanged/.gulp.js b/test/fixtures/config/theming/info/cwdChanged/.gulp.js new file mode 100644 index 00000000..3c3c9380 --- /dev/null +++ b/test/fixtures/config/theming/info/cwdChanged/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + info: { + cwdChanged: '{TIMESTAMP}CHANGE CWD TO {CwdPath: {1}}', + }, + }, + theme: { + CwdPath: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/info/cwdChanged/gulpfile.js b/test/fixtures/config/theming/info/cwdChanged/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/info/cwdChanged/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/info/loaderSuccess/.gulp.js b/test/fixtures/config/theming/info/loaderSuccess/.gulp.js new file mode 100644 index 00000000..ec7df4a5 --- /dev/null +++ b/test/fixtures/config/theming/info/loaderSuccess/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + info: { + loaderSuccess: 'LOADED {ModuleName: {1}}', + }, + }, + theme: { + ModuleName: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/info/loaderSuccess/gulpfile.babel.js b/test/fixtures/config/theming/info/loaderSuccess/gulpfile.babel.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/info/loaderSuccess/gulpfile.babel.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/info/preloadBefore/.gulp.js b/test/fixtures/config/theming/info/preloadBefore/.gulp.js new file mode 100644 index 00000000..a6744dda --- /dev/null +++ b/test/fixtures/config/theming/info/preloadBefore/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + info: { + preloadBefore: 'PRELOADING {ModuleName: {1}}', + }, + }, + theme: { + ModuleName: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/info/preloadBefore/gulpfile.js b/test/fixtures/config/theming/info/preloadBefore/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/info/preloadBefore/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/info/preloadBefore/preload.js b/test/fixtures/config/theming/info/preloadBefore/preload.js new file mode 100644 index 00000000..3b5d0c74 --- /dev/null +++ b/test/fixtures/config/theming/info/preloadBefore/preload.js @@ -0,0 +1 @@ +global.preload = 'hello preload!'; diff --git a/test/fixtures/config/theming/info/preloadSuccess/.gulp.js b/test/fixtures/config/theming/info/preloadSuccess/.gulp.js new file mode 100644 index 00000000..bd6497e2 --- /dev/null +++ b/test/fixtures/config/theming/info/preloadSuccess/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + info: { + preloadSuccess: 'PRELOADDED {ModuleName: {1}}', + }, + }, + theme: { + ModuleName: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/info/preloadSuccess/gulpfile.js b/test/fixtures/config/theming/info/preloadSuccess/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/info/preloadSuccess/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/info/preloadSuccess/preload.js b/test/fixtures/config/theming/info/preloadSuccess/preload.js new file mode 100644 index 00000000..3b5d0c74 --- /dev/null +++ b/test/fixtures/config/theming/info/preloadSuccess/preload.js @@ -0,0 +1 @@ +global.preload = 'hello preload!'; diff --git a/test/fixtures/config/theming/info/respawn/.gulp.js b/test/fixtures/config/theming/info/respawn/.gulp.js new file mode 100644 index 00000000..8f6de9e3 --- /dev/null +++ b/test/fixtures/config/theming/info/respawn/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + info: { + respawn: 'RESPAWN BY {NodeFlag: {1}}', + }, + }, + theme: { + NodeFlag: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/info/respawn/gulpfile.js b/test/fixtures/config/theming/info/respawn/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/info/respawn/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/info/taskStart/.gulp.js b/test/fixtures/config/theming/info/taskStart/.gulp.js new file mode 100644 index 00000000..c1cef5d1 --- /dev/null +++ b/test/fixtures/config/theming/info/taskStart/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + info: { + taskStart: '{TIMESTAMP}START {Task: {1}}', + }, + }, + theme: { + Task: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/info/taskStart/gulpfile.js b/test/fixtures/config/theming/info/taskStart/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/info/taskStart/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/info/taskStop/.gulp.js b/test/fixtures/config/theming/info/taskStop/.gulp.js new file mode 100644 index 00000000..7c62298c --- /dev/null +++ b/test/fixtures/config/theming/info/taskStop/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + info: { + taskStop: '{TIMESTAMP}STOP {Task: {1}}', + }, + }, + theme: { + Task: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/info/taskStop/gulpfile.js b/test/fixtures/config/theming/info/taskStop/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/info/taskStop/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/info/usingGulpfile/.gulp.js b/test/fixtures/config/theming/info/usingGulpfile/.gulp.js new file mode 100644 index 00000000..cea0669a --- /dev/null +++ b/test/fixtures/config/theming/info/usingGulpfile/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + info: { + usingGulpfile: '{TIMESTAMP}USING GULPFILE {File:{1}}', + }, + }, + theme: { + File: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/info/usingGulpfile/gulpfile.js b/test/fixtures/config/theming/info/usingGulpfile/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/info/usingGulpfile/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/info/version/.gulp.js b/test/fixtures/config/theming/info/version/.gulp.js new file mode 100644 index 00000000..4183557c --- /dev/null +++ b/test/fixtures/config/theming/info/version/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + info: { + version: 'gulp-cli {VERSION: v{1}} | gulp {VERSION: v{2}}', + }, + }, + theme: { + VERSION: '@@{1}@@', + }, +}; diff --git a/test/fixtures/config/theming/tasks/childTask/.gulp.js b/test/fixtures/config/theming/tasks/childTask/.gulp.js new file mode 100644 index 00000000..545b70f9 --- /dev/null +++ b/test/fixtures/config/theming/tasks/childTask/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + tasks: { + childTask: '{1}{child_task: {2}}', + } + }, + theme: { + child_task: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/tasks/childTask/gulpfile.js b/test/fixtures/config/theming/tasks/childTask/gulpfile.js new file mode 100644 index 00000000..b61b53c3 --- /dev/null +++ b/test/fixtures/config/theming/tasks/childTask/gulpfile.js @@ -0,0 +1,27 @@ +const { series } = require('gulp'); + +function taskA(done) { + done(); +} +taskA.description = 'This is task A'; +taskA.flags = { + '--abc': 'is a flag for task A', +}; + +const taskB = function(done) { + done(); +} +taskB.description = 'This is task B'; +taskB.flags = { + '--def': 'is a flag for task B', +}; + +const defaults = series(taskA, taskB); +defaults.description = 'This is default task'; +defaults.flags = { + '--ghi': 'is a flag for default task', +}; + +exports.default = defaults; +exports.taskA = taskA; +exports.taskB = taskB; diff --git a/test/fixtures/config/theming/tasks/gulpfile/.gulp.json b/test/fixtures/config/theming/tasks/gulpfile/.gulp.json new file mode 100644 index 00000000..9255c31f --- /dev/null +++ b/test/fixtures/config/theming/tasks/gulpfile/.gulp.json @@ -0,0 +1,10 @@ +{ + "msgs": { + "tasks": { + "gulpfile": "{FILE: {1}}" + } + }, + "theme": { + "FILE": "** {1} **" + } +} diff --git a/test/fixtures/config/theming/tasks/gulpfile/gulpfile.js b/test/fixtures/config/theming/tasks/gulpfile/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/tasks/gulpfile/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/tasks/gulpfile/remove/.gulp.json b/test/fixtures/config/theming/tasks/gulpfile/remove/.gulp.json new file mode 100644 index 00000000..2b9fdf1b --- /dev/null +++ b/test/fixtures/config/theming/tasks/gulpfile/remove/.gulp.json @@ -0,0 +1,10 @@ +{ + "msgs": { + "tasks": { + "gulpfile": null + } + }, + "theme": { + "FILE": "** {1} **" + } +} diff --git a/test/fixtures/config/theming/tasks/gulpfile/remove/gulpfile.js b/test/fixtures/config/theming/tasks/gulpfile/remove/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/tasks/gulpfile/remove/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/tasks/option/.gulp.js b/test/fixtures/config/theming/tasks/option/.gulp.js new file mode 100644 index 00000000..790af554 --- /dev/null +++ b/test/fixtures/config/theming/tasks/option/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + tasks: { + option: '{1}{OptionName: {2}}{IF:{3}?{4}» {5}}', + } + }, + theme: { + OptionName: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/tasks/option/gulpfile.js b/test/fixtures/config/theming/tasks/option/gulpfile.js new file mode 100644 index 00000000..b61b53c3 --- /dev/null +++ b/test/fixtures/config/theming/tasks/option/gulpfile.js @@ -0,0 +1,27 @@ +const { series } = require('gulp'); + +function taskA(done) { + done(); +} +taskA.description = 'This is task A'; +taskA.flags = { + '--abc': 'is a flag for task A', +}; + +const taskB = function(done) { + done(); +} +taskB.description = 'This is task B'; +taskB.flags = { + '--def': 'is a flag for task B', +}; + +const defaults = series(taskA, taskB); +defaults.description = 'This is default task'; +defaults.flags = { + '--ghi': 'is a flag for default task', +}; + +exports.default = defaults; +exports.taskA = taskA; +exports.taskB = taskB; diff --git a/test/fixtures/config/theming/tasks/topTask/.gulp.js b/test/fixtures/config/theming/tasks/topTask/.gulp.js new file mode 100644 index 00000000..b9c00721 --- /dev/null +++ b/test/fixtures/config/theming/tasks/topTask/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + tasks: { + topTask: '{1}{TaskName: {2}}{IF:{3}?{4}{5}}', + } + }, + theme: { + TaskName: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/tasks/topTask/gulpfile.js b/test/fixtures/config/theming/tasks/topTask/gulpfile.js new file mode 100644 index 00000000..b61b53c3 --- /dev/null +++ b/test/fixtures/config/theming/tasks/topTask/gulpfile.js @@ -0,0 +1,27 @@ +const { series } = require('gulp'); + +function taskA(done) { + done(); +} +taskA.description = 'This is task A'; +taskA.flags = { + '--abc': 'is a flag for task A', +}; + +const taskB = function(done) { + done(); +} +taskB.description = 'This is task B'; +taskB.flags = { + '--def': 'is a flag for task B', +}; + +const defaults = series(taskA, taskB); +defaults.description = 'This is default task'; +defaults.flags = { + '--ghi': 'is a flag for default task', +}; + +exports.default = defaults; +exports.taskA = taskA; +exports.taskB = taskB; diff --git a/test/fixtures/config/theming/tasksJson/gulpfile/.gulp.json b/test/fixtures/config/theming/tasksJson/gulpfile/.gulp.json new file mode 100644 index 00000000..9255c31f --- /dev/null +++ b/test/fixtures/config/theming/tasksJson/gulpfile/.gulp.json @@ -0,0 +1,10 @@ +{ + "msgs": { + "tasks": { + "gulpfile": "{FILE: {1}}" + } + }, + "theme": { + "FILE": "** {1} **" + } +} diff --git a/test/fixtures/config/theming/tasksJson/gulpfile/gulpfile.js b/test/fixtures/config/theming/tasksJson/gulpfile/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/tasksJson/gulpfile/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/warn/loaderFailure/.gulp.js b/test/fixtures/config/theming/warn/loaderFailure/.gulp.js new file mode 100644 index 00000000..9875f824 --- /dev/null +++ b/test/fixtures/config/theming/warn/loaderFailure/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + warn: { + loaderFailure: '{TIMESTAMP}FAIL TO LOAD {ModuleName: {1}}', + }, + }, + theme: { + ModuleName: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/warn/loaderFailure/gulpfile.coffee b/test/fixtures/config/theming/warn/loaderFailure/gulpfile.coffee new file mode 100644 index 00000000..1f8b8541 --- /dev/null +++ b/test/fixtures/config/theming/warn/loaderFailure/gulpfile.coffee @@ -0,0 +1 @@ +console.log 'hello' diff --git a/test/fixtures/config/theming/warn/preloadFailure/.gulp.js b/test/fixtures/config/theming/warn/preloadFailure/.gulp.js new file mode 100644 index 00000000..50e3bcc6 --- /dev/null +++ b/test/fixtures/config/theming/warn/preloadFailure/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + warn: { + preloadFailure: '{TIMESTAMP}FAILED TO PRELOAD {ModuleName: {1}}', + }, + }, + theme: { + ModuleName: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/warn/preloadFailure/gulpfile.js b/test/fixtures/config/theming/warn/preloadFailure/gulpfile.js new file mode 100644 index 00000000..db73dd16 --- /dev/null +++ b/test/fixtures/config/theming/warn/preloadFailure/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + done(); +} diff --git a/test/fixtures/config/theming/warn/taskNotComplete/.gulp.js b/test/fixtures/config/theming/warn/taskNotComplete/.gulp.js new file mode 100644 index 00000000..df6bd57f --- /dev/null +++ b/test/fixtures/config/theming/warn/taskNotComplete/.gulp.js @@ -0,0 +1,10 @@ +module.exports = { + msgs: { + warn: { + taskNotComplete: '{TIMESTAMP}TASK {TaskName: {1}} DID NOT COMPLETE', + }, + }, + theme: { + TaskName: '**{1}**', + }, +}; diff --git a/test/fixtures/config/theming/warn/taskNotComplete/gulpfile.js b/test/fixtures/config/theming/warn/taskNotComplete/gulpfile.js new file mode 100644 index 00000000..1e950f9a --- /dev/null +++ b/test/fixtures/config/theming/warn/taskNotComplete/gulpfile.js @@ -0,0 +1,3 @@ +exports.default = function(done) { + //done(); +} diff --git a/test/fixtures/errors/yarn/yarn.lock b/test/fixtures/errors/yarn/yarn.lock new file mode 100644 index 00000000..e69de29b diff --git a/test/flags-tasks.js b/test/flags-tasks.js index 4a1c689f..f43279c0 100644 --- a/test/flags-tasks.js +++ b/test/flags-tasks.js @@ -31,7 +31,7 @@ describe('flag: --tasks', function() { } }); - it('print the task list with description and flags', function(done) { + it('prints the task list with description and flags', function(done) { var opts = { cwd: baseDir }; exec(gulp( '--tasks', @@ -50,7 +50,7 @@ describe('flag: --tasks', function() { } }); - it('print the task list by gulp.task(s).unwrap and gulp.task(s)', function(done) { + it('prints the task list by gulp.task(s).unwrap and gulp.task(s)', function(done) { var opts = { cwd: baseDir }; exec(gulp( '--tasks', diff --git a/test/lib/check-task-not-found.js b/test/lib/check-task-not-found.js new file mode 100644 index 00000000..932c753c --- /dev/null +++ b/test/lib/check-task-not-found.js @@ -0,0 +1,28 @@ +'use strict'; + +var expect = require('expect'); +var checkTaskNotFound = require('../../lib/versioned/^4.0.0/log/check-task-not-found'); + +describe('lib: checkTaskNotFound', function() { + + it('Should return target task and similar tasks if both are included in error message', function(done) { + var err = new Error('Task never defined: task2 - did you mean? task0, task1'); + expect(checkTaskNotFound(err)).toEqual({ + target: 'task2', + similar: 'task0, task1', + }); + done(); + }); + + it('Should return only target task if similar tasks is not included in error message', function(done) { + var err = new Error('Task never defined: task2'); + expect(checkTaskNotFound(err)).toEqual({ target: 'task2' }); + done(); + }); + + it('Should return undefined if error is other', function(done) { + var err = new Error('xxx'); + expect(checkTaskNotFound(err)).toBeUndefined(); + done(); + }); +});