From c3ca14a280aa14576d4fe5bd310e59bdd91dacd5 Mon Sep 17 00:00:00 2001 From: tim Date: Tue, 22 Aug 2017 20:06:48 +0200 Subject: [PATCH 1/8] remove chalk for ansi-* --- index.js | 26 +++++++------- lib/shared/ansi.js | 22 ++++++++++++ lib/shared/cliOptions.js | 36 +++++++++---------- lib/shared/log/blacklistError.js | 4 +-- lib/shared/log/tasks.js | 14 ++++---- lib/shared/log/verify.js | 8 ++--- lib/versioned/^3.7.0/index.js | 6 ++-- lib/versioned/^3.7.0/log/events.js | 16 ++++----- lib/versioned/^4.0.0-alpha.1/index.js | 8 ++--- lib/versioned/^4.0.0-alpha.2/index.js | 8 ++--- lib/versioned/^4.0.0/index.js | 8 ++--- lib/versioned/^4.0.0/log/events.js | 14 ++++---- lib/versioned/^4.0.0/log/syncTask.js | 8 ++--- package.json | 9 ++++- test/config-description.js | 7 ++-- test/config-flags-compactTasks.js | 5 +-- test/config-flags-continue.js | 9 ++--- test/config-flags-log-level.js | 19 +++++----- test/config-flags-silent.js | 3 +- test/config-flags-sortTasks.js | 5 +-- test/config-flags-tasksDepth.js | 3 +- test/exports-as-tasks.js | 3 +- test/fixtures/packages/valid-package.json | 42 +++++++++++------------ test/flags-continue.js | 11 +++--- test/flags-gulpfile.js | 4 +-- test/flags-help.js | 12 ++----- test/flags-require.js | 9 ++--- test/flags-tasks.js | 17 ++++----- test/flags-verify.js | 7 ++-- test/shared/stripAnsi.js | 11 ++++++ 30 files changed, 200 insertions(+), 154 deletions(-) create mode 100644 lib/shared/ansi.js create mode 100644 test/shared/stripAnsi.js diff --git a/index.js b/index.js index 87ef29e9..1e4cd879 100644 --- a/index.js +++ b/index.js @@ -3,13 +3,13 @@ var fs = require('fs'); var path = require('path'); var log = require('gulplog'); -var chalk = require('chalk'); var yargs = require('yargs'); var Liftoff = require('liftoff'); var tildify = require('tildify'); var interpret = require('interpret'); var v8flags = require('v8flags'); var findRange = require('semver-greatest-satisfied-range'); +var ansi = require('./lib/shared/ansi'); var exit = require('./lib/shared/exit'); var cliOptions = require('./lib/shared/cliOptions'); var completion = require('./lib/shared/completion'); @@ -53,8 +53,8 @@ var cli = new Liftoff({ }); var usage = - '\n' + chalk.bold('Usage:') + - ' gulp ' + chalk.blue('[options]') + ' tasks'; + '\n' + ansi.bold('Usage:') + + ' gulp ' + ansi.blue('[options]') + ' tasks'; var parser = yargs.usage(usage, cliOptions); var opts = parser.argv; @@ -63,16 +63,16 @@ var opts = parser.argv; toConsole(log, opts); cli.on('require', function(name) { - log.info('Requiring external module', chalk.magenta(name)); + log.info('Requiring external module', ansi.magenta(name)); }); cli.on('requireFail', function(name) { - log.error(chalk.red('Failed to load external module'), chalk.magenta(name)); + log.error(ansi.red('Failed to load external module'), ansi.magenta(name)); }); cli.on('respawn', function(flags, child) { - var nodeFlags = chalk.magenta(flags.join(', ')); - var pid = chalk.magenta(child.pid); + var nodeFlags = ansi.magenta(flags.join(', ')); + var pid = ansi.magenta(child.pid); log.info('Node flags detected:', nodeFlags); log.info('Respawned to PID:', pid); }); @@ -138,15 +138,15 @@ function handleArguments(env) { if (!env.modulePath) { log.error( - chalk.red('Local gulp not found in'), - chalk.magenta(tildify(env.cwd)) + ansi.red('Local gulp not found in'), + ansi.magenta(tildify(env.cwd)) ); - log.error(chalk.red('Try running: npm install gulp')); + log.error(ansi.red('Try running: npm install gulp')); exit(1); } if (!env.configPath) { - log.error(chalk.red('No gulpfile found')); + log.error(ansi.red('No gulpfile found')); exit(1); } @@ -156,7 +156,7 @@ function handleArguments(env) { process.chdir(env.cwd); log.info( 'Working directory changed to', - chalk.magenta(tildify(env.cwd)) + ansi.magenta(tildify(env.cwd)) ); } @@ -165,7 +165,7 @@ function handleArguments(env) { if (!range) { return log.error( - chalk.red('Unsupported gulp version', env.modulePackage.version) + ansi.red('Unsupported gulp version', env.modulePackage.version) ); } diff --git a/lib/shared/ansi.js b/lib/shared/ansi.js new file mode 100644 index 00000000..6fe1c702 --- /dev/null +++ b/lib/shared/ansi.js @@ -0,0 +1,22 @@ +var red = require('ansi-red'); +var green = require('ansi-green'); +var blue = require('ansi-blue'); +var magenta = require('ansi-magenta'); +var cyan = require('ansi-cyan'); +var white = require('ansi-white'); +var gray = require('ansi-gray'); +var bgred = require('ansi-bgred'); +var bold = require('ansi-bold'); + +module.exports = { + red: red, + green: green, + blue: blue, + magenta: magenta, + cyan: cyan, + white: white, + gray: gray, + bgred: bgred, + bold: bold, +}; + diff --git a/lib/shared/cliOptions.js b/lib/shared/cliOptions.js index 90eba586..5b145c62 100644 --- a/lib/shared/cliOptions.js +++ b/lib/shared/cliOptions.js @@ -1,59 +1,59 @@ 'use strict'; -var chalk = require('chalk'); +var ansi = require('./ansi'); module.exports = { help: { alias: 'h', type: 'boolean', - desc: chalk.gray( + desc: ansi.gray( 'Show this help.'), }, version: { alias: 'v', type: 'boolean', - desc: chalk.gray( + desc: ansi.gray( 'Print the global and local gulp versions.'), }, require: { type: 'string', requiresArg: true, - desc: chalk.gray( + desc: ansi.gray( 'Will require a module before running the gulpfile. ' + 'This is useful for transpilers but also has other applications.'), }, gulpfile: { type: 'string', requiresArg: true, - desc: chalk.gray( + desc: ansi.gray( 'Manually set path of gulpfile. Useful if you have multiple gulpfiles. ' + 'This will set the CWD to the gulpfile directory as well.'), }, cwd: { type: 'string', requiresArg: true, - desc: chalk.gray( + desc: ansi.gray( 'Manually set the CWD. The search for the gulpfile, ' + 'as well as the relativity of all requires will be from here.'), }, verify: { - desc: chalk.gray( + desc: ansi.gray( 'Will verify plugins referenced in project\'s package.json against ' + 'the plugins blacklist.'), }, tasks: { alias: 'T', type: 'boolean', - desc: chalk.gray( + desc: ansi.gray( 'Print the task dependency tree for the loaded gulpfile.'), }, 'tasks-simple': { type: 'boolean', - desc: chalk.gray( + desc: ansi.gray( 'Print a plaintext list of tasks for the loaded gulpfile.'), }, 'tasks-json': { - desc: chalk.gray( + desc: ansi.gray( 'Print the task dependency tree, ' + 'in JSON format, for the loaded gulpfile.'), }, @@ -61,41 +61,41 @@ module.exports = { alias: 'depth', type: 'number', requiresArg: true, - desc: chalk.gray( + desc: ansi.gray( 'Specify the depth of the task dependency tree.'), }, 'compact-tasks': { type: 'boolean', - desc: chalk.gray( + desc: ansi.gray( 'Reduce the output of task dependency tree by printing ' + 'only top tasks and their child tasks.'), }, 'sort-tasks': { type: 'boolean', - desc: chalk.gray( + desc: ansi.gray( 'Will sort top tasks of task dependency tree.'), }, color: { type: 'boolean', - desc: chalk.gray( + desc: ansi.gray( 'Will force gulp and gulp plugins to display colors, ' + 'even when no color support is detected.'), }, 'no-color': { type: 'boolean', - desc: chalk.gray( + desc: ansi.gray( 'Will force gulp and gulp plugins to not display colors, ' + 'even when color support is detected.'), }, silent: { alias: 'S', type: 'boolean', - desc: chalk.gray( + desc: ansi.gray( 'Suppress all gulp logging.'), }, continue: { type: 'boolean', - desc: chalk.gray( + desc: ansi.gray( 'Continue execution of tasks upon failure.'), }, 'log-level': { @@ -103,7 +103,7 @@ module.exports = { // Type isn't needed because count acts as a boolean count: true, // Can't use `default` because it seems to be off by one - desc: chalk.gray( + desc: ansi.gray( 'Set the loglevel. -L for least verbose and -LLLL for most verbose. ' + '-LLL is default.'), }, diff --git a/lib/shared/log/blacklistError.js b/lib/shared/log/blacklistError.js index c3c5bf32..396436ac 100644 --- a/lib/shared/log/blacklistError.js +++ b/lib/shared/log/blacklistError.js @@ -1,12 +1,12 @@ 'use strict'; -var chalk = require('chalk'); var log = require('gulplog'); +var ansi = require('../ansi'); var exit = require('../exit'); function logBlacklistError(err) { - log.error(chalk.red('Error: failed to retrieve plugins black-list')); + log.error(ansi.red('Error: failed to retrieve plugins black-list')); log.error(err.message); // Avoid duplicating for each version exit(1); } diff --git a/lib/shared/log/tasks.js b/lib/shared/log/tasks.js index 3e4a7c91..37084d1d 100644 --- a/lib/shared/log/tasks.js +++ b/lib/shared/log/tasks.js @@ -1,11 +1,11 @@ 'use strict'; var archy = require('archy'); -var chalk = require('chalk'); var log = require('gulplog'); var sortBy = require('lodash.sortby'); var isObject = require('lodash.isplainobject'); +var ansi = require('../ansi'); var isString = require('../is-string'); var copyTree = require('./copy-tree'); @@ -145,20 +145,20 @@ function printTreeList(lines, spacer, lineInfos) { lines.forEach(function(branch, index) { var info = lineInfos[index]; - var line = chalk.white(branch); + var line = ansi.white(branch); if (info.type === 'top') { - line += chalk.cyan(info.name); + line += ansi.cyan(info.name); if (info.desc.length > 0) { - line += spacer(index) + chalk.white(info.desc); + line += spacer(index) + ansi.white(info.desc); } } else if (info.type === 'option') { - line += chalk.magenta(info.name); + line += ansi.magenta(info.name); if (info.desc.length > 0) { - line += spacer(index) + chalk.white('…' + info.desc); + line += spacer(index) + ansi.white('…' + info.desc); } } else { // If (info.type === 'child') { - line += chalk.white(info.name); + line += ansi.white(info.name); } log.info(line); diff --git a/lib/shared/log/verify.js b/lib/shared/log/verify.js index 795867a7..71046237 100644 --- a/lib/shared/log/verify.js +++ b/lib/shared/log/verify.js @@ -1,8 +1,8 @@ 'use strict'; -var chalk = require('chalk'); var log = require('gulplog'); +var ansi = require('../ansi'); var exit = require('../exit'); function logVerify(blacklisted) { @@ -10,16 +10,16 @@ function logVerify(blacklisted) { if (!pluginNames.length) { log.info( - chalk.green('There are no blacklisted plugins in this project') + ansi.green('There are no blacklisted plugins in this project') ); exit(0); } - log.warn(chalk.red('Blacklisted plugins found in this project:')); + log.warn(ansi.red('Blacklisted plugins found in this project:')); pluginNames.map(function(pluginName) { var reason = blacklisted[pluginName]; - log.warn(chalk.bgRed(pluginName) + ': ' + reason); + log.warn(ansi.bgred(pluginName) + ': ' + reason); }); exit(1); diff --git a/lib/versioned/^3.7.0/index.js b/lib/versioned/^3.7.0/index.js index 6e3eda7e..f91b175d 100644 --- a/lib/versioned/^3.7.0/index.js +++ b/lib/versioned/^3.7.0/index.js @@ -1,6 +1,5 @@ 'use strict'; -var chalk = require('chalk'); var log = require('gulplog'); var stdout = require('mute-stdout'); var tildify = require('tildify'); @@ -8,6 +7,7 @@ var tildify = require('tildify'); var taskTree = require('./taskTree'); var logTasks = require('../../shared/log/tasks'); +var ansi = require('../../shared/ansi'); var isString = require('../../shared/is-string'); var logEvents = require('./log/events'); var logTasksSimple = require('./log/tasksSimple'); @@ -24,7 +24,7 @@ function execute(opts, env, config) { // This is what actually loads up the gulpfile var exported = require(env.configPath); - log.info('Using gulpfile', chalk.magenta(tildify(env.configPath))); + log.info('Using gulpfile', ansi.magenta(tildify(env.configPath))); var gulpInst = require(env.modulePath); logEvents(gulpInst); @@ -45,7 +45,7 @@ function execute(opts, env, config) { if (config.description && isString(config.description)) { tree.label = config.description; } else { - tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath)); + tree.label = 'Tasks for ' + ansi.magenta(tildify(env.configPath)); } return logTasks(tree, opts, function(task) { return gulpInst.tasks[task].fn; diff --git a/lib/versioned/^3.7.0/log/events.js b/lib/versioned/^3.7.0/log/events.js index 3b15be3b..f88136d0 100644 --- a/lib/versioned/^3.7.0/log/events.js +++ b/lib/versioned/^3.7.0/log/events.js @@ -1,9 +1,9 @@ 'use strict'; -var chalk = require('chalk'); var log = require('gulplog'); var prettyTime = require('pretty-hrtime'); +var ansi = require('../../../shared/ansi'); var exit = require('../../../shared/exit'); var formatError = require('../formatError'); @@ -26,14 +26,14 @@ function logEvents(gulpInst) { gulpInst.on('task_start', function(e) { // TODO: batch these // so when 5 tasks start at once it only logs one time with all 5 - log.info('Starting', '\'' + chalk.cyan(e.task) + '\'...'); + log.info('Starting', '\'' + ansi.cyan(e.task) + '\'...'); }); gulpInst.on('task_stop', function(e) { var time = prettyTime(e.hrDuration); log.info( - 'Finished', '\'' + chalk.cyan(e.task) + '\'', - 'after', chalk.magenta(time) + 'Finished', '\'' + ansi.cyan(e.task) + '\'', + 'after', ansi.magenta(time) ); }); @@ -41,16 +41,16 @@ function logEvents(gulpInst) { var msg = formatError(e); var time = prettyTime(e.hrDuration); log.error( - '\'' + chalk.cyan(e.task) + '\'', - chalk.red('errored after'), - chalk.magenta(time) + '\'' + ansi.cyan(e.task) + '\'', + ansi.red('errored after'), + ansi.magenta(time) ); log.error(msg); }); gulpInst.on('task_not_found', function(err) { log.error( - chalk.red('Task \'' + err.task + '\' is not in your gulpfile') + ansi.red('Task \'' + err.task + '\' is not in your gulpfile') ); log.error('Please check the documentation for proper gulpfile formatting'); exit(1); diff --git a/lib/versioned/^4.0.0-alpha.1/index.js b/lib/versioned/^4.0.0-alpha.1/index.js index 3b3aa0f1..a791b87d 100644 --- a/lib/versioned/^4.0.0-alpha.1/index.js +++ b/lib/versioned/^4.0.0-alpha.1/index.js @@ -3,10 +3,10 @@ var fs = require('fs'); var log = require('gulplog'); -var chalk = require('chalk'); var stdout = require('mute-stdout'); var tildify = require('tildify'); +var ansi = require('../../shared/ansi'); var exit = require('../../shared/exit'); var isString = require('../../shared/is-string'); @@ -51,7 +51,7 @@ function execute(opts, env, config) { if (config.description && isString(config.description)) { tree.label = config.description; } else { - tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath)); + tree.label = 'Tasks for ' + ansi.magenta(tildify(env.configPath)); } tree.nodes = gulpInst.tree({ deep: true }); return logTasks(tree, opts, function(taskname) { @@ -74,14 +74,14 @@ function execute(opts, env, config) { return fs.writeFileSync(opts.tasksJson, output, 'utf-8'); } try { - log.info('Using gulpfile', chalk.magenta(tildify(env.configPath))); + log.info('Using gulpfile', ansi.magenta(tildify(env.configPath))); gulpInst.parallel(toRun)(function(err) { if (err) { exit(1); } }); } catch (err) { - log.error(chalk.red(err.message)); + log.error(ansi.red(err.message)); log.error('To list available tasks, try running: gulp --tasks'); exit(1); } diff --git a/lib/versioned/^4.0.0-alpha.2/index.js b/lib/versioned/^4.0.0-alpha.2/index.js index aba74979..dc616461 100644 --- a/lib/versioned/^4.0.0-alpha.2/index.js +++ b/lib/versioned/^4.0.0-alpha.2/index.js @@ -3,10 +3,10 @@ var fs = require('fs'); var log = require('gulplog'); -var chalk = require('chalk'); var stdout = require('mute-stdout'); var tildify = require('tildify'); +var ansi = require('../../shared/ansi'); var exit = require('../../shared/exit'); var isString = require('../../shared/is-string'); @@ -53,7 +53,7 @@ function execute(opts, env, config) { if (config.description && isString(config.description)) { tree.label = config.description; } else { - tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath)); + tree.label = 'Tasks for ' + ansi.magenta(tildify(env.configPath)); } return logTasks(tree, opts, getTask(gulpInst)); @@ -74,14 +74,14 @@ function execute(opts, env, config) { return fs.writeFileSync(opts.tasksJson, output, 'utf-8'); } try { - log.info('Using gulpfile', chalk.magenta(tildify(env.configPath))); + log.info('Using gulpfile', ansi.magenta(tildify(env.configPath))); gulpInst.parallel(toRun)(function(err) { if (err) { exit(1); } }); } catch (err) { - log.error(chalk.red(err.message)); + log.error(ansi.red(err.message)); log.error('To list available tasks, try running: gulp --tasks'); exit(1); } diff --git a/lib/versioned/^4.0.0/index.js b/lib/versioned/^4.0.0/index.js index 73c19c8b..85cb1ace 100644 --- a/lib/versioned/^4.0.0/index.js +++ b/lib/versioned/^4.0.0/index.js @@ -3,10 +3,10 @@ var fs = require('fs'); var log = require('gulplog'); -var chalk = require('chalk'); var stdout = require('mute-stdout'); var tildify = require('tildify'); +var ansi = require('../../shared/ansi'); var exit = require('../../shared/exit'); var isString = require('../../shared/is-string'); @@ -53,7 +53,7 @@ function execute(opts, env, config) { if (config.description && isString(config.description)) { tree.label = config.description; } else { - tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath)); + tree.label = 'Tasks for ' + ansi.magenta(tildify(env.configPath)); } return logTasks(tree, opts, getTask(gulpInst)); @@ -74,14 +74,14 @@ function execute(opts, env, config) { return fs.writeFileSync(opts.tasksJson, output, 'utf-8'); } try { - log.info('Using gulpfile', chalk.magenta(tildify(env.configPath))); + log.info('Using gulpfile', ansi.magenta(tildify(env.configPath))); gulpInst.parallel(toRun)(function(err) { if (err) { exit(1); } }); } catch (err) { - log.error(chalk.red(err.message)); + log.error(ansi.red(err.message)); log.error('To list available tasks, try running: gulp --tasks'); exit(1); } diff --git a/lib/versioned/^4.0.0/log/events.js b/lib/versioned/^4.0.0/log/events.js index 8c2f2d22..64938dcc 100644 --- a/lib/versioned/^4.0.0/log/events.js +++ b/lib/versioned/^4.0.0/log/events.js @@ -1,9 +1,9 @@ 'use strict'; var log = require('gulplog'); -var chalk = require('chalk'); var prettyTime = require('pretty-hrtime'); var formatError = require('../formatError'); +var ansi = require('../../../shared/ansi'); // Wire up logging events function logEvents(gulpInst) { @@ -14,15 +14,15 @@ function logEvents(gulpInst) { // TODO: batch these // so when 5 tasks start at once it only logs one time with all 5 var level = evt.branch ? 'debug' : 'info'; - log[level]('Starting', '\'' + chalk.cyan(evt.name) + '\'...'); + log[level]('Starting', '\'' + ansi.cyan(evt.name) + '\'...'); }); gulpInst.on('stop', function(evt) { var time = prettyTime(evt.duration); var level = evt.branch ? 'debug' : 'info'; log[level]( - 'Finished', '\'' + chalk.cyan(evt.name) + '\'', - 'after', chalk.magenta(time) + 'Finished', '\'' + ansi.cyan(evt.name) + '\'', + 'after', ansi.magenta(time) ); }); @@ -31,9 +31,9 @@ function logEvents(gulpInst) { var time = prettyTime(evt.duration); var level = evt.branch ? 'debug' : 'error'; log[level]( - '\'' + chalk.cyan(evt.name) + '\'', - chalk.red('errored after'), - chalk.magenta(time) + '\'' + ansi.cyan(evt.name) + '\'', + ansi.red('errored after'), + ansi.magenta(time) ); // If we haven't logged this before, log it and add to list diff --git a/lib/versioned/^4.0.0/log/syncTask.js b/lib/versioned/^4.0.0/log/syncTask.js index 493654fc..1932e89c 100644 --- a/lib/versioned/^4.0.0/log/syncTask.js +++ b/lib/versioned/^4.0.0/log/syncTask.js @@ -1,7 +1,7 @@ 'use strict'; var log = require('gulplog'); -var chalk = require('chalk'); +var ansi = require('../../../shared/ansi'); var tasks = {}; @@ -17,11 +17,11 @@ function warn() { }).join(', '); log.warn( - chalk.red('The following tasks did not complete:'), - chalk.cyan(taskNames) + ansi.red('The following tasks did not complete:'), + ansi.cyan(taskNames) ); log.warn( - chalk.red('Did you forget to signal async completion?') + ansi.red('Did you forget to signal async completion?') ); } diff --git a/package.json b/package.json index 5f566639..1dad6508 100644 --- a/package.json +++ b/package.json @@ -32,8 +32,15 @@ "changelog": "github-changes -o gulpjs -r gulp-cli -b master -f ./CHANGELOG.md --order-semver --use-commit-body" }, "dependencies": { + "ansi-bgred": "^0.1.1", + "ansi-blue": "^0.1.1", + "ansi-bold": "^0.1.1", + "ansi-cyan": "^0.1.1", + "ansi-gray": "^0.1.1", + "ansi-magenta": "^0.1.1", + "ansi-red": "^0.1.1", + "ansi-white": "^0.1.1", "archy": "^1.0.0", - "chalk": "^1.1.0", "copy-props": "^1.4.1", "fancy-log": "^1.1.0", "gulplog": "^1.0.0", diff --git a/test/config-description.js b/test/config-description.js index 41709909..f9daf1a9 100644 --- a/test/config-description.js +++ b/test/config-description.js @@ -7,6 +7,7 @@ var fs = require('fs'); var skipLines = require('gulp-test-tools').skipLines; var eraseTime = require('gulp-test-tools').eraseTime; var runner = require('gulp-test-tools').gulpRunner; +var stripAnsi = require('./shared/stripAnsi'); var fixturesDir = path.join(__dirname, 'fixtures', 'config'); var expectedDir = path.join(__dirname, 'expected', 'config'); @@ -25,7 +26,7 @@ describe('config: description', function() { expect(stderr).toEqual(''); var expected = fs.readFileSync(path.join(expectedDir, 'output0.txt'), 'utf-8'); - stdout = eraseTime(stdout); + stdout = eraseTime(stripAnsi(stdout)); expect(stdout).toEqual(expected); done(err); } @@ -43,7 +44,7 @@ describe('config: description', function() { expect(stderr).toEqual(''); var expected = fs.readFileSync(path.join(expectedDir, 'output0.txt'), 'utf-8'); - stdout = eraseTime(skipLines(stdout, 1)); + stdout = eraseTime(stripAnsi(skipLines(stdout, 1))); expect(stdout).toEqual(expected); done(err); } @@ -61,7 +62,7 @@ describe('config: description', function() { expect(stderr).toEqual(''); var expected = fs.readFileSync(path.join(expectedDir, 'output1.txt'), 'utf-8'); - stdout = eraseTime(stdout); + stdout = eraseTime(stripAnsi(stdout)); expect(stdout).toEqual(expected); done(err); } diff --git a/test/config-flags-compactTasks.js b/test/config-flags-compactTasks.js index 7019646a..4e5242b4 100644 --- a/test/config-flags-compactTasks.js +++ b/test/config-flags-compactTasks.js @@ -5,6 +5,7 @@ var path = require('path'); var fs = require('fs'); var skipLines = require('gulp-test-tools').skipLines; var eraseTime = require('gulp-test-tools').eraseTime; +var stripAnsi = require('./shared/stripAnsi'); var fixturesDir = path.join(__dirname, 'fixtures/config'); var expectedDir = path.join(__dirname, 'expected'); @@ -24,7 +25,7 @@ describe ('config: flags.compactTasks', function() { var expected = fs.readFileSync(filepath, 'utf-8'); expected = skipLines(expected, 1); - stdout = eraseTime(skipLines(stdout, 1)); + stdout = eraseTime(stripAnsi(skipLines(stdout, 1))); expect(stdout).toEqual(expected); expect(stderr).toEqual(''); @@ -44,7 +45,7 @@ describe ('config: flags.compactTasks', function() { var expected = fs.readFileSync(filepath, 'utf-8'); expected = skipLines(expected, 1); - stdout = eraseTime(skipLines(stdout, 1)); + stdout = eraseTime(stripAnsi(skipLines(stdout, 1))); expect(stdout).toEqual(expected); expect(stderr).toEqual(''); diff --git a/test/config-flags-continue.js b/test/config-flags-continue.js index 753fe8d5..39efffbd 100644 --- a/test/config-flags-continue.js +++ b/test/config-flags-continue.js @@ -6,6 +6,7 @@ var skipLines = require('gulp-test-tools').skipLines; var headLines = require('gulp-test-tools').headLines; var eraseTime = require('gulp-test-tools').eraseTime; var eraseLapse = require('gulp-test-tools').eraseLapse; +var stripAnsi = require('./shared/stripAnsi'); var fixturesDir = path.join(__dirname, 'fixtures/config'); var runner = require('gulp-test-tools').gulpRunner({ verbose: false }).basedir(fixturesDir); @@ -22,7 +23,7 @@ describe('config: flags.continue', function() { function cb(err, stdout, stderr) { expect(err).toNotEqual(null); - stdout = eraseLapse(eraseTime(skipLines(stdout, 1))); + stdout = eraseLapse(eraseTime(stripAnsi(skipLines(stdout, 1)))); expect(stdout).toEqual( 'Starting \'default\'...\n' + 'Starting \'err\'...\n' + @@ -30,7 +31,7 @@ describe('config: flags.continue', function() { 'Finished \'next\' after ?\n' + '' ); - stderr = eraseLapse(eraseTime(headLines(stderr, 2))); + stderr = eraseLapse(eraseTime(stripAnsi(headLines(stderr, 2)))); expect(stderr).toEqual( '\'err\' errored after ?\n' + 'Error: Error!' @@ -49,13 +50,13 @@ describe('config: flags.continue', function() { function cb(err, stdout, stderr) { expect(err).toNotEqual(null); - stdout = eraseLapse(eraseTime(skipLines(stdout, 1))); + stdout = eraseLapse(eraseTime(stripAnsi(skipLines(stdout, 1)))); expect(stdout).toEqual( 'Starting \'default\'...\n' + 'Starting \'err\'...\n' + '' ); - stderr = eraseLapse(eraseTime(headLines(stderr, 2))); + stderr = eraseLapse(eraseTime(stripAnsi(headLines(stderr, 2)))); expect(stderr).toEqual( '\'err\' errored after ?\n' + 'Error: Error!' diff --git a/test/config-flags-log-level.js b/test/config-flags-log-level.js index 6a960b81..4b5d8155 100644 --- a/test/config-flags-log-level.js +++ b/test/config-flags-log-level.js @@ -4,6 +4,7 @@ var expect = require('expect'); var path = require('path'); var eraseTime = require('gulp-test-tools').eraseTime; var runner = require('gulp-test-tools').gulpRunner; +var stripAnsi = require('./shared/stripAnsi'); describe('config: flag.logLevel', function() { @@ -14,7 +15,7 @@ describe('config: flag.logLevel', function() { .run(function(err, stdout, stderr) { expect(err).toNotEqual(null); expect(stdout).toEqual(''); - expect(eraseTime(stderr)).toEqual('No gulpfile found\n'); + expect(eraseTime(stripAnsi(stderr))).toEqual('No gulpfile found\n'); done(); }); }); @@ -27,7 +28,7 @@ describe('config: flag.logLevel', function() { .gulp('--verify', packageJsonPath) .run(function(err, stdout, stderr) { expect(err).toNotEqual(null); - expect(eraseTime(stdout)).toEqual( + expect(eraseTime(stripAnsi(stdout))).toEqual( 'Verifying plugins in ' + packageJsonPath + '\n' + 'Blacklisted plugins found in this project:\n' + 'gulp-blink: deprecated. use \`blink` instead.\n'); @@ -44,7 +45,7 @@ describe('config: flag.logLevel', function() { .gulp('--verify', packageJsonPath) .run(function(err, stdout, stderr) { expect(err).toEqual(null); - expect(eraseTime(stdout)).toEqual( + expect(eraseTime(stripAnsi(stdout))).toEqual( 'Verifying plugins in ' + packageJsonPath + '\n' + 'There are no blacklisted plugins in this project\n'); expect(stderr).toEqual(''); @@ -63,7 +64,7 @@ describe('config: flag.logLevel', function() { .run(function(err, stdout, stderr) { expect(err).toNotEqual(null); expect(stdout).toEqual(''); - expect(eraseTime(stderr)).toEqual('No gulpfile found\n'); + expect(eraseTime(stripAnsi(stderr))).toEqual('No gulpfile found\n'); done(); }); }); @@ -105,7 +106,7 @@ describe('config: flag.logLevel', function() { .run(function(err, stdout, stderr) { expect(err).toNotEqual(null); expect(stdout).toEqual(''); - expect(eraseTime(stderr)).toEqual('No gulpfile found\n'); + expect(eraseTime(stripAnsi(stderr))).toEqual('No gulpfile found\n'); done(); }); }); @@ -117,7 +118,7 @@ describe('config: flag.logLevel', function() { gulp('--verify', packageJsonPath) .run(function(err, stdout, stderr) { expect(err).toNotEqual(null); - expect(eraseTime(stdout)).toEqual( + expect(eraseTime(stripAnsi(stdout))).toEqual( 'Blacklisted plugins found in this project:\n' + 'gulp-blink: deprecated. use \`blink` instead.\n'); expect(stderr).toEqual(''); @@ -149,7 +150,7 @@ describe('config: flag.logLevel', function() { .run(function(err, stdout, stderr) { expect(err).toNotEqual(null); expect(stdout).toEqual(''); - expect(eraseTime(stderr)).toEqual('No gulpfile found\n'); + expect(eraseTime(stripAnsi(stderr))).toEqual('No gulpfile found\n'); done(); }); }); @@ -161,7 +162,7 @@ describe('config: flag.logLevel', function() { gulp('--verify', packageJsonPath) .run(function(err, stdout, stderr) { expect(err).toNotEqual(null); - expect(eraseTime(stdout)).toEqual( + expect(eraseTime(stripAnsi(stdout))).toEqual( 'Verifying plugins in ' + packageJsonPath + '\n' + 'Blacklisted plugins found in this project:\n' + 'gulp-blink: deprecated. use \`blink` instead.\n'); @@ -177,7 +178,7 @@ describe('config: flag.logLevel', function() { gulp('--verify', packageJsonPath) .run(function(err, stdout, stderr) { expect(err).toEqual(null); - expect(eraseTime(stdout)).toEqual( + expect(eraseTime(stripAnsi(stdout))).toEqual( 'Verifying plugins in ' + packageJsonPath + '\n' + 'There are no blacklisted plugins in this project\n'); expect(stderr).toEqual(''); diff --git a/test/config-flags-silent.js b/test/config-flags-silent.js index ee0ff1d0..80bc879d 100644 --- a/test/config-flags-silent.js +++ b/test/config-flags-silent.js @@ -5,6 +5,7 @@ var path = require('path'); var skipLines = require('gulp-test-tools').skipLines; var eraseTime = require('gulp-test-tools').eraseTime; var eraseLapse = require('gulp-test-tools').eraseLapse; +var stripAnsi = require('./shared/stripAnsi'); var fixturesDir = path.join(__dirname, 'fixtures/config'); var runner = require('gulp-test-tools').gulpRunner().basedir(fixturesDir); @@ -36,7 +37,7 @@ describe('config: flags.silent', function() { function cb(err, stdout, stderr) { expect(err).toEqual(null); expect(stderr).toEqual(''); - stdout = eraseLapse(eraseTime(skipLines(stdout, 1))); + stdout = eraseLapse(eraseTime(stripAnsi(skipLines(stdout, 1)))); expect(stdout).toEqual( 'Starting \'default\'...\n' + 'Finished \'default\' after ?\n' + diff --git a/test/config-flags-sortTasks.js b/test/config-flags-sortTasks.js index 1da46918..a5eed16c 100644 --- a/test/config-flags-sortTasks.js +++ b/test/config-flags-sortTasks.js @@ -5,6 +5,7 @@ var path = require('path'); var fs = require('fs'); var skipLines = require('gulp-test-tools').skipLines; var eraseTime = require('gulp-test-tools').eraseTime; +var stripAnsi = require('./shared/stripAnsi'); var fixturesDir = path.join(__dirname, 'fixtures/config'); var expectedDir = path.join(__dirname, 'expected'); @@ -24,7 +25,7 @@ describe ('config: flags.sortTasks', function() { var expected = fs.readFileSync(filepath, 'utf-8'); expected = skipLines(expected, 1); - stdout = eraseTime(skipLines(stdout, 1)); + stdout = eraseTime(stripAnsi(skipLines(stdout, 1))); expect(stdout).toEqual(expected); expect(stderr).toEqual(''); @@ -44,7 +45,7 @@ describe ('config: flags.sortTasks', function() { var expected = fs.readFileSync(filepath, 'utf-8'); expected = skipLines(expected, 1); - stdout = eraseTime(skipLines(stdout, 1)); + stdout = eraseTime(stripAnsi(skipLines(stdout, 1))); expect(stdout).toEqual(expected); expect(stderr).toEqual(''); diff --git a/test/config-flags-tasksDepth.js b/test/config-flags-tasksDepth.js index 90c7822f..f5df70c0 100644 --- a/test/config-flags-tasksDepth.js +++ b/test/config-flags-tasksDepth.js @@ -5,6 +5,7 @@ var path = require('path'); var fs = require('fs'); var skipLines = require('gulp-test-tools').skipLines; var eraseTime = require('gulp-test-tools').eraseTime; +var stripAnsi = require('./shared/stripAnsi'); var fixturesDir = path.join(__dirname, 'fixtures/config'); var expectedDir = path.join(__dirname, 'expected'); @@ -24,7 +25,7 @@ describe ('config: flags.tasksDepth', function() { var expected = fs.readFileSync(filepath, 'utf-8'); expected = skipLines(expected, 1); - stdout = eraseTime(skipLines(stdout, 1)); + stdout = eraseTime(stripAnsi(skipLines(stdout, 1))); expect(stdout).toEqual(expected); expect(stderr).toEqual(''); diff --git a/test/exports-as-tasks.js b/test/exports-as-tasks.js index 708c9a52..41d2644c 100644 --- a/test/exports-as-tasks.js +++ b/test/exports-as-tasks.js @@ -6,6 +6,7 @@ var path = require('path'); var skipLines = require('gulp-test-tools').skipLines; var eraseTime = require('gulp-test-tools').eraseTime; var runner = require('gulp-test-tools').gulpRunner; +var stripAnsi = require('./shared/stripAnsi'); var expectedDir = path.join(__dirname, 'expected'); @@ -24,7 +25,7 @@ describe('exports as tasks', function() { expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'tasks-as-exports.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - stdout = eraseTime(skipLines(stdout, 2)); + stdout = eraseTime(stripAnsi(skipLines(stdout, 2))); expect(stdout).toEqual(expected); done(err); } diff --git a/test/fixtures/packages/valid-package.json b/test/fixtures/packages/valid-package.json index b9d30e04..be2d488c 100644 --- a/test/fixtures/packages/valid-package.json +++ b/test/fixtures/packages/valid-package.json @@ -1,21 +1,21 @@ -{ - "name": "test-package-2", - "description": "Test Package for Testing!", - "version": "0.0.1", - "tags": [ - ], - "files": [ - ], - "dependencies": { - "yargs": "^3.27.0" - }, - "engines": { - "node": ">= 0.9" - }, - "licenses": [ - { - "type": "MIT", - "url": "https://raw.githubusercontent.com/gulpjs/gulp/master/LICENSE" - } - ] -} +{ + "name": "test-package-2", + "description": "Test Package for Testing!", + "version": "0.0.1", + "tags": [ + ], + "files": [ + ], + "dependencies": { + "yargs": "^3.27.0" + }, + "engines": { + "node": ">= 0.9" + }, + "licenses": [ + { + "type": "MIT", + "url": "https://raw.githubusercontent.com/gulpjs/gulp/master/LICENSE" + } + ] +} diff --git a/test/flags-continue.js b/test/flags-continue.js index fbfe644a..091edaef 100644 --- a/test/flags-continue.js +++ b/test/flags-continue.js @@ -6,6 +6,7 @@ var eraseTime = require('gulp-test-tools').eraseTime; var eraseLapse = require('gulp-test-tools').eraseLapse; var skipLines = require('gulp-test-tools').skipLines; var headLines = require('gulp-test-tools').headLines; +var stripAnsi = require('./shared/stripAnsi'); describe('flag: --continue', function() { @@ -16,7 +17,7 @@ describe('flag: --continue', function() { function cb(err, stdout, stderr) { expect(err).toNotEqual(null); - stdout = eraseLapse(eraseTime(skipLines(stdout, 2))); + stdout = eraseLapse(eraseTime(stripAnsi(skipLines(stdout, 2)))); expect(stdout).toEqual( 'Starting \'test4\'...\n' + 'Starting \'errorFunction\'...\n' + @@ -25,8 +26,8 @@ describe('flag: --continue', function() { '' ); - stderr = eraseLapse(eraseTime(headLines(stderr, 2))); - expect(stderr).toEqual( + stderr = eraseLapse(eraseTime(stripAnsi(headLines(stderr, 2)))); + expect(stripAnsi(stderr)).toEqual( '\'errorFunction\' errored after ?\n' + 'Error: Error!' ); @@ -42,14 +43,14 @@ describe('flag: --continue', function() { function cb(err, stdout, stderr) { expect(err).toNotEqual(null); expect(stdout).toNotMatch('Starting \'anon\''); - stdout = eraseLapse(eraseTime(skipLines(stdout, 2))); + stdout = eraseLapse(eraseTime(stripAnsi(skipLines(stdout, 2)))); expect(stdout).toEqual( 'Starting \'test4\'...\n' + 'Starting \'errorFunction\'...\n' + '' ); - stderr = eraseLapse(eraseTime(headLines(stderr, 2))); + stderr = eraseLapse(eraseTime(stripAnsi(headLines(stderr, 2)))); expect(stderr).toEqual( '\'errorFunction\' errored after ?\n' + 'Error: Error!' diff --git a/test/flags-gulpfile.js b/test/flags-gulpfile.js index 2f75a4e9..288db151 100644 --- a/test/flags-gulpfile.js +++ b/test/flags-gulpfile.js @@ -7,6 +7,7 @@ var headLines = require('gulp-test-tools').headLines; var eraseTime = require('gulp-test-tools').eraseTime; var eraseLapse = require('gulp-test-tools').eraseLapse; var path = require('path'); +var stripAnsi = require('./shared/stripAnsi'); describe('flag: --gulpfile', function() { @@ -25,8 +26,7 @@ describe('flag: --gulpfile', function() { var workdir = path.dirname(gulpfilePath).replace(/\//g, path.sep); expect(chgWorkdirLog).toMatch('Working directory changed to '); expect(chgWorkdirLog).toMatch(workdir); - - stdout = eraseLapse(eraseTime(skipLines(stdout, 2))); + stdout = eraseLapse(eraseTime(stripAnsi(skipLines(stdout, 2)))); expect(stdout).toEqual( 'Starting \'default\'...\n' + 'Starting \'logGulpfilePath\'...\n' + diff --git a/test/flags-help.js b/test/flags-help.js index f9dcad0a..597490b0 100644 --- a/test/flags-help.js +++ b/test/flags-help.js @@ -5,11 +5,7 @@ var runner = require('gulp-test-tools').gulpRunner; var path = require('path'); var fs = require('fs'); - -// Erases a first space inserted by `chalk`. -function eraseFirstSpace(s) { - return s.replace(/^(\r\n|\n|\r)\s?/g, '\n'); -} +var stripAnsi = require('./shared/stripAnsi'); var outputFile = path.join(__dirname, 'expected/flags-help.txt'); var outputText = fs.readFileSync(outputFile, 'utf8'); @@ -24,8 +20,7 @@ describe('flag: --help', function() { function cb(err, stdout, stderr) { expect(err).toEqual(null); expect(stderr).toEqual(''); - stdout = eraseFirstSpace(stdout); - expect(stdout).toEqual(outputText); + expect(stripAnsi(stdout)).toEqual(outputText); done(err); } }); @@ -38,8 +33,7 @@ describe('flag: --help', function() { function cb(err, stdout, stderr) { expect(err).toEqual(null); expect(stderr).toEqual(''); - stdout = eraseFirstSpace(stdout); - expect(stdout).toEqual(outputText); + expect(stripAnsi(stdout)).toEqual(outputText); done(err); } }); diff --git a/test/flags-require.js b/test/flags-require.js index 4e8decca..f87e77d9 100644 --- a/test/flags-require.js +++ b/test/flags-require.js @@ -7,6 +7,7 @@ var headLines = require('gulp-test-tools').headLines; var eraseTime = require('gulp-test-tools').eraseTime; var eraseLapse = require('gulp-test-tools').eraseLapse; var path = require('path'); +var stripAnsi = require('./shared/stripAnsi'); describe('flag: --require', function() { @@ -21,7 +22,7 @@ describe('flag: --require', function() { var insideLog = headLines(stdout, 1); expect(insideLog).toEqual('inside test module'); - var requireLog = eraseTime(headLines(stdout, 1, 1)); + var requireLog = eraseTime(stripAnsi(headLines(stdout, 1, 1))); expect(requireLog).toEqual( 'Requiring external module ../test-module.js'); @@ -30,7 +31,7 @@ describe('flag: --require', function() { expect(chgWorkdirLog).toMatch('Working directory changed to '); expect(chgWorkdirLog).toMatch(workdir); - stdout = eraseLapse(eraseTime(skipLines(stdout, 4))); + stdout = eraseLapse(eraseTime(stripAnsi(skipLines(stdout, 4)))); expect(stdout).toEqual( 'Starting \'default\'...\n' + 'Starting \'test1\'...\n' + @@ -57,7 +58,7 @@ describe('flag: --require', function() { function cb(err, stdout, stderr) { expect(err).toEqual(null); - stderr = eraseLapse(eraseTime(stderr)); + stderr = eraseLapse(eraseTime(stripAnsi(stderr))); expect(stderr).toMatch('Failed to load external module ./null-module.js'); expect(stdout).toNotMatch('inside test module'); expect(stdout).toNotMatch( @@ -68,7 +69,7 @@ describe('flag: --require', function() { expect(chgWorkdirLog).toMatch('Working directory changed to '); expect(chgWorkdirLog).toMatch(workdir); - stdout = eraseLapse(eraseTime(skipLines(stdout, 2))); + stdout = eraseLapse(eraseTime(stripAnsi(skipLines(stdout, 2)))); expect(stdout).toEqual( 'Starting \'default\'...\n' + 'Starting \'test1\'...\n' + diff --git a/test/flags-tasks.js b/test/flags-tasks.js index 10662cc1..8f7430c8 100644 --- a/test/flags-tasks.js +++ b/test/flags-tasks.js @@ -6,6 +6,7 @@ var path = require('path'); var skipLines = require('gulp-test-tools').skipLines; var eraseTime = require('gulp-test-tools').eraseTime; var runner = require('gulp-test-tools').gulpRunner; +var stripAnsi = require('./shared/stripAnsi'); var expectedDir = path.join(__dirname, 'expected'); @@ -21,7 +22,7 @@ describe('flag: --tasks', function() { expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - stdout = eraseTime(skipLines(stdout, 1)); + stdout = eraseTime(stripAnsi(skipLines(stdout, 1))); expect(stdout).toEqual(expected); done(err); } @@ -39,7 +40,7 @@ describe('flag: --tasks', function() { expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'with-desc-and-flags.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - stdout = eraseTime(skipLines(stdout, 1)); + stdout = eraseTime(stripAnsi(skipLines(stdout, 1))); expect(stdout).toEqual(expected); done(err); } @@ -58,7 +59,7 @@ describe('flag: --tasks', function() { expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'by-unwrap-and-not-by-unwrap.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - stdout = eraseTime(skipLines(stdout, 1)); + stdout = eraseTime(stripAnsi(skipLines(stdout, 1))); expect(stdout).toEqual(expected); done(err); } @@ -74,7 +75,7 @@ describe('flag: --tasks', function() { expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks-unsorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - stdout = eraseTime(skipLines(stdout, 1)); + stdout = eraseTime(stripAnsi(skipLines(stdout, 1))); expect(stdout).toEqual(expected); done(err); } @@ -91,7 +92,7 @@ describe('flag: --tasks', function() { expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks-sorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - stdout = eraseTime(skipLines(stdout, 1)); + stdout = eraseTime(stripAnsi(skipLines(stdout, 1))); expect(stdout).toEqual(expected); done(err); } @@ -108,7 +109,7 @@ describe('flag: --tasks', function() { expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks-depth4.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - stdout = eraseTime(skipLines(stdout, 1)); + stdout = eraseTime(stripAnsi(skipLines(stdout, 1))); expect(stdout).toEqual(expected); done(err); } @@ -125,7 +126,7 @@ describe('flag: --tasks', function() { expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks-depth4.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - stdout = eraseTime(skipLines(stdout, 1)); + stdout = eraseTime(stripAnsi(skipLines(stdout, 1))); expect(stdout).toEqual(expected); done(err); } @@ -142,7 +143,7 @@ describe('flag: --tasks', function() { expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks-compact.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - stdout = eraseTime(skipLines(stdout, 1)); + stdout = eraseTime(stripAnsi(skipLines(stdout, 1))); expect(stdout).toEqual(expected); done(err); } diff --git a/test/flags-verify.js b/test/flags-verify.js index e296b1ff..53664e19 100644 --- a/test/flags-verify.js +++ b/test/flags-verify.js @@ -4,6 +4,7 @@ var expect = require('expect'); var runner = require('gulp-test-tools').gulpRunner; var eraseTime = require('gulp-test-tools').eraseTime; var path = require('path'); +var stripAnsi = require('./shared/stripAnsi'); describe('flag: --verify', function() { @@ -15,7 +16,7 @@ describe('flag: --verify', function() { function cb(err, stdout, stderr) { expect(err).toNotEqual(null); expect(stderr).toEqual(''); - stdout = eraseTime(stdout); + stdout = eraseTime(stripAnsi(stdout)); expect(stdout).toEqual( 'Verifying plugins in ' + path.resolve('./test/fixtures/packages/invalid-package.json') + @@ -36,7 +37,7 @@ describe('flag: --verify', function() { function cb(err, stdout, stderr) { expect(err).toEqual(null); expect(stderr).toEqual(''); - stdout = eraseTime(stdout); + stdout = eraseTime(stripAnsi(stdout)); expect(stdout).toEqual( 'Verifying plugins in ' + path.resolve('./test/fixtures/packages/valid-package.json') + @@ -56,7 +57,7 @@ describe('flag: --verify', function() { function cb(err, stdout, stderr) { expect(err).toNotEqual(null); expect(stderr).toEqual(''); - stdout = eraseTime(stdout); + stdout = eraseTime(stripAnsi(stdout)); expect(stdout).toEqual( 'Verifying plugins in ' + path.resolve('./test/fixtures/packages/package.json') + '\n' + diff --git a/test/shared/stripAnsi.js b/test/shared/stripAnsi.js new file mode 100644 index 00000000..caef32e3 --- /dev/null +++ b/test/shared/stripAnsi.js @@ -0,0 +1,11 @@ +var ansiPattern = [ + '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\\u0007)', + '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))', +].join('|'); +var ansiRegex = new RegExp(ansiPattern, 'g'); + +function stripAnsi(value) { + return value.replace(ansiRegex, ''); +} + +module.exports = stripAnsi; From b018821effab9ae3c7af151f15c95bbc1f0d4386 Mon Sep 17 00:00:00 2001 From: tim Date: Tue, 22 Aug 2017 20:16:48 +0200 Subject: [PATCH 2/8] add ansi-green --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 1dad6508..75012a81 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "ansi-bold": "^0.1.1", "ansi-cyan": "^0.1.1", "ansi-gray": "^0.1.1", + "ansi-green": "^0.1.1", "ansi-magenta": "^0.1.1", "ansi-red": "^0.1.1", "ansi-white": "^0.1.1", From 0c4321265650a9d4c0179b0bc8b889e2a161e212 Mon Sep 17 00:00:00 2001 From: tim Date: Tue, 22 Aug 2017 20:28:37 +0200 Subject: [PATCH 3/8] fix --help tests --- test/flags-help.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/flags-help.js b/test/flags-help.js index 597490b0..82b9ea7c 100644 --- a/test/flags-help.js +++ b/test/flags-help.js @@ -7,6 +7,11 @@ var path = require('path'); var fs = require('fs'); var stripAnsi = require('./shared/stripAnsi'); +// Erases a first space inserted by `ansi-*`. +function eraseFirstSpace(s) { + return s.replace(/^(\r\n|\n|\r)\s?/g, '\n'); +} + var outputFile = path.join(__dirname, 'expected/flags-help.txt'); var outputText = fs.readFileSync(outputFile, 'utf8'); @@ -20,7 +25,8 @@ describe('flag: --help', function() { function cb(err, stdout, stderr) { expect(err).toEqual(null); expect(stderr).toEqual(''); - expect(stripAnsi(stdout)).toEqual(outputText); + stdout = stripAnsi(eraseFirstSpace(stdout)); + expect(stdout).toEqual(outputText); done(err); } }); @@ -33,7 +39,8 @@ describe('flag: --help', function() { function cb(err, stdout, stderr) { expect(err).toEqual(null); expect(stderr).toEqual(''); - expect(stripAnsi(stdout)).toEqual(outputText); + stdout = stripAnsi(eraseFirstSpace(stdout)); + expect(stdout).toEqual(outputText); done(err); } }); From 841065ffe967d9b83186321728c2cc8b05fbce9e Mon Sep 17 00:00:00 2001 From: tim Date: Tue, 22 Aug 2017 20:42:58 +0200 Subject: [PATCH 4/8] revert change --- test/fixtures/packages/valid-package.json | 42 +++++++++++------------ 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/test/fixtures/packages/valid-package.json b/test/fixtures/packages/valid-package.json index be2d488c..b9d30e04 100644 --- a/test/fixtures/packages/valid-package.json +++ b/test/fixtures/packages/valid-package.json @@ -1,21 +1,21 @@ -{ - "name": "test-package-2", - "description": "Test Package for Testing!", - "version": "0.0.1", - "tags": [ - ], - "files": [ - ], - "dependencies": { - "yargs": "^3.27.0" - }, - "engines": { - "node": ">= 0.9" - }, - "licenses": [ - { - "type": "MIT", - "url": "https://raw.githubusercontent.com/gulpjs/gulp/master/LICENSE" - } - ] -} +{ + "name": "test-package-2", + "description": "Test Package for Testing!", + "version": "0.0.1", + "tags": [ + ], + "files": [ + ], + "dependencies": { + "yargs": "^3.27.0" + }, + "engines": { + "node": ">= 0.9" + }, + "licenses": [ + { + "type": "MIT", + "url": "https://raw.githubusercontent.com/gulpjs/gulp/master/LICENSE" + } + ] +} From 080e2064132fb83c90768db0187e6a28a40f95f3 Mon Sep 17 00:00:00 2001 From: tim Date: Wed, 23 Aug 2017 17:36:44 +0200 Subject: [PATCH 5/8] use strict --- lib/shared/ansi.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/shared/ansi.js b/lib/shared/ansi.js index 6fe1c702..0d59172e 100644 --- a/lib/shared/ansi.js +++ b/lib/shared/ansi.js @@ -1,3 +1,5 @@ +'use strict'; + var red = require('ansi-red'); var green = require('ansi-green'); var blue = require('ansi-blue'); From 3e41e97fcdb324b969c7d4b8b152b416d3ae1041 Mon Sep 17 00:00:00 2001 From: tim Date: Fri, 25 Aug 2017 17:34:20 +0200 Subject: [PATCH 6/8] add strip-color instead of stripAnsi --- lib/shared/ansi.js | 2 + package.json | 1 + test/config-description.js | 2 +- test/config-flags-compactTasks.js | 2 +- test/config-flags-continue.js | 2 +- test/config-flags-log-level.js | 2 +- test/config-flags-silent.js | 2 +- test/config-flags-sortTasks.js | 2 +- test/config-flags-tasksDepth.js | 2 +- test/exports-as-tasks.js | 2 +- test/fixtures/packages/invalid-package.json | 42 ++++++++++----------- test/fixtures/packages/valid-package.json | 42 ++++++++++----------- test/flags-continue.js | 2 +- test/flags-gulpfile.js | 2 +- test/flags-help.js | 2 +- test/flags-require.js | 2 +- test/flags-tasks.js | 2 +- test/flags-verify.js | 2 +- test/shared/stripAnsi.js | 11 ------ 19 files changed, 59 insertions(+), 67 deletions(-) delete mode 100644 test/shared/stripAnsi.js diff --git a/lib/shared/ansi.js b/lib/shared/ansi.js index 0d59172e..a7da7301 100644 --- a/lib/shared/ansi.js +++ b/lib/shared/ansi.js @@ -9,6 +9,7 @@ var white = require('ansi-white'); var gray = require('ansi-gray'); var bgred = require('ansi-bgred'); var bold = require('ansi-bold'); +var strip = require('strip-color'); module.exports = { red: red, @@ -20,5 +21,6 @@ module.exports = { gray: gray, bgred: bgred, bold: bold, + strip: strip, }; diff --git a/package.json b/package.json index 75012a81..0982a799 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,7 @@ "mute-stdout": "^1.0.0", "pretty-hrtime": "^1.0.0", "semver-greatest-satisfied-range": "^1.0.0", + "strip-color": "^0.1.0", "tildify": "^1.0.0", "v8flags": "^2.0.9", "wreck": "^6.3.0", diff --git a/test/config-description.js b/test/config-description.js index f9daf1a9..2bd02f3b 100644 --- a/test/config-description.js +++ b/test/config-description.js @@ -7,7 +7,7 @@ var fs = require('fs'); var skipLines = require('gulp-test-tools').skipLines; var eraseTime = require('gulp-test-tools').eraseTime; var runner = require('gulp-test-tools').gulpRunner; -var stripAnsi = require('./shared/stripAnsi'); +var stripAnsi = require('../lib/shared/ansi').strip; var fixturesDir = path.join(__dirname, 'fixtures', 'config'); var expectedDir = path.join(__dirname, 'expected', 'config'); diff --git a/test/config-flags-compactTasks.js b/test/config-flags-compactTasks.js index 4e5242b4..95f3214c 100644 --- a/test/config-flags-compactTasks.js +++ b/test/config-flags-compactTasks.js @@ -5,7 +5,7 @@ var path = require('path'); var fs = require('fs'); var skipLines = require('gulp-test-tools').skipLines; var eraseTime = require('gulp-test-tools').eraseTime; -var stripAnsi = require('./shared/stripAnsi'); +var stripAnsi = require('../lib/shared/ansi').strip; var fixturesDir = path.join(__dirname, 'fixtures/config'); var expectedDir = path.join(__dirname, 'expected'); diff --git a/test/config-flags-continue.js b/test/config-flags-continue.js index 39efffbd..e51b3881 100644 --- a/test/config-flags-continue.js +++ b/test/config-flags-continue.js @@ -6,7 +6,7 @@ var skipLines = require('gulp-test-tools').skipLines; var headLines = require('gulp-test-tools').headLines; var eraseTime = require('gulp-test-tools').eraseTime; var eraseLapse = require('gulp-test-tools').eraseLapse; -var stripAnsi = require('./shared/stripAnsi'); +var stripAnsi = require('../lib/shared/ansi').strip; var fixturesDir = path.join(__dirname, 'fixtures/config'); var runner = require('gulp-test-tools').gulpRunner({ verbose: false }).basedir(fixturesDir); diff --git a/test/config-flags-log-level.js b/test/config-flags-log-level.js index 4b5d8155..4bef44a1 100644 --- a/test/config-flags-log-level.js +++ b/test/config-flags-log-level.js @@ -4,7 +4,7 @@ var expect = require('expect'); var path = require('path'); var eraseTime = require('gulp-test-tools').eraseTime; var runner = require('gulp-test-tools').gulpRunner; -var stripAnsi = require('./shared/stripAnsi'); +var stripAnsi = require('../lib/shared/ansi').strip; describe('config: flag.logLevel', function() { diff --git a/test/config-flags-silent.js b/test/config-flags-silent.js index 80bc879d..7d07f899 100644 --- a/test/config-flags-silent.js +++ b/test/config-flags-silent.js @@ -5,7 +5,7 @@ var path = require('path'); var skipLines = require('gulp-test-tools').skipLines; var eraseTime = require('gulp-test-tools').eraseTime; var eraseLapse = require('gulp-test-tools').eraseLapse; -var stripAnsi = require('./shared/stripAnsi'); +var stripAnsi = require('../lib/shared/ansi').strip; var fixturesDir = path.join(__dirname, 'fixtures/config'); var runner = require('gulp-test-tools').gulpRunner().basedir(fixturesDir); diff --git a/test/config-flags-sortTasks.js b/test/config-flags-sortTasks.js index a5eed16c..382ec744 100644 --- a/test/config-flags-sortTasks.js +++ b/test/config-flags-sortTasks.js @@ -5,7 +5,7 @@ var path = require('path'); var fs = require('fs'); var skipLines = require('gulp-test-tools').skipLines; var eraseTime = require('gulp-test-tools').eraseTime; -var stripAnsi = require('./shared/stripAnsi'); +var stripAnsi = require('../lib/shared/ansi').strip; var fixturesDir = path.join(__dirname, 'fixtures/config'); var expectedDir = path.join(__dirname, 'expected'); diff --git a/test/config-flags-tasksDepth.js b/test/config-flags-tasksDepth.js index f5df70c0..6701c6c1 100644 --- a/test/config-flags-tasksDepth.js +++ b/test/config-flags-tasksDepth.js @@ -5,7 +5,7 @@ var path = require('path'); var fs = require('fs'); var skipLines = require('gulp-test-tools').skipLines; var eraseTime = require('gulp-test-tools').eraseTime; -var stripAnsi = require('./shared/stripAnsi'); +var stripAnsi = require('../lib/shared/ansi').strip; var fixturesDir = path.join(__dirname, 'fixtures/config'); var expectedDir = path.join(__dirname, 'expected'); diff --git a/test/exports-as-tasks.js b/test/exports-as-tasks.js index 41d2644c..e1974d04 100644 --- a/test/exports-as-tasks.js +++ b/test/exports-as-tasks.js @@ -6,7 +6,7 @@ var path = require('path'); var skipLines = require('gulp-test-tools').skipLines; var eraseTime = require('gulp-test-tools').eraseTime; var runner = require('gulp-test-tools').gulpRunner; -var stripAnsi = require('./shared/stripAnsi'); +var stripAnsi = require('../lib/shared/ansi').strip; var expectedDir = path.join(__dirname, 'expected'); diff --git a/test/fixtures/packages/invalid-package.json b/test/fixtures/packages/invalid-package.json index 29a15016..4f99a0f2 100644 --- a/test/fixtures/packages/invalid-package.json +++ b/test/fixtures/packages/invalid-package.json @@ -1,21 +1,21 @@ -{ - "name": "test-package", - "description": "Test Package for Testing!", - "version": "0.0.1", - "tags": [ - ], - "files": [ - ], - "dependencies": { - "gulp-blink": "^0.1.4" - }, - "engines": { - "node": ">= 0.9" - }, - "licenses": [ - { - "type": "MIT", - "url": "https://raw.githubusercontent.com/gulpjs/gulp/master/LICENSE" - } - ] -} +{ + "name": "test-package", + "description": "Test Package for Testing!", + "version": "0.0.1", + "tags": [ + ], + "files": [ + ], + "dependencies": { + "gulp-blink": "^0.1.4" + }, + "engines": { + "node": ">= 0.9" + }, + "licenses": [ + { + "type": "MIT", + "url": "https://raw.githubusercontent.com/gulpjs/gulp/master/LICENSE" + } + ] +} diff --git a/test/fixtures/packages/valid-package.json b/test/fixtures/packages/valid-package.json index b9d30e04..be2d488c 100644 --- a/test/fixtures/packages/valid-package.json +++ b/test/fixtures/packages/valid-package.json @@ -1,21 +1,21 @@ -{ - "name": "test-package-2", - "description": "Test Package for Testing!", - "version": "0.0.1", - "tags": [ - ], - "files": [ - ], - "dependencies": { - "yargs": "^3.27.0" - }, - "engines": { - "node": ">= 0.9" - }, - "licenses": [ - { - "type": "MIT", - "url": "https://raw.githubusercontent.com/gulpjs/gulp/master/LICENSE" - } - ] -} +{ + "name": "test-package-2", + "description": "Test Package for Testing!", + "version": "0.0.1", + "tags": [ + ], + "files": [ + ], + "dependencies": { + "yargs": "^3.27.0" + }, + "engines": { + "node": ">= 0.9" + }, + "licenses": [ + { + "type": "MIT", + "url": "https://raw.githubusercontent.com/gulpjs/gulp/master/LICENSE" + } + ] +} diff --git a/test/flags-continue.js b/test/flags-continue.js index 091edaef..7a4de485 100644 --- a/test/flags-continue.js +++ b/test/flags-continue.js @@ -6,7 +6,7 @@ var eraseTime = require('gulp-test-tools').eraseTime; var eraseLapse = require('gulp-test-tools').eraseLapse; var skipLines = require('gulp-test-tools').skipLines; var headLines = require('gulp-test-tools').headLines; -var stripAnsi = require('./shared/stripAnsi'); +var stripAnsi = require('../lib/shared/ansi').strip; describe('flag: --continue', function() { diff --git a/test/flags-gulpfile.js b/test/flags-gulpfile.js index 288db151..2b87e134 100644 --- a/test/flags-gulpfile.js +++ b/test/flags-gulpfile.js @@ -7,7 +7,7 @@ var headLines = require('gulp-test-tools').headLines; var eraseTime = require('gulp-test-tools').eraseTime; var eraseLapse = require('gulp-test-tools').eraseLapse; var path = require('path'); -var stripAnsi = require('./shared/stripAnsi'); +var stripAnsi = require('../lib/shared/ansi').strip; describe('flag: --gulpfile', function() { diff --git a/test/flags-help.js b/test/flags-help.js index 82b9ea7c..48e10844 100644 --- a/test/flags-help.js +++ b/test/flags-help.js @@ -5,7 +5,7 @@ var runner = require('gulp-test-tools').gulpRunner; var path = require('path'); var fs = require('fs'); -var stripAnsi = require('./shared/stripAnsi'); +var stripAnsi = require('../lib/shared/ansi').strip; // Erases a first space inserted by `ansi-*`. function eraseFirstSpace(s) { diff --git a/test/flags-require.js b/test/flags-require.js index f87e77d9..2323b171 100644 --- a/test/flags-require.js +++ b/test/flags-require.js @@ -7,7 +7,7 @@ var headLines = require('gulp-test-tools').headLines; var eraseTime = require('gulp-test-tools').eraseTime; var eraseLapse = require('gulp-test-tools').eraseLapse; var path = require('path'); -var stripAnsi = require('./shared/stripAnsi'); +var stripAnsi = require('../lib/shared/ansi').strip; describe('flag: --require', function() { diff --git a/test/flags-tasks.js b/test/flags-tasks.js index 8f7430c8..7864b80e 100644 --- a/test/flags-tasks.js +++ b/test/flags-tasks.js @@ -6,7 +6,7 @@ var path = require('path'); var skipLines = require('gulp-test-tools').skipLines; var eraseTime = require('gulp-test-tools').eraseTime; var runner = require('gulp-test-tools').gulpRunner; -var stripAnsi = require('./shared/stripAnsi'); +var stripAnsi = require('../lib/shared/ansi').strip; var expectedDir = path.join(__dirname, 'expected'); diff --git a/test/flags-verify.js b/test/flags-verify.js index 53664e19..db4c1d86 100644 --- a/test/flags-verify.js +++ b/test/flags-verify.js @@ -4,7 +4,7 @@ var expect = require('expect'); var runner = require('gulp-test-tools').gulpRunner; var eraseTime = require('gulp-test-tools').eraseTime; var path = require('path'); -var stripAnsi = require('./shared/stripAnsi'); +var stripAnsi = require('../lib/shared/ansi').strip; describe('flag: --verify', function() { diff --git a/test/shared/stripAnsi.js b/test/shared/stripAnsi.js deleted file mode 100644 index caef32e3..00000000 --- a/test/shared/stripAnsi.js +++ /dev/null @@ -1,11 +0,0 @@ -var ansiPattern = [ - '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\\u0007)', - '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))', -].join('|'); -var ansiRegex = new RegExp(ansiPattern, 'g'); - -function stripAnsi(value) { - return value.replace(ansiRegex, ''); -} - -module.exports = stripAnsi; From 6b7ad71c062c8ff67bfd765b2673a81bcfa96389 Mon Sep 17 00:00:00 2001 From: tim Date: Tue, 26 Sep 2017 18:57:15 +0200 Subject: [PATCH 7/8] support --no-color --- lib/shared/ansi.js | 32 +++-- package.json | 2 +- test/config-description.js | 17 +-- test/config-flags-compactTasks.js | 19 ++- test/config-flags-continue.js | 11 +- test/config-flags-log-level.js | 201 ++++++++++++++---------------- test/config-flags-silent.js | 5 +- test/config-flags-sortTasks.js | 19 ++- test/config-flags-tasksDepth.js | 14 +-- test/exports-as-tasks.js | 7 +- test/flags-continue.js | 13 +- test/flags-gulpfile.js | 5 +- test/flags-help.js | 9 +- test/flags-require.js | 11 +- test/flags-tasks.js | 48 ++++--- test/flags-verify.js | 28 ++--- 16 files changed, 197 insertions(+), 244 deletions(-) diff --git a/lib/shared/ansi.js b/lib/shared/ansi.js index a7da7301..1e4fcb95 100644 --- a/lib/shared/ansi.js +++ b/lib/shared/ansi.js @@ -9,18 +9,28 @@ var white = require('ansi-white'); var gray = require('ansi-gray'); var bgred = require('ansi-bgred'); var bold = require('ansi-bold'); -var strip = require('strip-color'); +var hasFlag = require('has-flag'); module.exports = { - red: red, - green: green, - blue: blue, - magenta: magenta, - cyan: cyan, - white: white, - gray: gray, - bgred: bgred, - bold: bold, - strip: strip, + red: colorize() ? red : noColor, + green: colorize() ? green : noColor, + blue: colorize() ? blue : noColor, + magenta: colorize() ? magenta : noColor, + cyan: colorize() ? cyan : noColor, + white: colorize() ? white : noColor, + gray: colorize() ? gray : noColor, + bgred: colorize() ? bgred : noColor, + bold: colorize() ? bold : noColor, }; +function noColor(message) { + return message; +} + +function colorize() { + var noColorFlag = + hasFlag('no-color') || hasFlag('no-colors') || hasFlag('color=false'); + var isTTY = process.stdout && process.stdout.isTTY; + var colorOutput = !noColorFlag && isTTY; + return colorOutput; +} diff --git a/package.json b/package.json index d7999811..c2217486 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "copy-props": "^2.0.1", "fancy-log": "^1.1.0", "gulplog": "^1.0.0", + "has-flag": "^2.0.0", "interpret": "^1.0.0", "liftoff": "^2.3.0", "lodash.isfunction": "^3.0.8", @@ -54,7 +55,6 @@ "mute-stdout": "^1.0.0", "pretty-hrtime": "^1.0.0", "semver-greatest-satisfied-range": "^1.0.0", - "strip-color": "^0.1.0", "tildify": "^1.0.0", "v8flags": "^2.0.9", "wreck": "^6.3.0", diff --git a/test/config-description.js b/test/config-description.js index 2bd02f3b..e64d4630 100644 --- a/test/config-description.js +++ b/test/config-description.js @@ -7,13 +7,11 @@ var fs = require('fs'); var skipLines = require('gulp-test-tools').skipLines; var eraseTime = require('gulp-test-tools').eraseTime; var runner = require('gulp-test-tools').gulpRunner; -var stripAnsi = require('../lib/shared/ansi').strip; var fixturesDir = path.join(__dirname, 'fixtures', 'config'); var expectedDir = path.join(__dirname, 'expected', 'config'); describe('config: description', function() { - it('Should configure with a .gulp.* file in cwd', function(done) { runner({ verbose: false }) .basedir(fixturesDir) @@ -24,9 +22,8 @@ describe('config: description', function() { function cb(err, stdout, stderr) { expect(err).toEqual(null); expect(stderr).toEqual(''); - var expected = fs.readFileSync(path.join(expectedDir, 'output0.txt'), - 'utf-8'); - stdout = eraseTime(stripAnsi(stdout)); + var expected = fs.readFileSync(path.join(expectedDir, 'output0.txt'), 'utf-8'); + stdout = eraseTime(stdout); expect(stdout).toEqual(expected); done(err); } @@ -42,9 +39,8 @@ describe('config: description', function() { function cb(err, stdout, stderr) { expect(err).toEqual(null); expect(stderr).toEqual(''); - var expected = fs.readFileSync(path.join(expectedDir, 'output0.txt'), - 'utf-8'); - stdout = eraseTime(stripAnsi(skipLines(stdout, 1))); + var expected = fs.readFileSync(path.join(expectedDir, 'output0.txt'), 'utf-8'); + stdout = eraseTime(skipLines(stdout, 1)); expect(stdout).toEqual(expected); done(err); } @@ -60,9 +56,8 @@ describe('config: description', function() { function cb(err, stdout, stderr) { expect(err).toEqual(null); expect(stderr).toEqual(''); - var expected = fs.readFileSync(path.join(expectedDir, 'output1.txt'), - 'utf-8'); - stdout = eraseTime(stripAnsi(stdout)); + var expected = fs.readFileSync(path.join(expectedDir, 'output1.txt'), 'utf-8'); + stdout = eraseTime(stdout); expect(stdout).toEqual(expected); done(err); } diff --git a/test/config-flags-compactTasks.js b/test/config-flags-compactTasks.js index 95f3214c..cf4bb488 100644 --- a/test/config-flags-compactTasks.js +++ b/test/config-flags-compactTasks.js @@ -5,16 +5,15 @@ var path = require('path'); var fs = require('fs'); var skipLines = require('gulp-test-tools').skipLines; var eraseTime = require('gulp-test-tools').eraseTime; -var stripAnsi = require('../lib/shared/ansi').strip; var fixturesDir = path.join(__dirname, 'fixtures/config'); var expectedDir = path.join(__dirname, 'expected'); -var runner = require('gulp-test-tools').gulpRunner().basedir(fixturesDir); +var runner = require('gulp-test-tools') + .gulpRunner() + .basedir(fixturesDir); -describe ('config: flags.compactTasks', function() { - - it('Should compact task lists when `flags.compactTasks` is true in .gulp.*', - function(done) { +describe('config: flags.compactTasks', function() { + it('Should compact task lists when `flags.compactTasks` is true in .gulp.*', function(done) { runner .chdir('flags/compactTasks/t') .gulp('--tasks') @@ -25,7 +24,7 @@ describe ('config: flags.compactTasks', function() { var expected = fs.readFileSync(filepath, 'utf-8'); expected = skipLines(expected, 1); - stdout = eraseTime(stripAnsi(skipLines(stdout, 1))); + stdout = eraseTime(skipLines(stdout, 1)); expect(stdout).toEqual(expected); expect(stderr).toEqual(''); @@ -33,8 +32,7 @@ describe ('config: flags.compactTasks', function() { } }); - it('Should not compact task lists when `flags.compactTasks` is false in ' + - '.gulp.*', function(done) { + it('Should not compact task lists when `flags.compactTasks` is false in ' + '.gulp.*', function(done) { runner .chdir('flags/compactTasks/f') .gulp('--tasks') @@ -45,12 +43,11 @@ describe ('config: flags.compactTasks', function() { var expected = fs.readFileSync(filepath, 'utf-8'); expected = skipLines(expected, 1); - stdout = eraseTime(stripAnsi(skipLines(stdout, 1))); + stdout = eraseTime(skipLines(stdout, 1)); expect(stdout).toEqual(expected); expect(stderr).toEqual(''); done(err); } }); - }); diff --git a/test/config-flags-continue.js b/test/config-flags-continue.js index e51b3881..b24b8a6d 100644 --- a/test/config-flags-continue.js +++ b/test/config-flags-continue.js @@ -6,13 +6,11 @@ var skipLines = require('gulp-test-tools').skipLines; var headLines = require('gulp-test-tools').headLines; var eraseTime = require('gulp-test-tools').eraseTime; var eraseLapse = require('gulp-test-tools').eraseLapse; -var stripAnsi = require('../lib/shared/ansi').strip; var fixturesDir = path.join(__dirname, 'fixtures/config'); var runner = require('gulp-test-tools').gulpRunner({ verbose: false }).basedir(fixturesDir); describe('config: flags.continue', function() { - it('Should continue if `flags.continue` is true in .gulp.*', function(done) { runner @@ -23,7 +21,7 @@ describe('config: flags.continue', function() { function cb(err, stdout, stderr) { expect(err).toNotEqual(null); - stdout = eraseLapse(eraseTime(stripAnsi(skipLines(stdout, 1)))); + stdout = eraseLapse(eraseTime(skipLines(stdout, 1))); expect(stdout).toEqual( 'Starting \'default\'...\n' + 'Starting \'err\'...\n' + @@ -31,7 +29,7 @@ describe('config: flags.continue', function() { 'Finished \'next\' after ?\n' + '' ); - stderr = eraseLapse(eraseTime(stripAnsi(headLines(stderr, 2)))); + stderr = eraseLapse(eraseTime(headLines(stderr, 2))); expect(stderr).toEqual( '\'err\' errored after ?\n' + 'Error: Error!' @@ -50,13 +48,13 @@ describe('config: flags.continue', function() { function cb(err, stdout, stderr) { expect(err).toNotEqual(null); - stdout = eraseLapse(eraseTime(stripAnsi(skipLines(stdout, 1)))); + stdout = eraseLapse(eraseTime(skipLines(stdout, 1))); expect(stdout).toEqual( 'Starting \'default\'...\n' + 'Starting \'err\'...\n' + '' ); - stderr = eraseLapse(eraseTime(stripAnsi(headLines(stderr, 2)))); + stderr = eraseLapse(eraseTime(headLines(stderr, 2))); expect(stderr).toEqual( '\'err\' errored after ?\n' + 'Error: Error!' @@ -64,5 +62,4 @@ describe('config: flags.continue', function() { done(); } }); - }); diff --git a/test/config-flags-log-level.js b/test/config-flags-log-level.js index 4bef44a1..12fd20b9 100644 --- a/test/config-flags-log-level.js +++ b/test/config-flags-log-level.js @@ -4,10 +4,8 @@ var expect = require('expect'); var path = require('path'); var eraseTime = require('gulp-test-tools').eraseTime; var runner = require('gulp-test-tools').gulpRunner; -var stripAnsi = require('../lib/shared/ansi').strip; describe('config: flag.logLevel', function() { - describe('log level 3 by default', function() { it('Should output error log', function(done) { runner({ verbose: false }) @@ -15,39 +13,40 @@ describe('config: flag.logLevel', function() { .run(function(err, stdout, stderr) { expect(err).toNotEqual(null); expect(stdout).toEqual(''); - expect(eraseTime(stripAnsi(stderr))).toEqual('No gulpfile found\n'); + expect(eraseTime(stderr)).toEqual('No gulpfile found\n'); done(); }); }); it('Should output warn log', function(done) { - var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', - 'invalid-package.json'); + var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', 'invalid-package.json'); runner({ verbose: false }) .gulp('--verify', packageJsonPath) .run(function(err, stdout, stderr) { expect(err).toNotEqual(null); - expect(eraseTime(stripAnsi(stdout))).toEqual( - 'Verifying plugins in ' + packageJsonPath + '\n' + - 'Blacklisted plugins found in this project:\n' + - 'gulp-blink: deprecated. use \`blink` instead.\n'); + expect(eraseTime(stdout)).toEqual( + 'Verifying plugins in ' + + packageJsonPath + + '\n' + + 'Blacklisted plugins found in this project:\n' + + 'gulp-blink: deprecated. use `blink` instead.\n' + ); expect(stderr).toEqual(''); done(); }); }); it('Should output info log', function(done) { - var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', - 'valid-package.json'); + var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', 'valid-package.json'); runner({ verbose: false }) .gulp('--verify', packageJsonPath) .run(function(err, stdout, stderr) { expect(err).toEqual(null); - expect(eraseTime(stripAnsi(stdout))).toEqual( - 'Verifying plugins in ' + packageJsonPath + '\n' + - 'There are no blacklisted plugins in this project\n'); + expect(eraseTime(stdout)).toEqual( + 'Verifying plugins in ' + packageJsonPath + '\n' + 'There are no blacklisted plugins in this project\n' + ); expect(stderr).toEqual(''); done(err); }); @@ -55,135 +54,117 @@ describe('config: flag.logLevel', function() { }); describe('log level 1 by config `flags.logLevel`', function() { - var gulp = runner({ verbose: false }) - .basedir(path.join(__dirname, 'fixtures/config/flags/logLevel/L')) - .gulp; + var gulp = runner({ verbose: false }).basedir(path.join(__dirname, 'fixtures/config/flags/logLevel/L')).gulp; it('Should output error log', function(done) { - gulp('--gulpfile x') - .run(function(err, stdout, stderr) { - expect(err).toNotEqual(null); - expect(stdout).toEqual(''); - expect(eraseTime(stripAnsi(stderr))).toEqual('No gulpfile found\n'); - done(); - }); + gulp('--gulpfile x').run(function(err, stdout, stderr) { + expect(err).toNotEqual(null); + expect(stdout).toEqual(''); + expect(eraseTime(stderr)).toEqual('No gulpfile found\n'); + done(); + }); }); it('Should output warn log', function(done) { - var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', - 'invalid-package.json'); - - gulp('--verify', packageJsonPath) - .run(function(err, stdout, stderr) { - expect(err).toNotEqual(null); - expect(stdout).toEqual(''); - expect(stderr).toEqual(''); - done(); - }); + var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', 'invalid-package.json'); + + gulp('--verify', packageJsonPath).run(function(err, stdout, stderr) { + expect(err).toNotEqual(null); + expect(stdout).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) - .run(function(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stdout).toEqual(''); - expect(stderr).toEqual(''); - done(err); - }); + var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', 'valid-package.json'); + + gulp('--verify', packageJsonPath).run(function(err, stdout, stderr) { + expect(err).toEqual(null); + expect(stdout).toEqual(''); + expect(stderr).toEqual(''); + done(err); + }); }); }); describe('log level 2 by config `flags.logLevel`', function() { - var gulp = runner({ verbose: false }) - .basedir(path.join(__dirname, 'fixtures/config/flags/logLevel/LL')) - .gulp; + var gulp = runner({ verbose: false }).basedir(path.join(__dirname, 'fixtures/config/flags/logLevel/LL')).gulp; it('Should output error log', function(done) { - gulp('--gulpfile x') - .run(function(err, stdout, stderr) { - expect(err).toNotEqual(null); - expect(stdout).toEqual(''); - expect(eraseTime(stripAnsi(stderr))).toEqual('No gulpfile found\n'); - done(); - }); + gulp('--gulpfile x').run(function(err, stdout, stderr) { + expect(err).toNotEqual(null); + expect(stdout).toEqual(''); + expect(eraseTime(stderr)).toEqual('No gulpfile found\n'); + done(); + }); }); it('Should output warn log', function(done) { - var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', - 'invalid-package.json'); - - gulp('--verify', packageJsonPath) - .run(function(err, stdout, stderr) { - expect(err).toNotEqual(null); - expect(eraseTime(stripAnsi(stdout))).toEqual( - 'Blacklisted plugins found in this project:\n' + - 'gulp-blink: deprecated. use \`blink` instead.\n'); - expect(stderr).toEqual(''); - done(); - }); + var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', 'invalid-package.json'); + + gulp('--verify', packageJsonPath).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(stderr).toEqual(''); + done(); + }); }); it('Should output info log', function(done) { - var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', - 'valid-package.json'); - - gulp('--verify', packageJsonPath) - .run(function(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stdout).toEqual(''); - expect(stderr).toEqual(''); - done(err); - }); + var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', 'valid-package.json'); + + gulp('--verify', packageJsonPath).run(function(err, stdout, stderr) { + expect(err).toEqual(null); + expect(stdout).toEqual(''); + expect(stderr).toEqual(''); + done(err); + }); }); }); describe('log level 3 by config `flags.logLevel`', function() { - var gulp = runner({ verbose: false }) - .basedir(path.join(__dirname, 'fixtures/config/flags/logLevel/LLL')) - .gulp; + var gulp = runner({ verbose: false }).basedir(path.join(__dirname, 'fixtures/config/flags/logLevel/LLL')).gulp; it('Should output error log', function(done) { - gulp('--gulpfile x') - .run(function(err, stdout, stderr) { - expect(err).toNotEqual(null); - expect(stdout).toEqual(''); - expect(eraseTime(stripAnsi(stderr))).toEqual('No gulpfile found\n'); - done(); - }); + gulp('--gulpfile x').run(function(err, stdout, stderr) { + expect(err).toNotEqual(null); + expect(stdout).toEqual(''); + expect(eraseTime(stderr)).toEqual('No gulpfile found\n'); + done(); + }); }); it('Should output warn log', function(done) { - var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', - 'invalid-package.json'); - - gulp('--verify', packageJsonPath) - .run(function(err, stdout, stderr) { - expect(err).toNotEqual(null); - expect(eraseTime(stripAnsi(stdout))).toEqual( - 'Verifying plugins in ' + packageJsonPath + '\n' + + var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', 'invalid-package.json'); + + gulp('--verify', packageJsonPath).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(stderr).toEqual(''); - done(); - }); + 'gulp-blink: deprecated. use `blink` instead.\n' + ); + expect(stderr).toEqual(''); + done(); + }); }); it('Should output info log', function(done) { - var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', - 'valid-package.json'); - - gulp('--verify', packageJsonPath) - .run(function(err, stdout, stderr) { - expect(err).toEqual(null); - expect(eraseTime(stripAnsi(stdout))).toEqual( - 'Verifying plugins in ' + packageJsonPath + '\n' + - 'There are no blacklisted plugins in this project\n'); - expect(stderr).toEqual(''); - done(err); - }); + var packageJsonPath = path.resolve(__dirname, 'fixtures/packages', 'valid-package.json'); + + gulp('--verify', packageJsonPath).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(''); + done(err); + }); }); }); }); diff --git a/test/config-flags-silent.js b/test/config-flags-silent.js index 7d07f899..a56e91c1 100644 --- a/test/config-flags-silent.js +++ b/test/config-flags-silent.js @@ -5,13 +5,11 @@ var path = require('path'); var skipLines = require('gulp-test-tools').skipLines; var eraseTime = require('gulp-test-tools').eraseTime; var eraseLapse = require('gulp-test-tools').eraseLapse; -var stripAnsi = require('../lib/shared/ansi').strip; var fixturesDir = path.join(__dirname, 'fixtures/config'); var runner = require('gulp-test-tools').gulpRunner().basedir(fixturesDir); describe('config: flags.silent', function() { - it('Should be silent if `flags.silent` is true in .gulp.*', function(done) { runner @@ -37,7 +35,7 @@ describe('config: flags.silent', function() { function cb(err, stdout, stderr) { expect(err).toEqual(null); expect(stderr).toEqual(''); - stdout = eraseLapse(eraseTime(stripAnsi(skipLines(stdout, 1)))); + stdout = eraseLapse(eraseTime(skipLines(stdout, 1))); expect(stdout).toEqual( 'Starting \'default\'...\n' + 'Finished \'default\' after ?\n' + @@ -46,5 +44,4 @@ describe('config: flags.silent', function() { done(err); } }); - }); diff --git a/test/config-flags-sortTasks.js b/test/config-flags-sortTasks.js index 382ec744..8762fda4 100644 --- a/test/config-flags-sortTasks.js +++ b/test/config-flags-sortTasks.js @@ -5,16 +5,15 @@ var path = require('path'); var fs = require('fs'); var skipLines = require('gulp-test-tools').skipLines; var eraseTime = require('gulp-test-tools').eraseTime; -var stripAnsi = require('../lib/shared/ansi').strip; var fixturesDir = path.join(__dirname, 'fixtures/config'); var expectedDir = path.join(__dirname, 'expected'); -var runner = require('gulp-test-tools').gulpRunner().basedir(fixturesDir); +var runner = require('gulp-test-tools') + .gulpRunner() + .basedir(fixturesDir); -describe ('config: flags.sortTasks', function() { - - it('Should sort top tasks in task list when `flags.sortTasks` is true in ' + - '.gulp.*', function(done) { +describe('config: flags.sortTasks', function() { + it('Should sort top tasks in task list when `flags.sortTasks` is true in ' + '.gulp.*', function(done) { runner .chdir('flags/sortTasks/t') .gulp('--tasks') @@ -25,7 +24,7 @@ describe ('config: flags.sortTasks', function() { var expected = fs.readFileSync(filepath, 'utf-8'); expected = skipLines(expected, 1); - stdout = eraseTime(stripAnsi(skipLines(stdout, 1))); + stdout = eraseTime(skipLines(stdout, 1)); expect(stdout).toEqual(expected); expect(stderr).toEqual(''); @@ -33,8 +32,7 @@ describe ('config: flags.sortTasks', function() { } }); - it('Should sort top tasks in task list when `flags.sortTasks` is false in ' + - '.gulp.*', function(done) { + it('Should sort top tasks in task list when `flags.sortTasks` is false in ' + '.gulp.*', function(done) { runner .chdir('flags/sortTasks/f') .gulp('--tasks') @@ -45,12 +43,11 @@ describe ('config: flags.sortTasks', function() { var expected = fs.readFileSync(filepath, 'utf-8'); expected = skipLines(expected, 1); - stdout = eraseTime(stripAnsi(skipLines(stdout, 1))); + stdout = eraseTime(skipLines(stdout, 1)); expect(stdout).toEqual(expected); expect(stderr).toEqual(''); done(err); } }); - }); diff --git a/test/config-flags-tasksDepth.js b/test/config-flags-tasksDepth.js index 6701c6c1..3c9d687e 100644 --- a/test/config-flags-tasksDepth.js +++ b/test/config-flags-tasksDepth.js @@ -5,16 +5,15 @@ var path = require('path'); var fs = require('fs'); var skipLines = require('gulp-test-tools').skipLines; var eraseTime = require('gulp-test-tools').eraseTime; -var stripAnsi = require('../lib/shared/ansi').strip; var fixturesDir = path.join(__dirname, 'fixtures/config'); var expectedDir = path.join(__dirname, 'expected'); -var runner = require('gulp-test-tools').gulpRunner().basedir(fixturesDir); +var runner = require('gulp-test-tools') + .gulpRunner() + .basedir(fixturesDir); -describe ('config: flags.tasksDepth', function() { - - it('Should limit depth of task list when `flags.tasksDepth` is ' + - 'specified', function(done) { +describe('config: flags.tasksDepth', function() { + it('Should limit depth of task list when `flags.tasksDepth` is ' + 'specified', function(done) { runner .chdir('flags/tasksDepth') .gulp('--tasks') @@ -25,12 +24,11 @@ describe ('config: flags.tasksDepth', function() { var expected = fs.readFileSync(filepath, 'utf-8'); expected = skipLines(expected, 1); - stdout = eraseTime(stripAnsi(skipLines(stdout, 1))); + stdout = eraseTime(skipLines(stdout, 1)); expect(stdout).toEqual(expected); expect(stderr).toEqual(''); done(err); } }); - }); diff --git a/test/exports-as-tasks.js b/test/exports-as-tasks.js index e1974d04..2f922a94 100644 --- a/test/exports-as-tasks.js +++ b/test/exports-as-tasks.js @@ -6,7 +6,6 @@ var path = require('path'); var skipLines = require('gulp-test-tools').skipLines; var eraseTime = require('gulp-test-tools').eraseTime; var runner = require('gulp-test-tools').gulpRunner; -var stripAnsi = require('../lib/shared/ansi').strip; var expectedDir = path.join(__dirname, 'expected'); @@ -16,8 +15,7 @@ describe('exports as tasks', function() { it('prints the task list', function(done) { runner({ verbose: false }) - .gulp('--tasks', '--sort-tasks', - '--gulpfile ./test/fixtures/gulpfiles/gulpfile-exports.babel.js') + .gulp('--tasks', '--sort-tasks', '--gulpfile ./test/fixtures/gulpfiles/gulpfile-exports.babel.js') .run(cb); function cb(err, stdout, stderr) { @@ -25,10 +23,9 @@ describe('exports as tasks', function() { expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'tasks-as-exports.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - stdout = eraseTime(stripAnsi(skipLines(stdout, 2))); + stdout = eraseTime(skipLines(stdout, 2)); expect(stdout).toEqual(expected); done(err); } }); - }); diff --git a/test/flags-continue.js b/test/flags-continue.js index 7a4de485..b9774df7 100644 --- a/test/flags-continue.js +++ b/test/flags-continue.js @@ -6,10 +6,8 @@ var eraseTime = require('gulp-test-tools').eraseTime; var eraseLapse = require('gulp-test-tools').eraseLapse; var skipLines = require('gulp-test-tools').skipLines; var headLines = require('gulp-test-tools').headLines; -var stripAnsi = require('../lib/shared/ansi').strip; describe('flag: --continue', function() { - it('continues execution when flag is set', function(done) { runner({ verbose: false }) .gulp('test4', '--continue', '--cwd ./test/fixtures/gulpfiles') @@ -17,7 +15,7 @@ describe('flag: --continue', function() { function cb(err, stdout, stderr) { expect(err).toNotEqual(null); - stdout = eraseLapse(eraseTime(stripAnsi(skipLines(stdout, 2)))); + stdout = eraseLapse(eraseTime(skipLines(stdout, 2))); expect(stdout).toEqual( 'Starting \'test4\'...\n' + 'Starting \'errorFunction\'...\n' + @@ -26,8 +24,8 @@ describe('flag: --continue', function() { '' ); - stderr = eraseLapse(eraseTime(stripAnsi(headLines(stderr, 2)))); - expect(stripAnsi(stderr)).toEqual( + stderr = eraseLapse(eraseTime(headLines(stderr, 2))); + expect(stderr).toEqual( '\'errorFunction\' errored after ?\n' + 'Error: Error!' ); @@ -43,14 +41,14 @@ describe('flag: --continue', function() { function cb(err, stdout, stderr) { expect(err).toNotEqual(null); expect(stdout).toNotMatch('Starting \'anon\''); - stdout = eraseLapse(eraseTime(stripAnsi(skipLines(stdout, 2)))); + stdout = eraseLapse(eraseTime(skipLines(stdout, 2))); expect(stdout).toEqual( 'Starting \'test4\'...\n' + 'Starting \'errorFunction\'...\n' + '' ); - stderr = eraseLapse(eraseTime(stripAnsi(headLines(stderr, 2)))); + stderr = eraseLapse(eraseTime(headLines(stderr, 2))); expect(stderr).toEqual( '\'errorFunction\' errored after ?\n' + 'Error: Error!' @@ -58,5 +56,4 @@ describe('flag: --continue', function() { done(); } }); - }); diff --git a/test/flags-gulpfile.js b/test/flags-gulpfile.js index 2b87e134..8ae5e69a 100644 --- a/test/flags-gulpfile.js +++ b/test/flags-gulpfile.js @@ -7,10 +7,8 @@ var headLines = require('gulp-test-tools').headLines; var eraseTime = require('gulp-test-tools').eraseTime; var eraseLapse = require('gulp-test-tools').eraseLapse; var path = require('path'); -var stripAnsi = require('../lib/shared/ansi').strip; describe('flag: --gulpfile', function() { - it('Manually set path of gulpfile', function(done) { var gulpfilePath = 'test/fixtures/gulpfiles/gulpfile-2.js'; @@ -26,7 +24,7 @@ describe('flag: --gulpfile', function() { var workdir = path.dirname(gulpfilePath).replace(/\//g, path.sep); expect(chgWorkdirLog).toMatch('Working directory changed to '); expect(chgWorkdirLog).toMatch(workdir); - stdout = eraseLapse(eraseTime(stripAnsi(skipLines(stdout, 2)))); + stdout = eraseLapse(eraseTime(skipLines(stdout, 2))); expect(stdout).toEqual( 'Starting \'default\'...\n' + 'Starting \'logGulpfilePath\'...\n' + @@ -38,5 +36,4 @@ describe('flag: --gulpfile', function() { done(err); } }); - }); diff --git a/test/flags-help.js b/test/flags-help.js index 48e10844..8b2108b2 100644 --- a/test/flags-help.js +++ b/test/flags-help.js @@ -5,9 +5,8 @@ var runner = require('gulp-test-tools').gulpRunner; var path = require('path'); var fs = require('fs'); -var stripAnsi = require('../lib/shared/ansi').strip; -// Erases a first space inserted by `ansi-*`. +// Erases a first space inserted function eraseFirstSpace(s) { return s.replace(/^(\r\n|\n|\r)\s?/g, '\n'); } @@ -16,7 +15,6 @@ var outputFile = path.join(__dirname, 'expected/flags-help.txt'); var outputText = fs.readFileSync(outputFile, 'utf8'); describe('flag: --help', function() { - it('shows help using --help', function(done) { runner({ verbose: false }) .gulp('--help', '--cwd ./test/fixtures/gulpfiles') @@ -25,7 +23,7 @@ describe('flag: --help', function() { function cb(err, stdout, stderr) { expect(err).toEqual(null); expect(stderr).toEqual(''); - stdout = stripAnsi(eraseFirstSpace(stdout)); + stdout = eraseFirstSpace(stdout); expect(stdout).toEqual(outputText); done(err); } @@ -39,10 +37,9 @@ describe('flag: --help', function() { function cb(err, stdout, stderr) { expect(err).toEqual(null); expect(stderr).toEqual(''); - stdout = stripAnsi(eraseFirstSpace(stdout)); + stdout = eraseFirstSpace(stdout); expect(stdout).toEqual(outputText); done(err); } }); - }); diff --git a/test/flags-require.js b/test/flags-require.js index 2323b171..12f19f21 100644 --- a/test/flags-require.js +++ b/test/flags-require.js @@ -7,10 +7,8 @@ var headLines = require('gulp-test-tools').headLines; var eraseTime = require('gulp-test-tools').eraseTime; var eraseLapse = require('gulp-test-tools').eraseLapse; var path = require('path'); -var stripAnsi = require('../lib/shared/ansi').strip; describe('flag: --require', function() { - it('requires module before running gulpfile', function(done) { runner({ verbose: false }) .gulp('--require ../test-module.js', '--cwd ./test/fixtures/gulpfiles') @@ -22,7 +20,7 @@ describe('flag: --require', function() { var insideLog = headLines(stdout, 1); expect(insideLog).toEqual('inside test module'); - var requireLog = eraseTime(stripAnsi(headLines(stdout, 1, 1))); + var requireLog = eraseTime(headLines(stdout, 1, 1)); expect(requireLog).toEqual( 'Requiring external module ../test-module.js'); @@ -31,7 +29,7 @@ describe('flag: --require', function() { expect(chgWorkdirLog).toMatch('Working directory changed to '); expect(chgWorkdirLog).toMatch(workdir); - stdout = eraseLapse(eraseTime(stripAnsi(skipLines(stdout, 4)))); + stdout = eraseLapse(eraseTime(skipLines(stdout, 4))); expect(stdout).toEqual( 'Starting \'default\'...\n' + 'Starting \'test1\'...\n' + @@ -58,7 +56,7 @@ describe('flag: --require', function() { function cb(err, stdout, stderr) { expect(err).toEqual(null); - stderr = eraseLapse(eraseTime(stripAnsi(stderr))); + stderr = eraseLapse(eraseTime(stderr)); expect(stderr).toMatch('Failed to load external module ./null-module.js'); expect(stdout).toNotMatch('inside test module'); expect(stdout).toNotMatch( @@ -69,7 +67,7 @@ describe('flag: --require', function() { expect(chgWorkdirLog).toMatch('Working directory changed to '); expect(chgWorkdirLog).toMatch(workdir); - stdout = eraseLapse(eraseTime(stripAnsi(skipLines(stdout, 2)))); + stdout = eraseLapse(eraseTime(skipLines(stdout, 2))); expect(stdout).toEqual( 'Starting \'default\'...\n' + 'Starting \'test1\'...\n' + @@ -92,5 +90,4 @@ describe('flag: --require', function() { done(err); } }); - }); diff --git a/test/flags-tasks.js b/test/flags-tasks.js index 7864b80e..afae45af 100644 --- a/test/flags-tasks.js +++ b/test/flags-tasks.js @@ -6,12 +6,10 @@ var path = require('path'); var skipLines = require('gulp-test-tools').skipLines; var eraseTime = require('gulp-test-tools').eraseTime; var runner = require('gulp-test-tools').gulpRunner; -var stripAnsi = require('../lib/shared/ansi').strip; var expectedDir = path.join(__dirname, 'expected'); describe('flag: --tasks', function() { - it('prints the task list', function(done) { runner({ verbose: false }) .gulp('--tasks --sort-tasks --cwd ./test/fixtures/gulpfiles') @@ -22,7 +20,7 @@ describe('flag: --tasks', function() { expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - stdout = eraseTime(stripAnsi(skipLines(stdout, 1))); + stdout = eraseTime(skipLines(stdout, 1)); expect(stdout).toEqual(expected); done(err); } @@ -30,9 +28,12 @@ describe('flag: --tasks', function() { it('print the task list with description and flags', function(done) { runner({ verbose: false }) - .gulp('--tasks', '--sort-tasks', + .gulp( + '--tasks', + '--sort-tasks', '--gulpfile ./test/fixtures/gulpfiles/with-desc-and-flags.js', - '--cwd ./test/fixtures') + '--cwd ./test/fixtures' + ) .run(cb); function cb(err, stdout, stderr) { @@ -40,18 +41,20 @@ describe('flag: --tasks', function() { expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'with-desc-and-flags.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - stdout = eraseTime(stripAnsi(skipLines(stdout, 1))); + stdout = eraseTime(skipLines(stdout, 1)); expect(stdout).toEqual(expected); done(err); } }); - it('print the task list by gulp.task(s).unwrap and gulp.task(s)', - function(done) { + it('print the task list by gulp.task(s).unwrap and gulp.task(s)', function(done) { runner({ verbose: false }) - .gulp('--tasks', '--sort-tasks', + .gulp( + '--tasks', + '--sort-tasks', '--gulpfile ./test/fixtures/gulpfiles/by-unwrap-and-not-by-unwrap.js', - '--cwd ./test/fixtures') + '--cwd ./test/fixtures' + ) .run(cb); function cb(err, stdout, stderr) { @@ -59,7 +62,7 @@ describe('flag: --tasks', function() { expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'by-unwrap-and-not-by-unwrap.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - stdout = eraseTime(stripAnsi(skipLines(stdout, 1))); + stdout = eraseTime(skipLines(stdout, 1)); expect(stdout).toEqual(expected); done(err); } @@ -75,7 +78,7 @@ describe('flag: --tasks', function() { expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks-unsorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - stdout = eraseTime(stripAnsi(skipLines(stdout, 1))); + stdout = eraseTime(skipLines(stdout, 1)); expect(stdout).toEqual(expected); done(err); } @@ -83,8 +86,7 @@ describe('flag: --tasks', function() { it('prints the task list with --sort-tasks flag', function(done) { runner({ verbose: false }) - .gulp('--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', - '--sort-tasks') + .gulp('--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', '--sort-tasks') .run(cb); function cb(err, stdout, stderr) { @@ -92,7 +94,7 @@ describe('flag: --tasks', function() { expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks-sorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - stdout = eraseTime(stripAnsi(skipLines(stdout, 1))); + stdout = eraseTime(skipLines(stdout, 1)); expect(stdout).toEqual(expected); done(err); } @@ -100,8 +102,7 @@ describe('flag: --tasks', function() { it('prints the task list with --tasks-depth flag', function(done) { runner({ verbose: false }) - .gulp('--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', - '--tasks-depth 4') + .gulp('--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', '--tasks-depth 4') .run(cb); function cb(err, stdout, stderr) { @@ -109,7 +110,7 @@ describe('flag: --tasks', function() { expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks-depth4.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - stdout = eraseTime(stripAnsi(skipLines(stdout, 1))); + stdout = eraseTime(skipLines(stdout, 1)); expect(stdout).toEqual(expected); done(err); } @@ -117,8 +118,7 @@ describe('flag: --tasks', function() { it('prints the task list with --depth flag', function(done) { runner({ verbose: false }) - .gulp('--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', - '--depth 4') + .gulp('--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', '--depth 4') .run(cb); function cb(err, stdout, stderr) { @@ -126,7 +126,7 @@ describe('flag: --tasks', function() { expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks-depth4.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - stdout = eraseTime(stripAnsi(skipLines(stdout, 1))); + stdout = eraseTime(skipLines(stdout, 1)); expect(stdout).toEqual(expected); done(err); } @@ -134,8 +134,7 @@ describe('flag: --tasks', function() { it('prints the task list with --compact-tasks flag', function(done) { runner({ verbose: false }) - .gulp('--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', - '--compact-tasks') + .gulp('--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', '--compact-tasks') .run(cb); function cb(err, stdout, stderr) { @@ -143,10 +142,9 @@ describe('flag: --tasks', function() { expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks-compact.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - stdout = eraseTime(stripAnsi(skipLines(stdout, 1))); + stdout = eraseTime(skipLines(stdout, 1)); expect(stdout).toEqual(expected); done(err); } }); - }); diff --git a/test/flags-verify.js b/test/flags-verify.js index db4c1d86..7f5deb66 100644 --- a/test/flags-verify.js +++ b/test/flags-verify.js @@ -4,10 +4,8 @@ var expect = require('expect'); var runner = require('gulp-test-tools').gulpRunner; var eraseTime = require('gulp-test-tools').eraseTime; var path = require('path'); -var stripAnsi = require('../lib/shared/ansi').strip; describe('flag: --verify', function() { - it('dependencies with invalid dependency', function(done) { runner({ verbose: false }) .gulp('--verify invalid-package.json', '--cwd ./test/fixtures/packages/') @@ -16,14 +14,14 @@ describe('flag: --verify', function() { function cb(err, stdout, stderr) { expect(err).toNotEqual(null); expect(stderr).toEqual(''); - stdout = eraseTime(stripAnsi(stdout)); + stdout = eraseTime(stdout); expect(stdout).toEqual( 'Verifying plugins in ' + path.resolve('./test/fixtures/packages/invalid-package.json') + '\n' + - 'Blacklisted plugins found in this project:\n' + - 'gulp-blink: deprecated. use `blink` instead.\n' + - '' + 'Blacklisted plugins found in this project:\n' + + 'gulp-blink: deprecated. use `blink` instead.\n' + + '' ); done(); } @@ -37,13 +35,13 @@ describe('flag: --verify', function() { function cb(err, stdout, stderr) { expect(err).toEqual(null); expect(stderr).toEqual(''); - stdout = eraseTime(stripAnsi(stdout)); + stdout = eraseTime(stdout); expect(stdout).toEqual( 'Verifying plugins in ' + path.resolve('./test/fixtures/packages/valid-package.json') + '\n' + - 'There are no blacklisted plugins in this project\n' + - '' + 'There are no blacklisted plugins in this project\n' + + '' ); done(err); } @@ -57,16 +55,16 @@ describe('flag: --verify', function() { function cb(err, stdout, stderr) { expect(err).toNotEqual(null); expect(stderr).toEqual(''); - stdout = eraseTime(stripAnsi(stdout)); + stdout = eraseTime(stdout); expect(stdout).toEqual( 'Verifying plugins in ' + - path.resolve('./test/fixtures/packages/package.json') + '\n' + - 'Blacklisted plugins found in this project:\n' + - 'gulp-blink: deprecated. use `blink` instead.\n' + - '' + path.resolve('./test/fixtures/packages/package.json') + + '\n' + + 'Blacklisted plugins found in this project:\n' + + 'gulp-blink: deprecated. use `blink` instead.\n' + + '' ); done(); } }); - }); From a670b586457bf31ad79ebee24e6eb1839aaafc0e Mon Sep 17 00:00:00 2001 From: tim Date: Tue, 26 Sep 2017 19:34:39 +0200 Subject: [PATCH 8/8] revert fixture changes --- test/fixtures/packages/invalid-package.json | 42 ++++++++++----------- test/fixtures/packages/valid-package.json | 42 ++++++++++----------- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/test/fixtures/packages/invalid-package.json b/test/fixtures/packages/invalid-package.json index 4f99a0f2..29a15016 100644 --- a/test/fixtures/packages/invalid-package.json +++ b/test/fixtures/packages/invalid-package.json @@ -1,21 +1,21 @@ -{ - "name": "test-package", - "description": "Test Package for Testing!", - "version": "0.0.1", - "tags": [ - ], - "files": [ - ], - "dependencies": { - "gulp-blink": "^0.1.4" - }, - "engines": { - "node": ">= 0.9" - }, - "licenses": [ - { - "type": "MIT", - "url": "https://raw.githubusercontent.com/gulpjs/gulp/master/LICENSE" - } - ] -} +{ + "name": "test-package", + "description": "Test Package for Testing!", + "version": "0.0.1", + "tags": [ + ], + "files": [ + ], + "dependencies": { + "gulp-blink": "^0.1.4" + }, + "engines": { + "node": ">= 0.9" + }, + "licenses": [ + { + "type": "MIT", + "url": "https://raw.githubusercontent.com/gulpjs/gulp/master/LICENSE" + } + ] +} diff --git a/test/fixtures/packages/valid-package.json b/test/fixtures/packages/valid-package.json index be2d488c..b9d30e04 100644 --- a/test/fixtures/packages/valid-package.json +++ b/test/fixtures/packages/valid-package.json @@ -1,21 +1,21 @@ -{ - "name": "test-package-2", - "description": "Test Package for Testing!", - "version": "0.0.1", - "tags": [ - ], - "files": [ - ], - "dependencies": { - "yargs": "^3.27.0" - }, - "engines": { - "node": ">= 0.9" - }, - "licenses": [ - { - "type": "MIT", - "url": "https://raw.githubusercontent.com/gulpjs/gulp/master/LICENSE" - } - ] -} +{ + "name": "test-package-2", + "description": "Test Package for Testing!", + "version": "0.0.1", + "tags": [ + ], + "files": [ + ], + "dependencies": { + "yargs": "^3.27.0" + }, + "engines": { + "node": ">= 0.9" + }, + "licenses": [ + { + "type": "MIT", + "url": "https://raw.githubusercontent.com/gulpjs/gulp/master/LICENSE" + } + ] +}