diff --git a/.editorconfig b/.editorconfig index aaa39996..e7b73a7a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,18 +1,13 @@ -# EditorConfig is Awesome: http://editorconfig.org - -# Top-most EditorConfig file. +# https://editorconfig.org root = true -# Unix-style newlines with a newline ending every file. [*] -end_of_line = lf -insert_final_newline = true -charset = utf-8 indent_style = space indent_size = 2 +charset = utf-8 trim_trailing_whitespace = true +insert_final_newline = true +end_of_line = lf -# Don't trim whitespace in Markdown in order to be able -# to do two spaces for line breaks. [*.md] trim_trailing_whitespace = false diff --git a/.eslintrc b/.eslintrc index ea9ec781..331ecbe0 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,7 +1,7 @@ { "extends": "gulp", "rules": { - "max-len": [1, 90], + "max-len": [1, 130], "max-statements": [1, 40], "no-console": "off" } diff --git a/.github/support.yml b/.github/support.yml deleted file mode 100644 index 3ee3d22c..00000000 --- a/.github/support.yml +++ /dev/null @@ -1,2 +0,0 @@ -# Configuration for support-requests - https://github.com/dessant/support-requests -_extends: gulp diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml new file mode 100644 index 00000000..90a12261 --- /dev/null +++ b/.github/workflows/dev.yml @@ -0,0 +1,86 @@ +name: dev +on: + pull_request: + push: + branches: + - master + - main +env: + CI: true + +jobs: + prettier: + name: Format code + runs-on: ubuntu-latest + if: ${{ github.event_name == 'push' }} + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Prettier + uses: gulpjs/prettier_action@v3.0 + with: + commit_message: 'chore: Run prettier' + prettier_options: '--write .' + + test: + name: Tests for Node ${{ matrix.node }} on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + + strategy: + fail-fast: false + matrix: + node: [10, 12, 14, 16, 18] + os: [ubuntu-latest, windows-latest, macos-latest] + + steps: + - name: Clone repository + uses: actions/checkout@v2 + + - name: Set Node.js version + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node }} + + - run: node --version + - run: npm --version + + - name: Install npm dependencies + run: npm install + + - name: Run lint + run: npm run lint + + - name: Run tests + # Run test without coverage because a behavior about esm is different with nyc or not + run: npm test + + coveralls: + needs: test + name: Finish up + + runs-on: ubuntu-latest + steps: + - name: Clone repository + uses: actions/checkout@v2 + + - name: Set Node.js version + uses: actions/setup-node@v2 + with: + # Coverage with LTS version + node-version: 18 + + - run: node --version + - run: npm --version + + - name: Install npm dependencies + run: npm install + + - name: Run coverage + run: npm run cover + + - name: Coveralls + uses: coverallsapp/github-action@v1.1.2 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..87cd13c0 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,16 @@ +name: release +on: + push: + branches: + - master + - main + +jobs: + release-please: + runs-on: ubuntu-latest + steps: + - uses: GoogleCloudPlatform/release-please-action@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + release-type: node + package-name: release-please-action diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..c96ebe0c --- /dev/null +++ b/.prettierignore @@ -0,0 +1,3 @@ +coverage/ +.nyc_output/ +CHANGELOG.md diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 25fc79b7..00000000 --- a/.travis.yml +++ /dev/null @@ -1,21 +0,0 @@ -sudo: false -language: node_js -node_js: - - "14" - - "12" - - "10" - - "8" - - "6" - - "4" - - "0.12" - - "0.10" -after_script: - - if [ $(echo "${TRAVIS_NODE_VERSION}" | cut -d'.' -f1) -ge 6 ]; then - npm run coveralls; - fi - -git: - depth: 10 -os: - - linux - - osx diff --git a/LICENSE b/LICENSE index 9aedc0d7..6443cad0 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015 Blaine Bublitz, Eric Schoffstall and other contributors +Copyright (c) 2015, 2017-2020, 2022-2023 Blaine Bublitz and Eric Schoffstall Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 6c4249e9..71f4d7a7 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@

- +

# gulp-cli -[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![AppVeyor Build Status][appveyor-image]][appveyor-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Gitter chat][gitter-image]][gitter-url] +[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][ci-image]][ci-url] [![Coveralls Status][coveralls-image]][coveralls-url] Command Line Utility for Gulp @@ -91,15 +91,15 @@ Add `gulp --completion=fish | source` to `~/.config/fish/config.fish`. ## Compilers -You can find a list of supported languages at https://github.com/js-cli/js-interpret. If you would like to add support for a new language, send pull requests/open issues on that project. +You can find a list of supported languages at https://github.com/gulpjs/interpret. If you would like to add support for a new language, send pull requests/open issues on that project. ## Environment -The CLI adds process.env.INIT_CWD which is the original cwd it was launched from. +The CLI adds `process.env.INIT_CWD` which is the original cwd it was launched from. ## Configuration -Configuration is supported through the use of a `.gulp.*` file (e.g. `.gulp.json`, `.gulp.yml`). You can find a list of supported languages at https://github.com/js-cli/js-interpret. +Configuration is supported through the use of a `.gulp.*` file (e.g. `.gulp.json`, `.gulp.yml`). You can find a list of supported languages at https://github.com/gulpjs/interpret. Configuration from the home directory (`~`) and current working directory (`cwd`) are merged with `cwd` taking precedence. @@ -114,7 +114,7 @@ Supported configurations properties: | flags.gulpfile | Set a default gulpfile | | flags.silent | Silence logging by default | | flags.series | Run tasks given on the CLI in series (the default is parallel) | -| flags.require | An array of modules to require before running the gulpfile. Any relative paths will be resolved against the `--cwd` directory (if you don't want that behavior, use absolute paths) | +| flags.preload | An array of modules to preload before running the gulpfile. Any relative paths will be resolved against the `--cwd` directory (if you don't want that behavior, use absolute paths) | | flags.nodeFlags | An array of flags used to forcibly respawn the process upon startup. For example, if you always want your gulpfiles to run in node's harmony mode, you can set `--harmony` here | ## Flags @@ -143,9 +143,9 @@ __Some flags only work with gulp 4 and will be ignored when invoked against gulp Print the global and local gulp versions. - --require [path] + --preload [path] - Will require a module before running the gulpfile. This is useful for transpilers but also has other applications. + Will preload a module before running the gulpfile. This is useful for transpilers but also has other applications. --gulpfile [path] @@ -155,7 +155,7 @@ __Some flags only work with gulp 4 and will be ignored when invoked against gulp --cwd [path] - Manually set the CWD. The search for the gulpfile, as well as the relativity of all requires (including the `--require` flag) will be from here. + Manually set the CWD. The search for the gulpfile, as well as the relativity of all preloads (with the `--preload` flag) will be from here. --verify [path (optional)] @@ -229,18 +229,15 @@ __Some flags only work with gulp 4 and will be ignored when invoked against gulp MIT -[downloads-image]: http://img.shields.io/npm/dm/gulp-cli.svg -[npm-url]: https://www.npmjs.com/package/gulp-cli -[npm-image]: http://img.shields.io/npm/v/gulp-cli.svg -[travis-url]: https://travis-ci.org/gulpjs/gulp-cli -[travis-image]: http://img.shields.io/travis/gulpjs/gulp-cli.svg?label=travis-ci + +[downloads-image]: https://img.shields.io/npm/dm/gulp-cli.svg?style=flat-square +[npm-url]: https://www.npmjs.com/package/gulp-cli +[npm-image]: https://img.shields.io/npm/v/gulp-cli.svg?style=flat-square -[appveyor-url]: https://ci.appveyor.com/project/gulpjs/gulp-cli -[appveyor-image]: https://img.shields.io/appveyor/ci/gulpjs/gulp-cli.svg?label=appveyor +[ci-url]: https://github.com/gulpjs/gulp-cli/actions?query=workflow:dev +[ci-image]: https://img.shields.io/github/actions/workflow/status/gulpjs/gulp-cli/dev.yml?branch=master&style=flat-square [coveralls-url]: https://coveralls.io/r/gulpjs/gulp-cli -[coveralls-image]: http://img.shields.io/coveralls/gulpjs/gulp-cli/master.svg - -[gitter-url]: https://gitter.im/gulpjs/gulp -[gitter-image]: https://badges.gitter.im/gulpjs/gulp.svg +[coveralls-image]: https://img.shields.io/coveralls/gulpjs/gulp-cli.svg?style=flat-square + diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 32e31abb..00000000 --- a/appveyor.yml +++ /dev/null @@ -1,29 +0,0 @@ -# http://www.appveyor.com/docs/appveyor-yml -# http://www.appveyor.com/docs/lang/nodejs-iojs - -environment: - matrix: - # node.js - - nodejs_version: "0.10" - - nodejs_version: "0.12" - - nodejs_version: "4" - - nodejs_version: "6" - - nodejs_version: "8" - - nodejs_version: "10" - - nodejs_version: "12" - - nodejs_version: "14" - -install: - - npm install -g npm@^3 - - ps: Install-Product node $env:nodejs_version - - npm install - -test_script: - - node --version - - npm --version - - cmd: npm test - -build: off - -# build version format -version: "{build}" diff --git a/index.js b/index.js index 258c86ac..9e5f43b6 100644 --- a/index.js +++ b/index.js @@ -3,25 +3,24 @@ var fs = require('fs'); var path = require('path'); var log = require('gulplog'); -var yargs = require('yargs'); + var Liftoff = require('liftoff'); var interpret = require('interpret'); var v8flags = require('v8flags'); var findRange = require('semver-greatest-satisfied-range'); -var ansi = require('./lib/shared/ansi'); +var chalk = require('chalk'); var exit = require('./lib/shared/exit'); var tildify = require('./lib/shared/tildify'); var makeTitle = require('./lib/shared/make-title'); -var cliOptions = require('./lib/shared/cli-options'); +var parser = require('./lib/shared/options/parser'); var completion = require('./lib/shared/completion'); var verifyDeps = require('./lib/shared/verify-dependencies'); var cliVersion = require('./package.json').version; -var getBlacklist = require('./lib/shared/get-blacklist'); +var getBlacklist = require('./lib/shared/blacklist'); var toConsole = require('./lib/shared/log/to-console'); -var loadConfigFiles = require('./lib/shared/config/load-files'); -var mergeConfigToCliFlags = require('./lib/shared/config/cli-flags'); -var mergeConfigToEnvFlags = require('./lib/shared/config/env-flags'); +var mergeProjectAndUserHomeConfigs = require('./lib/shared/config/merge-configs'); +var overrideEnvFlagsByConfigAndCliOpts = require('./lib/shared/config/env-flags'); // Logging functions var logVerify = require('./lib/shared/log/verify'); @@ -41,49 +40,69 @@ var cli = new Liftoff({ extensions: interpret.jsVariants, v8flags: v8flags, configFiles: { - '.gulp': { - home: { - path: '~', + project: [ + { + name: '.gulp', + path: '.', extensions: interpret.extensions, + findUp: true, }, - cwd: { - path: '.', + ], + userHome: [ + { + name: '.gulp', + path: '~', extensions: interpret.extensions, }, - }, + ], }, }); -var usage = - '\n' + ansi.bold('Usage:') + - ' gulp ' + ansi.blue('[options]') + ' tasks'; - -var parser = yargs.usage(usage, cliOptions); var opts = parser.argv; -cli.on('require', function(name) { +cli.on('preload:before', function(name) { + log.info('Preloading external module:', chalk.magenta(name)); +}); + +cli.on('preload:success', function(name) { + log.info('Preloaded external module:', chalk.magenta(name)); +}); + +cli.on('preload:failure', function(name, error) { + log.warn( + chalk.yellow('Failed to preload external module:'), + chalk.magenta(name) + ); + /* istanbul ignore else */ + if (error) { + log.warn(chalk.yellow(error.toString())); + } +}); + +cli.on('loader:success', function(name) { // This is needed because interpret needs to stub the .mjs extension // Without the .mjs require hook, rechoir blows up // However, we don't want to show the mjs-stub loader in the logs + /* istanbul ignore else */ if (path.basename(name, '.js') !== 'mjs-stub') { - log.info('Requiring external module', ansi.magenta(name)); + log.info('Loaded external module:', chalk.magenta(name)); } }); -cli.on('requireFail', function(name, error) { +cli.on('loader:failure', function(name, error) { log.warn( - ansi.yellow('Failed to load external module'), - ansi.magenta(name) + chalk.yellow('Failed to load external module:'), + chalk.magenta(name) ); /* istanbul ignore else */ if (error) { - log.warn(ansi.yellow(error.toString())); + log.warn(chalk.yellow(error.toString())); } }); cli.on('respawn', function(flags, child) { - var nodeFlags = ansi.magenta(flags.join(', ')); - var pid = ansi.magenta(child.pid); + var nodeFlags = chalk.magenta(flags.join(', ')); + var pid = chalk.magenta(child.pid); log.info('Node flags detected:', nodeFlags); log.info('Respawned to PID:', pid); }); @@ -92,49 +111,47 @@ function run() { cli.prepare({ cwd: opts.cwd, configPath: opts.gulpfile, - require: opts.require, + preload: opts.preload, completion: opts.completion, - }, function(env) { - var cfgLoadOrder = ['home', 'cwd']; - var cfg = loadConfigFiles(env.configFiles['.gulp'], cfgLoadOrder); - opts = mergeConfigToCliFlags(opts, cfg); - env = mergeConfigToEnvFlags(env, cfg, opts); - env.configProps = cfg; - - // Set up event listeners for logging again after configuring. - toConsole(log, opts); - - cli.execute(env, env.nodeFlags, handleArguments); - }); + }, onPrepare); } module.exports = run; -// The actual logic -function handleArguments(env) { +function onPrepare(env) { + var cfg = mergeProjectAndUserHomeConfigs(env); + env = overrideEnvFlagsByConfigAndCliOpts(env, cfg, opts); + + // Set up event listeners for logging again after configuring. + toConsole(log, env.config.flags); + cli.execute(env, env.nodeFlags, onExecute); +} + +// The actual logic +function onExecute(env) { // This translates the --continue flag in gulp // To the settle env variable for undertaker // We use the process.env so the user's gulpfile // Can know about the flag - if (opts.continue) { + if (env.config.flags.continue) { process.env.UNDERTAKER_SETTLE = 'true'; } - if (opts.help) { + if (env.config.flags.help) { parser.showHelp(console.log); exit(0); } // Anything that needs to print outside of the logging mechanism should use console.log - if (opts.version) { + if (env.config.flags.version) { console.log('CLI version:', cliVersion); console.log('Local version:', env.modulePackage.version || 'Unknown'); exit(0); } - if (opts.verify) { - var pkgPath = opts.verify !== true ? opts.verify : 'package.json'; + if (env.config.flags.verify) { + var pkgPath = env.config.flags.verify !== true ? env.config.flags.verify : 'package.json'; /* istanbul ignore else */ if (path.resolve(pkgPath) !== path.normalize(pkgPath)) { pkgPath = path.join(env.cwd, pkgPath); @@ -164,8 +181,8 @@ function handleArguments(env) { ? 'Local modules not found in' : 'Local gulp not found in'; log.error( - ansi.red(missingGulpMessage), - ansi.magenta(tildify(env.cwd)) + chalk.red(missingGulpMessage), + chalk.magenta(tildify(env.cwd)) ); var hasYarn = fs.existsSync(path.join(env.cwd, 'yarn.lock')); /* istanbul ignore next */ @@ -177,12 +194,12 @@ function handleArguments(env) { : hasYarn ? 'yarn add gulp' : 'npm install gulp'; - log.error(ansi.red('Try running: ' + installCommand)); + log.error(chalk.red('Try running: ' + installCommand)); exit(1); } if (!env.configPath) { - log.error(ansi.red('No gulpfile found')); + log.error(chalk.red('No gulpfile found')); exit(1); } @@ -192,7 +209,7 @@ function handleArguments(env) { process.chdir(env.cwd); log.info( 'Working directory changed to', - ansi.magenta(tildify(env.cwd)) + chalk.magenta(tildify(env.cwd)) ); } @@ -201,12 +218,12 @@ function handleArguments(env) { if (!range) { log.error( - ansi.red('Unsupported gulp version', env.modulePackage.version) + chalk.red('Unsupported gulp version', env.modulePackage.version) ); exit(1); } // Load and execute the CLI version var versionedDir = path.join(__dirname, '/lib/versioned/', range, '/'); - require(versionedDir)(opts, env, env.configProps); + require(versionedDir)(env); } diff --git a/lib/shared/ansi.js b/lib/shared/ansi.js deleted file mode 100644 index d5030fa0..00000000 --- a/lib/shared/ansi.js +++ /dev/null @@ -1,41 +0,0 @@ -'use strict'; - -var colors = require('ansi-colors'); -var supportsColor = require('color-support'); - -var hasColors = colorize(); - -/* istanbul ignore next */ -module.exports = { - red: hasColors ? colors.red : noColor, - green: hasColors ? colors.green : noColor, - blue: hasColors ? colors.blue : noColor, - magenta: hasColors ? colors.magenta : noColor, - cyan: hasColors ? colors.cyan : noColor, - white: hasColors ? colors.white : noColor, - gray: hasColors ? colors.gray : noColor, - bgred: hasColors ? colors.bgred : noColor, - bold: hasColors ? colors.bold : noColor, - yellow: hasColors ? colors.yellow : noColor, -}; - -function noColor(message) { - return message; -} - -function hasFlag(flag) { - return (process.argv.indexOf('--' + flag) !== -1); -} - -function colorize() { - if (hasFlag('no-color')) { - return false; - } - - /* istanbul ignore if */ - if (hasFlag('color')) { - return true; - } - - return supportsColor(); -} diff --git a/lib/shared/blacklist/get-remote-json.js b/lib/shared/blacklist/get-remote-json.js new file mode 100644 index 00000000..f5a21b68 --- /dev/null +++ b/lib/shared/blacklist/get-remote-json.js @@ -0,0 +1,39 @@ +'use strict'; + +var https = require('https'); + +function getRemoteJson(url, cb) { + var chunks = []; + + https.get(url, onRequest).on('error', onError);; + + function onRequest(res) { + if (res.statusCode !== 200) { + res.resume(); // Consume response data to free up memory + return cb(new Error('Request failed. Status Code: ' + res.statusCode)); + } + + res.on('error', onError); + res.on('data', onDrain); + res.on('end', onEnd); + } + + /* istanbul ignore next */ + function onError(e) { + cb(e, null); + } + + function onDrain(d) { + chunks.push(d); + } + + function onEnd() { + try { + cb(null, JSON.parse(Buffer.concat(chunks).toString('utf8'))); + } catch (err) { + cb(new Error('Invalid Blacklist JSON.')); + } + } +} + +module.exports = getRemoteJson; diff --git a/lib/shared/blacklist/index.js b/lib/shared/blacklist/index.js new file mode 100644 index 00000000..edf66fa1 --- /dev/null +++ b/lib/shared/blacklist/index.js @@ -0,0 +1,11 @@ +'use strict'; + +var getRemoteJson = require('./get-remote-json'); + +var url = 'https://raw.githubusercontent.com/gulpjs/plugins/master/src/blackList.json'; + +function getBlacklist(cb) { + getRemoteJson(url, cb); +} + +module.exports = getBlacklist; diff --git a/lib/shared/config/cli-flags.js b/lib/shared/config/cli-flags.js index 1baf38d0..996aaa6b 100644 --- a/lib/shared/config/cli-flags.js +++ b/lib/shared/config/cli-flags.js @@ -2,7 +2,7 @@ var copyProps = require('copy-props'); -var fromTo = { +var fromConfigToCliOpts = { 'flags.silent': 'silent', 'flags.continue': 'continue', 'flags.series': 'series', @@ -12,8 +12,9 @@ var fromTo = { 'flags.sortTasks': 'sortTasks', }; -function mergeConfigToCliFlags(opt, config) { - return copyProps(config, opt, fromTo, defaults); +function mergeCliOpts(opts, config) { + opts = copyProps(opts, {}); + return copyProps(config, opts, fromConfigToCliOpts, defaults); } function defaults(cfgInfo, optInfo) { @@ -22,4 +23,4 @@ function defaults(cfgInfo, optInfo) { } } -module.exports = mergeConfigToCliFlags; +module.exports = mergeCliOpts; diff --git a/lib/shared/config/env-flags.js b/lib/shared/config/env-flags.js index a5a4abd7..59b4d4be 100644 --- a/lib/shared/config/env-flags.js +++ b/lib/shared/config/env-flags.js @@ -3,17 +3,29 @@ var path = require('path'); var copyProps = require('copy-props'); -var toFrom = { +var mergeCliOpts = require('./cli-flags'); + +var toEnvFromConfig = { configPath: 'flags.gulpfile', configBase: 'flags.gulpfile', - require: 'flags.require', + preload: 'flags.preload', nodeFlags: 'flags.nodeFlags', }; -function mergeConfigToEnvFlags(env, config, cliOpts) { +function overrideEnvFlags(env, config, cliOpts) { + cliOpts = mergeCliOpts(cliOpts, config); + // This must reverse because `flags.gulpfile` determines 2 different properties var reverse = true; - return copyProps(env, config, toFrom, convert, reverse); + env = copyProps(env, config, toEnvFromConfig, convert, reverse); + + env.config = { + flags: cliOpts, + }; + if (config.description) { + env.config.description = config.description; + } + return env function convert(configInfo, envInfo) { if (envInfo.keyChain === 'configBase') { @@ -30,7 +42,7 @@ function mergeConfigToEnvFlags(env, config, cliOpts) { return; } - if (envInfo.keyChain === 'require') { + if (envInfo.keyChain === 'preload') { return [].concat(envInfo.value, configInfo.value); } @@ -41,4 +53,4 @@ function mergeConfigToEnvFlags(env, config, cliOpts) { } } -module.exports = mergeConfigToEnvFlags; +module.exports = overrideEnvFlags; diff --git a/lib/shared/config/load-files.js b/lib/shared/config/load-files.js deleted file mode 100644 index 4ebb29cb..00000000 --- a/lib/shared/config/load-files.js +++ /dev/null @@ -1,30 +0,0 @@ -'use strict'; - -var copyProps = require('copy-props'); -var path = require('path'); - -function loadConfigFiles(configFiles, configFileOrder) { - var config = {}; - - configFileOrder.forEach(loadFile); - - function loadFile(key) { - var filePath = configFiles[key]; - if (!filePath) { - return; - } - - copyProps(require(filePath), config, convert); - - function convert(loadedInfo) { - if (loadedInfo.keyChain === 'flags.gulpfile') { - return path.resolve(path.dirname(filePath), loadedInfo.value); - } - return loadedInfo.value; - } - } - - return config; -} - -module.exports = loadConfigFiles; diff --git a/lib/shared/config/merge-configs.js b/lib/shared/config/merge-configs.js new file mode 100644 index 00000000..8202f182 --- /dev/null +++ b/lib/shared/config/merge-configs.js @@ -0,0 +1,28 @@ +'use strict'; + +var copyProps = require('copy-props'); +var path = require('path'); + +function mergeConfigs(env) { + var cfg = {}; + if (env.configFiles.userHome) { + copyConfig(env.config.userHome, cfg, env.configFiles.userHome); + } + if (env.configFiles.project) { + copyConfig(env.config.project, cfg, env.configFiles.project); + } + return cfg; +} + +function copyConfig(src, dest, filePath) { + return copyProps(src, dest, convert); + + function convert(loadedInfo) { + if (loadedInfo.keyChain === 'flags.gulpfile') { + return path.resolve(path.dirname(filePath), loadedInfo.value); + } + return loadedInfo.value; + } +} + +module.exports = mergeConfigs; diff --git a/lib/shared/get-blacklist.js b/lib/shared/get-blacklist.js deleted file mode 100644 index 4cc16d45..00000000 --- a/lib/shared/get-blacklist.js +++ /dev/null @@ -1,62 +0,0 @@ -'use strict'; - -var https = require('https'); - -var concat = require('concat-stream'); - -var url = 'https://raw.githubusercontent.com/gulpjs/plugins/master/src/blackList.json'; - -function collect(stream, cb) { - stream.on('error', cb); - stream.pipe(concat(onSuccess)); - - function onSuccess(result) { - cb(null, result); - } -} - -function parse(str, cb) { - try { - cb(null, JSON.parse(str)); - } catch (err) { - /* istanbul ignore next */ - cb(new Error('Invalid Blacklist JSON.')); - } -} - -// TODO: Test this impl -function getBlacklist(cb) { - https.get(url, onRequest); - - function onRequest(res) { - /* istanbul ignore if */ - if (res.statusCode !== 200) { - // TODO: Test different status codes - return cb(new Error('Request failed. Status Code: ' + res.statusCode)); - } - - res.setEncoding('utf8'); - - collect(res, onCollect); - } - - function onCollect(err, result) { - /* istanbul ignore if */ - if (err) { - return cb(err); - } - - parse(result, onParse); - } - - function onParse(err, blacklist) { - /* istanbul ignore if */ - if (err) { - return cb(err); - } - - cb(null, blacklist); - } -} - -module.exports = getBlacklist; diff --git a/lib/shared/is-object.js b/lib/shared/is-object.js new file mode 100644 index 00000000..6375b561 --- /dev/null +++ b/lib/shared/is-object.js @@ -0,0 +1,7 @@ +'use strict'; + +function isObject(v) { + return (v != null && typeof v === 'object' && !Array.isArray(v)); +} + +module.exports = isObject; diff --git a/lib/shared/log/blacklist-error.js b/lib/shared/log/blacklist-error.js index b0355b2d..f3361b72 100644 --- a/lib/shared/log/blacklist-error.js +++ b/lib/shared/log/blacklist-error.js @@ -1,13 +1,13 @@ 'use strict'; var log = require('gulplog'); +var chalk = require('chalk'); -var ansi = require('../ansi'); var exit = require('../exit'); /* istanbul ignore next */ function logBlacklistError(err) { - log.error(ansi.red('Error: failed to retrieve plugins black-list')); + log.error(chalk.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/format-hrtime.js b/lib/shared/log/format-hrtime.js new file mode 100644 index 00000000..0547bd1e --- /dev/null +++ b/lib/shared/log/format-hrtime.js @@ -0,0 +1,48 @@ +'use strict'; + +var units = [ + [ 'h', 3600e9 ], + [ 'min', 60e9 ], + [ 's', 1e9 ], + [ 'ms', 1e6 ], + [ 'μs', 1e3 ], +]; + +function formatHrTime(hrtime) { + if (!Array.isArray(hrtime) || hrtime.length !== 2) { + return ''; + } + if (typeof hrtime[0] !== 'number' || typeof hrtime[1] !== 'number') { + return ''; + } + + var nano = hrtime[0] * 1e9 + hrtime[1]; + + for (var i = 0; i < units.length; i++) { + if (nano < units[i][1]) { + continue; + } + + if (nano >= units[i][1] * 10) { + return Math.round(nano / units[i][1]) + ' ' + units[i][0]; + } + + var s = String(Math.round(nano * 1e2 / units[i][1])); + if (s.slice(-2) === '00') { + s = s.slice(0, -2); + } else if (s.slice(-1) === '0') { + s = s.slice(0, -2) + '.' + s.slice(-2, -1); + } else { + s = s.slice(0, -2) + '.' + s.slice(-2); + } + return s + ' ' + units[i][0]; + } + + if (nano > 0) { + return nano + ' ns'; + } + + return ''; +} + +module.exports = formatHrTime; diff --git a/lib/shared/log/tasks.js b/lib/shared/log/tasks.js index 0b76b088..2d59fe35 100644 --- a/lib/shared/log/tasks.js +++ b/lib/shared/log/tasks.js @@ -1,165 +1,155 @@ 'use strict'; -var archy = require('archy'); var log = require('gulplog'); - -var sortBy = require('array-sort'); -var isObject = require('isobject'); - -var ansi = require('../ansi'); -var copyTree = require('./copy-tree'); +var chalk = require('chalk'); +var isObject = require('../is-object'); function logTasks(tree, opts, getTask) { if (opts.sortTasks) { - tree.nodes = sortBy(tree.nodes, 'label'); + tree.nodes = tree.nodes.sort(compareByLabel); } - var lineInfos = []; - var entryObserver = getLineInfoCollector(lineInfos); - var nodeFactory = getNodeFactory(getTask, entryObserver); - - tree = copyTree(tree, opts, nodeFactory); - var spacer = getSpacerForLineIndents(tree, lineInfos); - var lines = getLinesContainingOnlyBranches(tree); + var maxDepth = opts.tasksDepth; + if (typeof maxDepth !== 'number') { + maxDepth = 50; + } else if (maxDepth < 1) { + maxDepth = 1; + } - log.info(tree.label); - printTreeList(lines, spacer, lineInfos); -} + var compactedTasks = opts.compactTasks ? tree.nodes : []; -function getLineInfoCollector(lineInfos) { - return { - topTask: function(node) { - lineInfos.push({ - name: node.label, - desc: node.desc, - type: 'top', - }); - }, - option: function(opt) { - lineInfos.push({ - name: opt.label, - desc: opt.desc, - type: 'option', - }); - }, - childTask: function(node) { - lineInfos.push({ - name: node.label, - type: 'child', - }); - }, + var treeOpts = { + maxDepth: maxDepth, + compactedTasks: compactedTasks, + getTask: getTask, }; -} -function getNodeFactory(getTask, entryObserver) { - return { - topNode: function(node) { - return { - label: node.label, - }; - }, - - taskNode: function(node) { - /* istanbul ignore next */ - var task = getTask(node.label) || {}; - - var newNode = { - label: node.label, - desc: typeof task.description === 'string' ? task.description : '', - opts: [], - }; - entryObserver.topTask(newNode); - - if (isObject(task.flags)) { - Object.keys(task.flags).sort().forEach(function(flag) { - if (flag.length === 0) { - return; - } - /* istanbul ignore next */ - var opt = { - label: flag, - desc: typeof task.flags[flag] === 'string' ? task.flags[flag] : '', - }; - entryObserver.option(opt); - newNode.opts.push(opt); - newNode.label += '\n' + opt.label; // The way of archy for options. - }); - } - - return newNode; - }, - - childNode: function(node) { - var newChild = { - label: node.label, - }; - entryObserver.childTask(newChild); - newChild.label = ''; // Because don't use child tasks to calc indents. - - return newChild; - }, - }; + printTaskTree(tree, treeOpts); } -function getSpacerForLineIndents(tree, lineInfos) { - var maxSize = 0; - var sizes = []; - - archy(tree) - .split('\n') - .slice(1, -1) - .forEach(function(line, index) { - var info = lineInfos[index]; - if (info.type === 'top' || info.type === 'option') { - maxSize = Math.max(maxSize, line.length); - sizes.push(line.length); - } else { - sizes.push(0); - } - }); +function printTaskTree(tree, opts) { + var lines = []; + lines.push({ label: tree.label }); + var maxLabelWidth = 0; - maxSize += 3; + tree.nodes.forEach(function(node, idx, arr) { + var isLast = idx === arr.length - 1; + var w = createTreeLines(node, lines, opts, 1, '', isLast); + maxLabelWidth = Math.max(maxLabelWidth, w || 0); + }); - return function(index) { - return Array(maxSize - sizes[index]).join(' '); - }; + lines.forEach(function(line) { + var s = line.label; + if (line.desc) { + var spaces = ' '.repeat(maxLabelWidth - line.label.length) + ' '; + s += spaces + line.desc; + } + log.info(s); + }); } -function getLinesContainingOnlyBranches(tree) { - tree.nodes.forEach(function(node) { - node.label = ''; - node.opts.forEach(function() { - node.label += '\n'; +function createTreeLines(node, lines, opts, depth, bars, isLast) { + var task = { label: node.label, bars: bars, depth: depth }; + if (depth === 1) { + var t = opts.getTask(node.label); + task.desc = t.description; + task.flags = t.flags; + } + + var isLeaf = isLeafNode(node, depth, opts); + + var maxLabelWidth = addTaskToLines(task, lines, isLast, isLeaf); + + if (!isLeaf) { + bars += (isLast ? ' ' : '│ '); + node.nodes.forEach(function(node, idx, arr) { + var isLast = idx === arr.length - 1; + createTreeLines(node, lines, opts, depth + 1, bars, isLast); }); - }); + } - return archy(tree) - .split('\n') - .slice(1, -1); + return maxLabelWidth; } -function printTreeList(lines, spacer, lineInfos) { - lines.forEach(function(branch, index) { - var info = lineInfos[index]; - - var line = ansi.white(branch); - - if (info.type === 'top') { - line += ansi.cyan(info.name); - if (info.desc.length > 0) { - line += spacer(index) + ansi.white(info.desc); - } - } else if (info.type === 'option') { - line += ansi.magenta(info.name); - if (info.desc.length > 0) { - line += spacer(index) + ansi.white('…' + info.desc); - } - } else { // If (info.type === 'child') { - line += ansi.white(info.name); - } +function addTaskToLines(task, lines, isLast, isLeaf) { + var taskBars = task.bars + (isLast ? '└' : '├') + '─'; + if (isLeaf) { + taskBars += '─ '; + } else { + taskBars += '┬ '; + } - log.info(line); - }); + var line = {}; + if (task.depth === 1) { + line.label = chalk.white(taskBars) + chalk.white(task.label); + } else { + line.label = chalk.white(taskBars) + chalk.cyan(task.label); + } + if (typeof task.desc === 'string' && task.desc) { + line.desc = chalk.white(task.desc); + } + lines.push(line); + + var maxLabelWidth = line.label.length + + if (!isObject(task.flags)) { + return maxLabelWidth; + } + + var flagBars = task.bars; + if (isLast) { + flagBars += ' '; + } else { + flagBars += '│ '; + } + + if (isLeaf) { + flagBars += ' '; + } else { + flagBars += '│ '; + } + + Object.entries(task.flags).sort(flagSorter).forEach(addFlagsToLines); + + function addFlagsToLines(ent) { + if (typeof ent[0] !== 'string' || !ent[0]) return; + var line = {}; + lines.push(line); + line.label = chalk.white(flagBars) + chalk.magenta(ent[0]); + + maxLabelWidth = Math.max(maxLabelWidth, line.label.length); + + if (typeof ent[1] !== 'string' || !ent[1]) return; + line.desc = chalk.white('…' + ent[1]); + } + + return maxLabelWidth; +} + +function isLeafNode(node, depth, opts) { + if (depth >= opts.maxDepth) { + return true; + } else if (depth > 1 && opts.compactedTasks.includes(node)) { + return true; + } else if (!Array.isArray(node.nodes) || node.nodes.length === 0) { + return true; + } + return false; +} + +function compareByLabel(a, b) { + /* istanbul ignore if */ + if (!b.label) { + return -1; + } else /* istanbul ignore if */ if (!a.label) { + return 1; + } else { + return (a.label <= b.label) ? -1 : 1; + } +} + +function flagSorter(a, b) { + return (a[0] <= b[0]) ? -1 : 1; } module.exports = logTasks; diff --git a/lib/shared/log/verify.js b/lib/shared/log/verify.js index 71046237..f635bd39 100644 --- a/lib/shared/log/verify.js +++ b/lib/shared/log/verify.js @@ -2,7 +2,7 @@ var log = require('gulplog'); -var ansi = require('../ansi'); +var chalk = require('chalk'); var exit = require('../exit'); function logVerify(blacklisted) { @@ -10,16 +10,16 @@ function logVerify(blacklisted) { if (!pluginNames.length) { log.info( - ansi.green('There are no blacklisted plugins in this project') + chalk.green('There are no blacklisted plugins in this project') ); exit(0); } - log.warn(ansi.red('Blacklisted plugins found in this project:')); + log.warn(chalk.red('Blacklisted plugins found in this project:')); pluginNames.map(function(pluginName) { var reason = blacklisted[pluginName]; - log.warn(ansi.bgred(pluginName) + ': ' + reason); + log.warn(chalk.bgRed(pluginName) + ': ' + reason); }); exit(1); diff --git a/lib/shared/cli-options.js b/lib/shared/options/parser.js similarity index 79% rename from lib/shared/cli-options.js rename to lib/shared/options/parser.js index 09d98e3d..94801742 100644 --- a/lib/shared/cli-options.js +++ b/lib/shared/options/parser.js @@ -1,60 +1,65 @@ 'use strict'; -var ansi = require('./ansi'); +var chalk = require('chalk'); +var yargs = require('yargs'); -module.exports = { +var usage = + '\n' + chalk.bold('Usage:') + + ' gulp ' + chalk.blue('[options]') + ' tasks'; + +var options = { help: { alias: 'h', type: 'boolean', - desc: ansi.gray( + desc: chalk.gray( 'Show this help.'), }, version: { alias: 'v', type: 'boolean', - desc: ansi.gray( + desc: chalk.gray( 'Print the global and local gulp versions.'), }, - require: { + preload: { type: 'string', requiresArg: true, - desc: ansi.gray( - 'Will require a module before running the gulpfile. ' + + desc: chalk.gray( + 'Will preload a module before running the gulpfile. ' + 'This is useful for transpilers but also has other applications.'), }, gulpfile: { alias: 'f', type: 'string', requiresArg: true, - desc: ansi.gray( + desc: chalk.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: ansi.gray( + desc: chalk.gray( 'Manually set the CWD. The search for the gulpfile, ' + 'as well as the relativity of all requires will be from here.'), }, verify: { - desc: ansi.gray( + desc: chalk.gray( 'Will verify plugins referenced in project\'s package.json against ' + 'the plugins blacklist.'), }, tasks: { alias: 'T', type: 'boolean', - desc: ansi.gray( + desc: chalk.gray( 'Print the task dependency tree for the loaded gulpfile.'), }, 'tasks-simple': { type: 'boolean', - desc: ansi.gray( + desc: chalk.gray( 'Print a plaintext list of tasks for the loaded gulpfile.'), }, 'tasks-json': { - desc: ansi.gray( + desc: chalk.gray( 'Print the task dependency tree, ' + 'in JSON format, for the loaded gulpfile.'), }, @@ -63,31 +68,31 @@ module.exports = { type: 'number', requiresArg: true, default: undefined, // To detect if this cli option is specified. - desc: ansi.gray( + desc: chalk.gray( 'Specify the depth of the task dependency tree.'), }, 'compact-tasks': { type: 'boolean', default: undefined, // To detect if this cli option is specified. - desc: ansi.gray( + desc: chalk.gray( 'Reduce the output of task dependency tree by printing ' + 'only top tasks and their child tasks.'), }, 'sort-tasks': { type: 'boolean', default: undefined, // To detect if this cli option is specified. - desc: ansi.gray( + desc: chalk.gray( 'Will sort top tasks of task dependency tree.'), }, color: { type: 'boolean', - desc: ansi.gray( + desc: chalk.gray( 'Will force gulp and gulp plugins to display colors, ' + 'even when no color support is detected.'), }, 'no-color': { type: 'boolean', - desc: ansi.gray( + desc: chalk.gray( 'Will force gulp and gulp plugins to not display colors, ' + 'even when color support is detected.'), }, @@ -95,19 +100,19 @@ module.exports = { alias: 'S', type: 'boolean', default: undefined, // To detect if this cli option is specified. - desc: ansi.gray( + desc: chalk.gray( 'Suppress all gulp logging.'), }, continue: { type: 'boolean', default: undefined, // To detect if this cli option is specified. - desc: ansi.gray( + desc: chalk.gray( 'Continue execution of tasks upon failure.'), }, series: { type: 'boolean', default: undefined, // To detect if this cli option is specified. - desc: ansi.gray( + desc: chalk.gray( 'Run tasks given on the CLI in series (the default is parallel).'), }, 'log-level': { @@ -115,8 +120,14 @@ module.exports = { // Type isn't needed because count acts as a boolean count: true, default: undefined, // To detect if this cli option is specified. - desc: ansi.gray( + desc: chalk.gray( 'Set the loglevel. -L for least verbose and -LLLL for most verbose. ' + '-LLL is default.'), - }, + } }; + +var parser = yargs + .help(false).version(false).detectLocale(false) + .usage(usage).options(options); + +module.exports = parser; diff --git a/lib/shared/require-or-import.js b/lib/shared/require-or-import.js index 6970ae42..4cf5877e 100644 --- a/lib/shared/require-or-import.js +++ b/lib/shared/require-or-import.js @@ -9,6 +9,7 @@ try { // That way we can keep supporting all Node.js versions all the way back to 0.10. importESM = new Function('id', 'return import(id);'); } catch (e) { + /* istanbul ignore next */ importESM = null; } @@ -18,12 +19,18 @@ function requireOrImport(path, callback) { try { cjs = require(path); } catch (e) { - if (pathToFileURL && importESM && e.code === 'ERR_REQUIRE_ESM') { - // This is needed on Windows, because import() fails if providing a Windows file path. - var url = pathToFileURL(path); - importESM(url).then(function(esm) { callback(null, esm); }, callback); - return; + /* istanbul ignore else */ + if (pathToFileURL && importESM) { + // Because e.code is undefined on nyc process. + /* istanbul ignore else */ + if (e.code === 'ERR_REQUIRE_ESM' || process.env.NYC_CONFIG) { + // This is needed on Windows, because import() fails if providing a Windows file path. + var url = pathToFileURL(path); + importESM(url).then(function(esm) { callback(null, esm); }, callback); + return; + } } + /* istanbul ignore next */ err = e; } process.nextTick(function() { callback(err, cjs); }); diff --git a/lib/shared/verify-dependencies.js b/lib/shared/verify-dependencies.js index a0d4812c..2dbe9b7a 100644 --- a/lib/shared/verify-dependencies.js +++ b/lib/shared/verify-dependencies.js @@ -1,7 +1,5 @@ 'use strict'; -var matchdep = require('matchdep'); - /** * Given a collection of plugin names verifies this collection against * the blacklist. Returns an object with: @@ -12,14 +10,25 @@ var matchdep = require('matchdep'); * @param blacklist - contents of the blacklist in JSON format */ function verifyDependencies(pkg, blacklist) { - var blacklisted = matchdep - .filterAll(Object.keys(blacklist), pkg) + var pluginNames = [ + 'dependencies', + 'devDependencies', + 'peerDependencies', + ].reduce(function(res, prop) { + return res.concat(Object.keys(pkg[prop] || {})); + }, []); + + var blacklisted = pluginNames.filter(isContainedInBlacklist) .reduce(function(blacklisted, pluginName) { blacklisted[pluginName] = blacklist[pluginName]; return blacklisted; }, {}); return blacklisted; + + function isContainedInBlacklist(pluginName) { + return Boolean(blacklist[pluginName]); + } } module.exports = verifyDependencies; diff --git a/lib/versioned/^3.7.0/index.js b/lib/versioned/^3.7.0/index.js index b3a0da55..a5cc2a9f 100644 --- a/lib/versioned/^3.7.0/index.js +++ b/lib/versioned/^3.7.0/index.js @@ -4,20 +4,22 @@ var fs = require('fs'); var log = require('gulplog'); var stdout = require('mute-stdout'); +var chalk = require('chalk'); var taskTree = require('./task-tree'); var copyTree = require('../../shared/log/copy-tree'); var tildify = require('../../shared/tildify'); var logTasks = require('../../shared/log/tasks'); -var ansi = require('../../shared/ansi'); var exit = require('../../shared/exit'); var logEvents = require('./log/events'); var logTasksSimple = require('./log/tasks-simple'); var registerExports = require('../../shared/register-exports'); var requireOrImport = require('../../shared/require-or-import'); -function execute(opts, env, config) { +function execute(env) { + var opts = env.config.flags; + var tasks = opts._; var toRun = tasks.length ? tasks : ['default']; @@ -35,7 +37,7 @@ function execute(opts, env, config) { exit(1); } - log.info('Using gulpfile', ansi.magenta(tildify(env.configPath))); + log.info('Using gulpfile', chalk.magenta(tildify(env.configPath))); var gulpInst = require(env.modulePath); logEvents(gulpInst); @@ -51,10 +53,10 @@ function execute(opts, env, config) { } if (opts.tasks) { tree = taskTree(gulpInst.tasks); - if (config.description && typeof config.description === 'string') { - tree.label = config.description; + if (env.config.description && typeof env.config.description === 'string') { + tree.label = env.config.description; } else { - tree.label = 'Tasks for ' + ansi.magenta(tildify(env.configPath)); + tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath)); } return logTasks(tree, opts, function(task) { return gulpInst.tasks[task].fn; @@ -62,8 +64,8 @@ function execute(opts, env, config) { } if (opts.tasksJson) { tree = taskTree(gulpInst.tasks); - if (config.description && typeof config.description === 'string') { - tree.label = config.description; + if (env.config.description && typeof env.config.description === 'string') { + tree.label = env.config.description; } else { tree.label = 'Tasks for ' + tildify(env.configPath); } diff --git a/lib/versioned/^3.7.0/log/events.js b/lib/versioned/^3.7.0/log/events.js index b7bd00a8..a20de7ce 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 log = require('gulplog'); -var prettyTime = require('pretty-hrtime'); +var formatTime = require('../../../shared/log/format-hrtime'); +var chalk = require('chalk'); -var ansi = require('../../../shared/ansi'); var exit = require('../../../shared/exit'); var formatError = require('../format-error'); @@ -26,31 +26,31 @@ 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', '\'' + ansi.cyan(e.task) + '\'...'); + log.info('Starting', '\'' + chalk.cyan(e.task) + '\'...'); }); gulpInst.on('task_stop', function(e) { - var time = prettyTime(e.hrDuration); + var time = formatTime(e.hrDuration); log.info( - 'Finished', '\'' + ansi.cyan(e.task) + '\'', - 'after', ansi.magenta(time) + 'Finished', '\'' + chalk.cyan(e.task) + '\'', + 'after', chalk.magenta(time) ); }); gulpInst.on('task_err', function(e) { var msg = formatError(e); - var time = prettyTime(e.hrDuration); + var time = formatTime(e.hrDuration); log.error( - '\'' + ansi.cyan(e.task) + '\'', - ansi.red('errored after'), - ansi.magenta(time) + '\'' + chalk.cyan(e.task) + '\'', + chalk.red('errored after'), + chalk.magenta(time) ); log.error(msg); }); gulpInst.on('task_not_found', function(err) { log.error( - ansi.red('Task \'' + err.task + '\' is not in your gulpfile') + chalk.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 116956a8..c9c5ffc3 100644 --- a/lib/versioned/^4.0.0-alpha.1/index.js +++ b/lib/versioned/^4.0.0-alpha.1/index.js @@ -4,8 +4,8 @@ var fs = require('fs'); var log = require('gulplog'); var stdout = require('mute-stdout'); +var chalk = require('chalk'); -var ansi = require('../../shared/ansi'); var exit = require('../../shared/exit'); var tildify = require('../../shared/tildify'); @@ -18,7 +18,8 @@ var registerExports = require('../../shared/register-exports'); var copyTree = require('../../shared/log/copy-tree'); var requireOrImport = require('../../shared/require-or-import'); -function execute(opts, env, config) { +function execute(env) { + var opts = env.config.flags; var tasks = opts._; var toRun = tasks.length ? tasks : ['default']; @@ -52,10 +53,10 @@ function execute(opts, env, config) { } if (opts.tasks) { tree = {}; - if (config.description && typeof config.description === 'string') { - tree.label = config.description; + if (env.config.description && typeof env.config.description === 'string') { + tree.label = env.config.description; } else { - tree.label = 'Tasks for ' + ansi.magenta(tildify(env.configPath)); + tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath)); } tree.nodes = gulpInst.tree({ deep: true }); return logTasks(tree, opts, function(taskname) { @@ -64,8 +65,8 @@ function execute(opts, env, config) { } if (opts.tasksJson) { tree = {}; - if (config.description && typeof config.description === 'string') { - tree.label = config.description; + if (env.config.description && typeof env.config.description === 'string') { + tree.label = env.config.description; } else { tree.label = 'Tasks for ' + tildify(env.configPath); } @@ -78,7 +79,7 @@ function execute(opts, env, config) { return fs.writeFileSync(opts.tasksJson, output, 'utf-8'); } try { - log.info('Using gulpfile', ansi.magenta(tildify(env.configPath))); + log.info('Using gulpfile', chalk.magenta(tildify(env.configPath))); var runMethod = opts.series ? 'series' : 'parallel'; gulpInst[runMethod](toRun)(function(err) { if (err) { @@ -86,7 +87,7 @@ function execute(opts, env, config) { } }); } catch (err) { - log.error(ansi.red(err.message)); + log.error(chalk.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 1fca06fb..3d1763a6 100644 --- a/lib/versioned/^4.0.0-alpha.2/index.js +++ b/lib/versioned/^4.0.0-alpha.2/index.js @@ -4,8 +4,8 @@ var fs = require('fs'); var log = require('gulplog'); var stdout = require('mute-stdout'); +var chalk = require('chalk'); -var ansi = require('../../shared/ansi'); var exit = require('../../shared/exit'); var tildify = require('../../shared/tildify'); @@ -19,7 +19,8 @@ var copyTree = require('../../shared/log/copy-tree'); var getTask = require('../^4.0.0/log/get-task'); var requireOrImport = require('../../shared/require-or-import'); -function execute(opts, env, config) { +function execute(env) { + var opts = env.config.flags; var tasks = opts._; var toRun = tasks.length ? tasks : ['default']; @@ -54,18 +55,18 @@ function execute(opts, env, config) { } if (opts.tasks) { tree = gulpInst.tree({ deep: true }); - if (config.description && typeof config.description === 'string') { - tree.label = config.description; + if (env.config.description && typeof env.config.description === 'string') { + tree.label = env.config.description; } else { - tree.label = 'Tasks for ' + ansi.magenta(tildify(env.configPath)); + tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath)); } return logTasks(tree, opts, getTask(gulpInst)); } if (opts.tasksJson) { tree = gulpInst.tree({ deep: true }); - if (config.description && typeof config.description === 'string') { - tree.label = config.description; + if (env.config.description && typeof env.config.description === 'string') { + tree.label = env.config.description; } else { tree.label = 'Tasks for ' + tildify(env.configPath); } @@ -78,7 +79,7 @@ function execute(opts, env, config) { return fs.writeFileSync(opts.tasksJson, output, 'utf-8'); } try { - log.info('Using gulpfile', ansi.magenta(tildify(env.configPath))); + log.info('Using gulpfile', chalk.magenta(tildify(env.configPath))); var runMethod = opts.series ? 'series' : 'parallel'; gulpInst[runMethod](toRun)(function(err) { if (err) { @@ -86,7 +87,7 @@ function execute(opts, env, config) { } }); } catch (err) { - log.error(ansi.red(err.message)); + log.error(chalk.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 f0f0f45b..d6883587 100644 --- a/lib/versioned/^4.0.0/index.js +++ b/lib/versioned/^4.0.0/index.js @@ -5,7 +5,7 @@ var fs = require('fs'); var log = require('gulplog'); var stdout = require('mute-stdout'); -var ansi = require('../../shared/ansi'); +var chalk = require('chalk'); var exit = require('../../shared/exit'); var tildify = require('../../shared/tildify'); @@ -19,7 +19,8 @@ var copyTree = require('../../shared/log/copy-tree'); var getTask = require('./log/get-task'); var requireOrImport = require('../../shared/require-or-import'); -function execute(opts, env, config) { +function execute(env) { + var opts = env.config.flags; var tasks = opts._; var toRun = tasks.length ? tasks : ['default']; @@ -54,18 +55,18 @@ function execute(opts, env, config) { } if (opts.tasks) { tree = gulpInst.tree({ deep: true }); - if (config.description && typeof config.description === 'string') { - tree.label = config.description; + if (env.config.description && typeof env.config.description === 'string') { + tree.label = env.config.description; } else { - tree.label = 'Tasks for ' + ansi.magenta(tildify(env.configPath)); + tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath)); } return logTasks(tree, opts, getTask(gulpInst)); } if (opts.tasksJson) { tree = gulpInst.tree({ deep: true }); - if (config.description && typeof config.description === 'string') { - tree.label = config.description; + if (env.config.description && typeof env.config.description === 'string') { + tree.label = env.config.description; } else { tree.label = 'Tasks for ' + tildify(env.configPath); } @@ -78,7 +79,7 @@ function execute(opts, env, config) { return fs.writeFileSync(opts.tasksJson, output, 'utf-8'); } try { - log.info('Using gulpfile', ansi.magenta(tildify(env.configPath))); + log.info('Using gulpfile', chalk.magenta(tildify(env.configPath))); var runMethod = opts.series ? 'series' : 'parallel'; gulpInst[runMethod](toRun)(function(err) { if (err) { @@ -86,7 +87,7 @@ function execute(opts, env, config) { } }); } catch (err) { - log.error(ansi.red(err.message)); + log.error(chalk.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 1f6e7b16..0fb82c5c 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 prettyTime = require('pretty-hrtime'); +var formatTime = require('../../../shared/log/format-hrtime'); -var ansi = require('../../../shared/ansi'); +var chalk = require('chalk'); var formatError = require('../format-error'); // Wire up logging events @@ -16,27 +16,27 @@ 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', '\'' + ansi.cyan(evt.name) + '\'...'); + log[level]('Starting', '\'' + chalk.cyan(evt.name) + '\'...'); }); gulpInst.on('stop', function(evt) { - var time = prettyTime(evt.duration); + var time = formatTime(evt.duration); /* istanbul ignore next */ var level = evt.branch ? 'debug' : 'info'; log[level]( - 'Finished', '\'' + ansi.cyan(evt.name) + '\'', - 'after', ansi.magenta(time) + 'Finished', '\'' + chalk.cyan(evt.name) + '\'', + 'after', chalk.magenta(time) ); }); gulpInst.on('error', function(evt) { var msg = formatError(evt); - var time = prettyTime(evt.duration); + var time = formatTime(evt.duration); var level = evt.branch ? 'debug' : 'error'; log[level]( - '\'' + ansi.cyan(evt.name) + '\'', - ansi.red('errored after'), - ansi.magenta(time) + '\'' + chalk.cyan(evt.name) + '\'', + chalk.red('errored after'), + chalk.magenta(time) ); // If we haven't logged this before, log it and add to list diff --git a/lib/versioned/^4.0.0/log/get-task.js b/lib/versioned/^4.0.0/log/get-task.js index 1b158714..144acb47 100644 --- a/lib/versioned/^4.0.0/log/get-task.js +++ b/lib/versioned/^4.0.0/log/get-task.js @@ -1,6 +1,6 @@ 'use strict'; -var isObject = require('isobject'); +var isObject = require('../../../shared/is-object'); function getTask(gulpInst) { return function(name) { diff --git a/lib/versioned/^4.0.0/log/sync-task.js b/lib/versioned/^4.0.0/log/sync-task.js index 39cb4536..ff380f10 100644 --- a/lib/versioned/^4.0.0/log/sync-task.js +++ b/lib/versioned/^4.0.0/log/sync-task.js @@ -1,7 +1,7 @@ 'use strict'; var log = require('gulplog'); -var ansi = require('../../../shared/ansi'); +var chalk = require('chalk'); var tasks = {}; @@ -19,11 +19,11 @@ function warn() { process.exitCode = 1; log.warn( - ansi.red('The following tasks did not complete:'), - ansi.cyan(taskNames) + chalk.red('The following tasks did not complete:'), + chalk.cyan(taskNames) ); log.warn( - ansi.red('Did you forget to signal async completion?') + chalk.red('Did you forget to signal async completion?') ); } diff --git a/package.json b/package.json index bed47c0f..47ff7595 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "license": "MIT", "man": "gulp.1", "engines": { - "node": ">= 0.10" + "node": ">=10.13.0" }, "main": "index.js", "bin": { @@ -27,43 +27,44 @@ "prepublish": "marked-man --name gulp docs/CLI.md > gulp.1", "pretest": "npm run lint", "test": "mocha --async-only --timeout 5000 test/lib test", - "cover": "nyc --reporter=lcov --reporter=text-summary npm test", - "coveralls": "nyc --reporter=text-lcov npm test | coveralls" + "cover": "nyc mocha --async-only --timeout 5000 test/lib test" }, "dependencies": { - "ansi-colors": "^1.0.1", - "archy": "^1.0.0", - "array-sort": "^1.0.0", - "concat-stream": "^1.6.0", - "color-support": "^1.1.3", - "copy-props": "^2.0.1", - "fancy-log": "^1.3.2", - "gulplog": "^1.0.0", - "interpret": "^1.4.0", - "isobject": "^3.0.1", - "liftoff": "^3.1.0", - "matchdep": "^2.0.0", - "mute-stdout": "^1.0.0", - "pretty-hrtime": "^1.0.0", - "replace-homedir": "^1.0.0", - "semver-greatest-satisfied-range": "^1.1.0", - "v8flags": "^3.2.0", - "yargs": "^7.1.0" + "chalk": "^4.1.2", + "copy-props": "^4.0.0", + "fancy-log": "^2.0.0", + "gulplog": "^2.0.1", + "interpret": "^3.1.1", + "liftoff": "^4.0.0", + "mute-stdout": "^2.0.0", + "replace-homedir": "^2.0.0", + "semver-greatest-satisfied-range": "^2.0.0", + "v8flags": "^4.0.0", + "yargs": "^16.2.0" }, "devDependencies": { - "babel-preset-es2015": "^6.5.0", - "babel-register": "^6.5.1", - "coveralls": "^3.0.3", - "eslint": "^2.13.1", - "eslint-config-gulp": "^3.0.1", - "expect": "^1.20.2", - "gulp": "^4.0.0", - "gulp-test-tools": "^0.6.1", - "marked-man": "^0.2.1", - "mocha": "^3.2.0", - "nyc": "^13.3.0", - "rimraf": "^2.6.1", - "semver": "^5.7.1" + "@babel/core": "^7.20.2", + "@babel/preset-env": "^7.20.2", + "@babel/register": "^7.18.9", + "eslint": "^7.32.0", + "eslint-config-gulp": "^5.0.1", + "expect": "^27.5.1", + "gulp": "^4.0.2", + "marked-man": "^0.7.0", + "marked": "^0.7.0", + "mocha": "^8.4.0", + "nyc": "^15.1.0", + "rimraf": "^3.0.2", + "semver": "^7.3.8" + }, + "nyc": { + "reporter": [ + "lcov", + "text-summary" + ] + }, + "prettier": { + "singleQuote": true }, "keywords": [ "build", diff --git a/test/.eslintrc b/test/.eslintrc deleted file mode 100644 index ce82a15a..00000000 --- a/test/.eslintrc +++ /dev/null @@ -1,6 +0,0 @@ -{ - "extends": "gulp/test", - "rules": { - "no-console": "off" - } -} diff --git a/test/completion.js b/test/completion.js index 745422b5..3c30ad74 100644 --- a/test/completion.js +++ b/test/completion.js @@ -1,10 +1,12 @@ 'use strict'; var expect = require('expect'); -var runner = require('gulp-test-tools').gulpRunner; +var exec = require('child_process').exec; var path = require('path'); var fs = require('fs'); +var gulp = require('./tool/gulp-cmd'); + describe('flag: --completion', function() { ['bash', 'fish', 'powershell', 'zsh'].forEach(function(type) { @@ -12,12 +14,10 @@ describe('flag: --completion', function() { var file = path.resolve(__dirname, '../completion', type); var expected = fs.readFileSync(file, 'utf8') + '\n'; - runner({ verbose: false }) - .gulp('--completion=' + type) - .run(cb); + exec(gulp('--completion=' + type), cb); function cb(err, stdout, stderr) { - expect(err).toNotExist(); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(stdout).toEqual(expected); done(err); @@ -26,15 +26,12 @@ describe('flag: --completion', function() { }); it('shows error message for unknown completion type', function(done) { - var expected = - 'echo "gulp autocompletion rules for \'unknown\' not found"\n'; + var expected = 'echo "gulp autocompletion rules for \'unknown\' not found"\n'; - runner({ verbose: false }) - .gulp('--completion=unknown') - .run(cb); + exec(gulp('--completion=unknown'), cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); + expect(err).not.toBeNull(); expect(stderr).toEqual(''); expect(stdout).toEqual(expected); done(); @@ -42,12 +39,10 @@ describe('flag: --completion', function() { }); it('shows error message for missing completion type', function(done) { - runner({ verbose: false }) - .gulp('--completion') - .run(cb); + exec(gulp('--completion'), cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); + expect(err).not.toBeNull(); expect(stderr).toMatch('Missing completion type'); expect(stdout).toEqual(''); done(); diff --git a/test/config-description.js b/test/config-description.js index 41709909..ac85fd70 100644 --- a/test/config-description.js +++ b/test/config-description.js @@ -1,68 +1,71 @@ 'use strict'; var expect = require('expect'); +var exec = require('child_process').exec; var path = require('path'); 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 sliceLines = require('./tool/slice-lines'); +var eraseTime = require('./tool/erase-time'); +var gulp = require('./tool/gulp-cmd'); -var fixturesDir = path.join(__dirname, 'fixtures', 'config'); +var baseDir = 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) - .chdir('foo/bar') - .gulp('--tasks') - .run(cb); + var opts = { cwd: path.join(baseDir, 'foo/bar') }; + exec(gulp('--tasks'), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - var expected = fs.readFileSync(path.join(expectedDir, 'output0.txt'), - 'utf-8'); - stdout = eraseTime(stdout); - expect(stdout).toEqual(expected); + var expected = fs.readFileSync(path.join(expectedDir, 'output0.txt'), 'utf-8'); + expect(eraseTime(stdout)).toEqual(expected); done(err); } }); it('Should configure with a .gulp.* file in cwd found up', function(done) { - runner({ verbose: false }) - .basedir(fixturesDir) - .chdir('foo/bar/baz') - .gulp('--tasks') - .run(cb); + var opts = { cwd: path.join(baseDir, 'foo/bar/baz') }; + exec(gulp('--tasks'), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - var expected = fs.readFileSync(path.join(expectedDir, 'output0.txt'), - 'utf-8'); - stdout = eraseTime(skipLines(stdout, 1)); - expect(stdout).toEqual(expected); + var expected = fs.readFileSync(path.join(expectedDir, 'output0.txt'), 'utf-8'); + expect(sliceLines(stdout, 1)).toEqual(expected); + done(err); + } + }); + + it('Should configure with a .gulp.* file in cwd even if it is not a project root', function(done) { + var opts = { cwd: path.join(baseDir, 'foo/bar/quux') }; + exec(gulp('--tasks'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + var expected = fs.readFileSync(path.join(expectedDir, 'output2.txt'), 'utf-8'); + expect(sliceLines(stdout, 1)).toEqual(expected); done(err); } }); it('Should configure with a .gulp.* file in cwd by --cwd', function(done) { - runner({ verbose: false }) - .basedir(fixturesDir) - .chdir('qux') - .gulp('--tasks', '--gulpfile ../foo/bar/gulpfile.js', '--cwd .') - .run(cb); + var opts = { cwd: path.join(baseDir, 'qux') }; + exec(gulp( + '--tasks', + '--gulpfile ../foo/bar/gulpfile.js', + '--cwd .' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - var expected = fs.readFileSync(path.join(expectedDir, 'output1.txt'), - 'utf-8'); - stdout = eraseTime(stdout); - expect(stdout).toEqual(expected); + var expected = fs.readFileSync(path.join(expectedDir, 'output1.txt'), 'utf-8'); + expect(eraseTime(stdout)).toEqual(expected); done(err); } }); diff --git a/test/config-flags-compactTasks.js b/test/config-flags-compact-tasks.js similarity index 59% rename from test/config-flags-compactTasks.js rename to test/config-flags-compact-tasks.js index 460af741..06945128 100644 --- a/test/config-flags-compactTasks.js +++ b/test/config-flags-compact-tasks.js @@ -1,51 +1,42 @@ 'use strict'; var expect = require('expect'); +var exec = require('child_process').exec; var path = require('path'); var fs = require('fs'); -var skipLines = require('gulp-test-tools').skipLines; -var eraseTime = require('gulp-test-tools').eraseTime; -var fixturesDir = path.join(__dirname, 'fixtures/config'); +var sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, 'fixtures/config/flags/compactTasks'); var expectedDir = path.join(__dirname, 'expected'); -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) { - runner - .chdir('flags/compactTasks/t') - .gulp('--tasks') - .run(cb); + it('Should compact task lists when `flags.compactTasks` is true in .gulp.*', function(done) { + var opts = { cwd: path.join(baseDir, 't') }; + exec(gulp('--tasks'), opts, cb); function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-compact.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expected = skipLines(expected, 1); - - stdout = eraseTime(skipLines(stdout, 1)); - + expected = sliceLines(expected, 1); + stdout = sliceLines(stdout, 1); expect(stdout).toEqual(expected); expect(stderr).toEqual(''); done(err); } }); - it('Should not compact task lists when `flags.compactTasks` is false in ' + - '.gulp.*', function(done) { - runner - .chdir('flags/compactTasks/f') - .gulp('--tasks') - .run(cb); + it('Should not compact task lists when `flags.compactTasks` is false in .gulp.*', function(done) { + var opts = { cwd: path.join(baseDir, 'f') }; + exec(gulp('--tasks'), opts, cb); function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-unsorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expected = skipLines(expected, 1); - - stdout = eraseTime(skipLines(stdout, 1)); - + expected = sliceLines(expected, 1); + stdout = sliceLines(stdout, 1); expect(stdout).toEqual(expected); expect(stderr).toEqual(''); done(err); @@ -53,18 +44,14 @@ describe('config: flags.compactTasks', function() { }); it('Should overridden by cli flag: --compact-tasks', function(done) { - runner - .chdir('flags/compactTasks/f') - .gulp('--tasks --compact-tasks') - .run(cb); + var opts = { cwd: path.join(baseDir, 'f') }; + exec(gulp('--tasks', '--compact-tasks'), opts, cb); function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-compact.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expected = skipLines(expected, 1); - - stdout = eraseTime(skipLines(stdout, 1)); - + expected = sliceLines(expected, 1); + stdout = sliceLines(stdout, 1); expect(stdout).toEqual(expected); expect(stderr).toEqual(''); done(err); @@ -72,18 +59,14 @@ describe('config: flags.compactTasks', function() { }); it('Should overridden by cli flag: --no-compact-tasks', function(done) { - runner - .chdir('flags/compactTasks/t') - .gulp('--tasks --no-compact-tasks') - .run(cb); + var opts = { cwd: path.join(baseDir, 't') }; + exec(gulp('--tasks', '--no-compact-tasks'), opts, cb); function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-unsorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expected = skipLines(expected, 1); - - stdout = eraseTime(skipLines(stdout, 1)); - + expected = sliceLines(expected, 1); + stdout = sliceLines(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 30edf19b..5764bfbb 100644 --- a/test/config-flags-continue.js +++ b/test/config-flags-continue.js @@ -1,28 +1,23 @@ 'use strict'; var expect = require('expect'); +var exec = require('child_process').exec; var path = require('path'); -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 fixturesDir = path.join(__dirname, 'fixtures/config'); -var runner = require('gulp-test-tools').gulpRunner({ verbose: false }).basedir(fixturesDir); +var sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, 'fixtures/config/flags/continue'); describe('config: flags.continue', function() { - it('Should continue if `flags.continue` is true in .gulp.*', - function(done) { - runner - .chdir('flags/continue/t') - .gulp() - .run(cb); + it('Should continue if `flags.continue` is true in .gulp.*', function(done) { + var opts = { cwd: path.join(baseDir, 't') }; + exec(gulp(), opts, cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); - - stdout = eraseLapse(eraseTime(skipLines(stdout, 1))); + expect(err).not.toBeNull(); + stdout = sliceLines(stdout, 1); expect(stdout).toEqual( 'Starting \'default\'...\n' + 'Starting \'err\'...\n' + @@ -30,7 +25,7 @@ describe('config: flags.continue', function() { 'Finished \'next\' after ?\n' + '' ); - stderr = eraseLapse(eraseTime(headLines(stderr, 2))); + stderr = sliceLines(stderr, 0, 2); expect(stderr).toEqual( '\'err\' errored after ?\n' + 'Error: Error!' @@ -39,23 +34,19 @@ describe('config: flags.continue', function() { } }); - it('Should not continue if `flags.continue` is false in .gulp.*', - function(done) { - runner - .chdir('flags/continue/f') - .gulp() - .run(cb); + it('Should not continue if `flags.continue` is false in .gulp.*', function(done) { + var opts = { cwd: path.join(baseDir, 'f') }; + exec(gulp(), opts, cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); - - stdout = eraseLapse(eraseTime(skipLines(stdout, 1))); + expect(err).not.toBeNull(); + stdout = sliceLines(stdout, 1); expect(stdout).toEqual( 'Starting \'default\'...\n' + 'Starting \'err\'...\n' + '' ); - stderr = eraseLapse(eraseTime(headLines(stderr, 2))); + stderr = sliceLines(stderr, 0, 2); expect(stderr).toEqual( '\'err\' errored after ?\n' + 'Error: Error!' @@ -65,15 +56,12 @@ describe('config: flags.continue', function() { }); it('Should overridden by cli flag: --continue', function(done) { - runner - .chdir('flags/continue/f') - .gulp('--continue') - .run(cb); + var opts = { cwd: path.join(baseDir, 'f') }; + exec(gulp('--continue'), opts, cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); - - stdout = eraseLapse(eraseTime(skipLines(stdout, 1))); + expect(err).not.toBeNull(); + stdout = sliceLines(stdout, 1); expect(stdout).toEqual( 'Starting \'default\'...\n' + 'Starting \'err\'...\n' + @@ -81,7 +69,7 @@ describe('config: flags.continue', function() { 'Finished \'next\' after ?\n' + '' ); - stderr = eraseLapse(eraseTime(headLines(stderr, 2))); + stderr = sliceLines(stderr, 0, 2); expect(stderr).toEqual( '\'err\' errored after ?\n' + 'Error: Error!' @@ -91,21 +79,18 @@ describe('config: flags.continue', function() { }); it('Should overridden by cli flag: --no-continue', function(done) { - runner - .chdir('flags/continue/t') - .gulp('--no-continue') - .run(cb); + var opts = { cwd: path.join(baseDir, 't') }; + exec(gulp('--no-continue'), opts, cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); - - stdout = eraseLapse(eraseTime(skipLines(stdout, 1))); + expect(err).not.toBeNull(); + stdout = sliceLines(stdout, 1); expect(stdout).toEqual( 'Starting \'default\'...\n' + 'Starting \'err\'...\n' + '' ); - stderr = eraseLapse(eraseTime(headLines(stderr, 2))); + stderr = sliceLines(stderr, 0, 2); expect(stderr).toEqual( '\'err\' errored after ?\n' + 'Error: Error!' diff --git a/test/config-flags-gulpfile.js b/test/config-flags-gulpfile.js index 3ac37ac1..329043d4 100644 --- a/test/config-flags-gulpfile.js +++ b/test/config-flags-gulpfile.js @@ -1,105 +1,117 @@ 'use strict'; var expect = require('expect'); - +var exec = require('child_process').exec; var path = require('path'); -var fixturesDir = path.join(__dirname, 'fixtures/config'); -var headLines = require('gulp-test-tools').headLines; -var eraseTime = require('gulp-test-tools').eraseTime; -var runner = require('gulp-test-tools').gulpRunner().basedir(fixturesDir); +var sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, 'fixtures/config/flags/gulpfile'); +var prjDir = path.join(baseDir, 'prj'); describe('config: flags.gulpfile', function() { it('Should configure with a .gulp.* file', function(done) { - runner - .chdir('flags/gulpfile') - .gulp() - .run(cb); + var opts = { cwd: prjDir }; + exec(gulp(), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - stdout = headLines(stdout, 2, 2); - expect(stdout).toEqual( - 'This gulpfile : ' + - path.join(fixturesDir, 'flags/gulpfile/is/here/mygulpfile.js') + - '\n' + - 'The current directory : ' + path.join(fixturesDir, 'flags/gulpfile') + expect(sliceLines(stdout, 2, 4)).toEqual( + 'This gulpfile : ' + path.join(baseDir, 'is/here/gulpfile-by-prj-cfg.js') + '\n' + + 'The current directory : ' + prjDir ); done(err); } }); - it('Should configure with a .gulp.* file in the directory specified by ' + - '\n\t--cwd', function(done) { - runner - .gulp('--cwd ./flags/gulpfile') - .run(cb); + it('Should configure with a .gulp.* file in the directory specified by --cwd', function(done) { + var opts = { cwd: prjDir }; + exec(gulp('--cwd ../cwd'), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - stdout = headLines(stdout, 2, 3); - expect(stdout).toEqual( - 'This gulpfile : ' + - path.join(fixturesDir, 'flags/gulpfile/is/here/mygulpfile.js') + - '\n' + - 'The current directory : ' + path.join(fixturesDir, 'flags/gulpfile') + expect(sliceLines(stdout, 3, 5)).toEqual( + 'This gulpfile : ' + path.join(baseDir, 'is/here/gulpfile-by-cwd-cfg.js') + '\n' + + 'The current directory : ' + path.join(baseDir, 'cwd') ); done(err); } }); - it('Should ignore a ./gulp.* file if another directory is specified by ' + - '\n\t--cwd', function(done) { - runner - .chdir('./flags/gulpfile') - .gulp('--cwd ./cwd') - .run(cb); + it('Should configure with a .gulp.* file found up', function(done) { + var opts = { cwd: path.join(prjDir, 'findup') }; + exec(gulp(), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - stdout = headLines(stdout, 1, 3); - expect(stdout).toEqual( - 'Another gulpfile : ' + - path.join(fixturesDir, 'flags/gulpfile/cwd/gulpfile.js') + expect(sliceLines(stdout, 2, 4)).toEqual( + 'This gulpfile : ' + path.join(baseDir, 'is/here/gulpfile-by-prj-cfg.js') + '\n' + + 'The current directory : ' + path.join(prjDir, 'findup') ); done(err); } }); - it('Should ignore a ./.gulp.* file if another gulpfile is specified by ' + - '\n\t--gulpfile', function(done) { - runner - .chdir('./flags/gulpfile') - .gulp('--gulpfile ./cwd/gulpfile.js') - .run(cb); + it('Should configure with a .gulp.* file found up the directory specified by --cwd', function(done) { + var opts = { cwd: prjDir }; + exec(gulp('--cwd ../cwd/findup'), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - stdout = headLines(stdout, 1, 3); - expect(stdout).toEqual( - 'Another gulpfile : ' + - path.join(fixturesDir, 'flags/gulpfile/cwd/gulpfile.js') + expect(sliceLines(stdout, 3, 5)).toEqual( + 'This gulpfile : ' + path.join(baseDir, 'is/here/gulpfile-by-cwd-cfg.js') + '\n' + + 'The current directory : ' + path.join(baseDir, 'cwd/findup') + ); + done(err); + } + }); + + it('Should ignore a ./gulp.* file if another directory is specified by --cwd', function(done) { + var opts = { cwd: prjDir }; + exec(gulp('--cwd ../is/here'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(sliceLines(stdout, 3, 5)).toEqual( + 'This gulpfile : ' + path.join(baseDir, 'is/here/gulpfile.js') + '\n' + + 'The current directory : ' + path.join(baseDir, 'is/here') + ); + done(err); + } + }); + + it('Should ignore a ./.gulp.* file if another gulpfile is specified by --gulpfile', function(done) { + var opts = { cwd: prjDir }; + exec(gulp('--gulpfile ../is/here/gulpfile.js'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(sliceLines(stdout, 3, 5)).toEqual( + 'This gulpfile : ' + path.join(baseDir, 'is/here/gulpfile.js') + '\n' + + 'The current directory : ' + path.join(baseDir, 'is/here') ); done(err); } }); it('Should overridden by cli flag: --gulpfile', function(done) { - runner - .chdir('./flags/gulpfile/override-by-cliflag') - .gulp('--gulpfile mygulpfile.js') - .run(cb); + var opts = { cwd: path.join(baseDir, 'override-by-cliflag') }; + exec(gulp('--gulpfile mygulpfile.js'), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - stdout = headLines(stdout, 1, 2); - expect(stdout).toEqual('Gulpfile : ' + path.join(fixturesDir, 'flags/gulpfile/override-by-cliflag/mygulpfile.js')); + expect(sliceLines(stdout, 2, 3)).toEqual( + 'Gulpfile : ' + path.join(baseDir, 'override-by-cliflag/mygulpfile.js') + ); done(err); } }); @@ -107,25 +119,30 @@ describe('config: flags.gulpfile', function() { it('Should autoload a module for loading a specified gulpfile', function(done) { this.timeout(0); - runner - .chdir('flags/gulpfile/autoload') - .gulp('dist') - .run(cb); + var opts = { cwd: path.join(baseDir, 'autoload') }; + exec(gulp('dist'), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); + expect(sliceLines(stdout, 0, 1)).toEqual('Loaded external module: @babel/register'); + expect(sliceLines(stdout, 4, 5)).toEqual('clean!'); + expect(sliceLines(stdout, 7, 8)).toEqual('build!'); + done(err); + } + }); - var requiring = eraseTime(headLines(stdout, 1)); - expect(requiring).toEqual('Requiring external module babel-register'); - var clean = eraseTime(headLines(stdout, 1, 4)); - expect(clean).toEqual('clean!'); - var build = eraseTime(headLines(stdout, 1, 7)); - expect(build).toEqual('build!'); + it('Should output error logs of autoload if fail to load module for a specified gulpfile', function(done) { + var opts = { cwd: path.join(baseDir, 'autoload-fail') }; + exec(gulp('dist'), opts, cb); - done(err); + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stderr).not.toEqual(''); + expect(sliceLines(stdout, 0, 1)).toEqual('Failed to load external module: coffeescript/register'); + expect(sliceLines(stdout, 1, 2)).toMatch('Error: Cannot find module \'coffeescript/register\''); + done(); } }); }); - diff --git a/test/config-flags-log-level.js b/test/config-flags-log-level.js index c3c20918..8d187cf0 100644 --- a/test/config-flags-log-level.js +++ b/test/config-flags-log-level.js @@ -1,196 +1,206 @@ 'use strict'; var expect = require('expect'); +var exec = require('child_process').exec; var path = require('path'); -var eraseTime = require('gulp-test-tools').eraseTime; -var headLines = require('gulp-test-tools').headLines; -var runner = require('gulp-test-tools').gulpRunner; + +var sliceLines = require('./tool/slice-lines'); +var eraseTime = require('./tool/erase-time'); +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, 'fixtures/config/flags/logLevel'); describe('config: flag.logLevel', function() { describe('log level 3 by default', function() { - var gulp = runner({ verbose: false }) - .basedir(path.join(__dirname, 'fixtures/config/flags/logLevel')) - .gulp; it('Should output error log', function(done) { - gulp('--gulpfile x') - .run(function(err, stdout, stderr) { - expect(err).toNotEqual(null); - expect(stdout).toEqual(''); - expect(eraseTime(stderr)).toEqual('No gulpfile found\n'); - done(); - }); + var opts = { cwd: baseDir }; + exec(gulp('--gulpfile x'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stdout).toEqual(''); + expect(eraseTime(stderr)).toEqual('No gulpfile found\n'); + done(); + } }); it('Should output warn log', function(done) { - gulp('--require', 'mymodule') - .run(function(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - expect(headLines(eraseTime(stdout), 2)).toMatch( - 'Failed to load external module mymodule\n' + - 'Error: Cannot find module \'mymodule\' from \''); - done(); - }); + var opts = { cwd: baseDir }; + exec(gulp('--preload mymodule'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(sliceLines(stdout, 1, 3)).toMatch( + 'Failed to preload external module: mymodule\n' + + 'Error: Cannot find module \'mymodule\' from \''); + done(); + } }); it('Should output info log', function(done) { - gulp('--harmony') - .run(function(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - expect(headLines(eraseTime(stdout), 2)).toMatch( - 'Node flags detected: --harmony\n' + - 'Respawned to PID: '); - done(err); - }); + var opts = { cwd: baseDir }; + exec(gulp('--harmony'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(sliceLines(stdout, 0, 2)).toMatch( + 'Node flags detected: --harmony\n' + + 'Respawned to PID: '); + done(err); + } }); }); describe('log level 1 by config `flags.logLevel`', function() { - 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(stderr)).toEqual('No gulpfile found\n'); - done(); - }); + var opts = { cwd: baseDir }; + exec(gulp('--gulpfile x'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stdout).toEqual(''); + expect(eraseTime(stderr)).toEqual('No gulpfile found\n'); + done(); + } }); it('Should output warn log', function(done) { - gulp('--require', 'mymodule') - .run(function(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - expect(stderr).toEqual(''); - done(); - }); + var opts = { cwd: path.join(baseDir, 'L') }; + exec(gulp('--preload mymodule'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(stderr).toEqual(''); + done(); + } }); it('Should output info log', function(done) { - gulp('--harmony') - .run(function(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - expect(stdout).toEqual(''); - done(err); - }); + var opts = { cwd: path.join(baseDir, 'L') }; + exec(gulp('--harmony'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(stdout).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; - it('Should output error log', function(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(); - }); + var opts = { cwd: path.join(baseDir, 'LL') }; + exec(gulp('--gulpfile x'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stdout).toEqual(''); + expect(eraseTime(stderr)).toEqual('No gulpfile found\n'); + done(); + } }); it('Should output warn log', function(done) { - gulp('--require', 'mymodule') - .run(function(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - expect(eraseTime(stdout)).toMatch( - 'Failed to load external module mymodule\n' + - 'Error: Cannot find module \'mymodule\' from \''); - done(); - }); + var opts = { cwd: path.join(baseDir, 'LL') }; + exec(gulp('--preload mymodule'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseTime(stdout)).toMatch( + 'Failed to preload external module: mymodule\n' + + 'Error: Cannot find module \'mymodule\' from \''); + done(); + } }); it('Should output info log', function(done) { - gulp('--harmony') - .run(function(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - expect(stdout).toEqual(''); - done(err); - }); + var opts = { cwd: path.join(baseDir, 'LL') }; + exec(gulp('--harmony'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(stdout).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; - it('Should output error log', function(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(); - }); + var opts = { cwd: path.join(baseDir, 'LLL') }; + exec(gulp('--gulpfile x'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(stdout).toEqual(''); + expect(eraseTime(stderr)).toEqual('No gulpfile found\n'); + done(); + } }); it('Should output warn log', function(done) { - gulp('--require', 'mymodule') - .run(function(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - expect(headLines(eraseTime(stdout), 2)).toMatch( - 'Failed to load external module mymodule\n' + - 'Error: Cannot find module \'mymodule\' from \''); - done(); - }); + var opts = { cwd: path.join(baseDir, 'LLL') }; + exec(gulp('--preload mymodule'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(eraseTime(stdout)).toMatch( + 'Failed to preload external module: mymodule\n' + + 'Error: Cannot find module \'mymodule\' from \''); + done(); + } }); it('Should output info log', function(done) { - gulp('--harmony') - .run(function(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - expect(headLines(eraseTime(stdout), 2)).toMatch( - 'Node flags detected: --harmony\n' + - 'Respawned to PID: '); - done(err); - }); + var opts = { cwd: path.join(baseDir, 'LLL') }; + exec(gulp('--harmony'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(sliceLines(stdout, 0, 2)).toMatch( + 'Node flags detected: --harmony\n' + + 'Respawned to PID: '); + done(err); + } }); }); describe('Overridden by cli flag: -L/-LL/-LLL', function() { it('Should not output info log by -L', function(done) { - var gulp = runner({ verbose: false }) - .basedir(path.join(__dirname, 'fixtures/config/flags/logLevel/LLL')) - .gulp; - - gulp('-L', '--require', 'mymodule') - .run(function(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stdout).toEqual(''); - expect(stderr).toEqual(''); - done(err); - }); + var opts = { cwd: path.join(baseDir, 'LLL') }; + exec(gulp('-L', '--preload mymodule'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stdout).toEqual(''); + expect(stderr).toEqual(''); + done(err); + } }); it('Should output info log by -LLL', function(done) { - var gulp = runner({ verbose: false }) - .basedir(path.join(__dirname, 'fixtures/config/flags/logLevel/L')) - .gulp; - - gulp('-LLL', '--harmony') - .run(function(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - expect(headLines(eraseTime(stdout), 2)).toMatch( - 'Node flags detected: --harmony\n' + - 'Respawned to PID: '); - done(err); - }); + var opts = { cwd: path.join(baseDir, 'L') }; + exec(gulp('-LLL', '--harmony'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(sliceLines(stdout, 0, 2)).toMatch( + 'Node flags detected: --harmony\n' + + 'Respawned to PID: '); + done(err); + } }); }); }); diff --git a/test/config-flags-node-flags.js b/test/config-flags-node-flags.js index ac05dbb3..eb9c00cb 100644 --- a/test/config-flags-node-flags.js +++ b/test/config-flags-node-flags.js @@ -1,88 +1,64 @@ 'use strict'; var expect = require('expect'); +var exec = require('child_process').exec; var path = require('path'); -var fixturesDir = path.join(__dirname, 'fixtures/config'); +var sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); -var runner = require('gulp-test-tools').gulpRunner().basedir(fixturesDir); -var headLines = require('gulp-test-tools').headLines; -var skipLines = require('gulp-test-tools').skipLines; -var eraseTime = require('gulp-test-tools').eraseTime; -var eraseLapse = require('gulp-test-tools').eraseLapse; +var baseDir = path.join(__dirname, 'fixtures/config/flags/nodeFlags'); describe('config: nodeFlags', function() { it('Should respawn by a node flag: --lazy', function(done) { - runner - .chdir('flags/nodeFlags/string') - .gulp() - .run(cb); + var opts = { cwd: path.join(baseDir, 'string') }; + exec(gulp(), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - - var line = eraseTime(headLines(stdout, 1)); - expect(line).toEqual('Node flags detected: --lazy'); - - line = eraseTime(headLines(stdout, 2, 1)); - expect(line).toMatch('Respawned to PID: '); + expect(sliceLines(stdout, 0, 1)).toEqual('Node flags detected: --lazy'); + expect(sliceLines(stdout, 1, 3)).toMatch('Respawned to PID: '); done(err); } }); it('Should respawn by a node flag: --lazy --trace-deprecation', function(done) { - runner - .chdir('flags/nodeFlags/array') - .gulp() - .run(cb); + var opts = { cwd: path.join(baseDir, 'array') }; + exec(gulp(), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - - var line = eraseTime(headLines(stdout, 1)); - expect(line).toEqual('Node flags detected: --lazy, --trace-deprecation'); - - line = eraseTime(headLines(stdout, 2, 1)); - expect(line).toMatch('Respawned to PID: '); + expect(sliceLines(stdout, 0, 1)).toEqual('Node flags detected: --lazy, --trace-deprecation'); + expect(sliceLines(stdout, 1, 3)).toMatch('Respawned to PID: '); done(err); } }); it('Should respawn with flags in config file and command line', function(done) { - runner - .chdir('flags/nodeFlags/string') - .gulp('--harmony') - .run(cb); + var opts = { cwd: path.join(baseDir, 'string') }; + exec(gulp('--harmony'), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - - var line = eraseTime(headLines(stdout, 1)); - expect(line).toEqual('Node flags detected: --lazy, --harmony'); - - line = eraseTime(headLines(stdout, 2, 1)); - expect(line).toMatch('Respawned to PID: '); + expect(sliceLines(stdout, 0, 1)).toEqual('Node flags detected: --lazy, --harmony'); + expect(sliceLines(stdout, 1, 3)).toMatch('Respawned to PID: '); done(err); } }); it('Should not respawn when a node flag is specified to undefined', function(done) { - runner - .chdir('flags/nodeFlags/undefined') - .gulp() - .run(cb); + var opts = { cwd: path.join(baseDir, 'undefined') }; + exec(gulp(), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - - stdout = eraseLapse(eraseTime(stdout)); - expect(headLines(stdout, 1)).toMatch('Using gulpfile '); - expect(skipLines(stdout, 1)).toEqual( + expect(sliceLines(stdout, 0, 1)).toMatch('Using gulpfile '); + expect(sliceLines(stdout, 1)).toEqual( 'Starting \'default\'...\n' + 'Default\n' + 'Finished \'default\' after ?\n' + @@ -92,18 +68,14 @@ describe('config: nodeFlags', function() { }); it('Should not respawn when a node flag is specified to null', function(done) { - runner - .chdir('flags/nodeFlags/null') - .gulp() - .run(cb); + var opts = { cwd: path.join(baseDir, 'null') }; + exec(gulp(), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - - stdout = eraseLapse(eraseTime(stdout)); - expect(headLines(stdout, 1)).toMatch('Using gulpfile '); - expect(skipLines(stdout, 1)).toEqual( + expect(sliceLines(stdout, 0, 1)).toMatch('Using gulpfile '); + expect(sliceLines(stdout, 1)).toEqual( 'Starting \'default\'...\n' + 'Default\n' + 'Finished \'default\' after ?\n' + @@ -111,5 +83,4 @@ describe('config: nodeFlags', function() { done(err); } }); - }); diff --git a/test/config-flags-preload.js b/test/config-flags-preload.js new file mode 100644 index 00000000..47942363 --- /dev/null +++ b/test/config-flags-preload.js @@ -0,0 +1,90 @@ +'use strict'; + +var expect = require('expect'); +var exec = require('child_process').exec; +var path = require('path'); + +var sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, 'fixtures/config/flags/preload'); + +describe('config: flags.preload', function() { + + it('Should configure with an array in a .gulp.* file', function(done) { + var opts = { cwd: path.join(baseDir, 'array') }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(sliceLines(stdout, 0, 1)).toEqual('Preloading external module: ./preload_one'); + expect(sliceLines(stdout, 1, 2)).toEqual('Preloaded external module: ./preload_one'); + expect(sliceLines(stdout, 2, 3)).toEqual('Preloading external module: ./preload_two'); + expect(sliceLines(stdout, 3, 4)).toEqual('Preloaded external module: ./preload_two'); + expect(sliceLines(stdout, 6, 7)).toEqual('preload one!'); + expect(sliceLines(stdout, 7, 8)).toEqual('preload two!'); + done(err); + } + }); + + it('Should configure with a string in a .gulp.* file', function(done) { + var opts = { cwd: path.join(baseDir, 'string') }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(sliceLines(stdout, 0, 1)).toEqual('Preloading external module: ./preload'); + expect(sliceLines(stdout, 1, 2)).toEqual('Preloaded external module: ./preload'); + expect(sliceLines(stdout, 4, 5)).toEqual('hello preload!'); + done(err); + } + }); + + it('Combines --preload flag with .gulp.* file flags.preload', function(done) { + var opts = { cwd: path.join(baseDir, 'join-flags') }; + exec(gulp('--preload ./preload_one'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(sliceLines(stdout, 0, 1)).toEqual('Preloading external module: ./preload_one'); + expect(sliceLines(stdout, 1, 2)).toEqual('Preloaded external module: ./preload_one'); + expect(sliceLines(stdout, 2, 3)).toEqual('Preloading external module: ./preload_two'); + expect(sliceLines(stdout, 3, 4)).toEqual('Preloaded external module: ./preload_two'); + expect(sliceLines(stdout, 6, 7)).toEqual('preload one!'); + expect(sliceLines(stdout, 7, 8)).toEqual('preload two!'); + done(err); + } + }); + + it('resolves relative requires against cwd', function(done) { + var opts = { cwd: path.join(__dirname, 'fixtures/config') }; + exec(gulp('--cwd flags/preload/with-cwd'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(sliceLines(stdout, 0, 1)).toEqual('Preloading external module: ../preload'); + expect(sliceLines(stdout, 1, 2)).toEqual('Preloaded external module: ../preload'); + expect(sliceLines(stdout, 5, 6)).toEqual('hello preload!'); + done(err); + } + }); + + it('works with absolute paths, ignoring cwd', function(done) { + var opts = { cwd: path.join(__dirname, 'fixtures/config') }; + exec(gulp('--cwd flags/preload/with-absolute'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + var absolute = path.join(__dirname, './fixtures/config/flags/preload/preload'); + expect(sliceLines(stdout, 0, 1)).toEqual('Preloading external module: ' + absolute); + expect(sliceLines(stdout, 1, 2)).toEqual('Preloaded external module: ' + absolute); + expect(sliceLines(stdout, 5, 6)).toEqual('hello preload!'); + done(err); + } + }); +}); diff --git a/test/config-flags-require.js b/test/config-flags-require.js deleted file mode 100644 index 6db4de52..00000000 --- a/test/config-flags-require.js +++ /dev/null @@ -1,109 +0,0 @@ -'use strict'; - -var expect = require('expect'); - -var path = require('path'); -var fixturesDir = path.join(__dirname, 'fixtures/config'); - -var headLines = require('gulp-test-tools').headLines; -var eraseTime = require('gulp-test-tools').eraseTime; -var runner = require('gulp-test-tools').gulpRunner().basedir(fixturesDir); - -describe('config: flags.require', function() { - - it('Should configure with an array in a .gulp.* file', function(done) { - runner - .chdir('flags/require/array') - .gulp() - .run(cb); - - function cb(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - - var requiring1 = eraseTime(headLines(stdout, 1)); - expect(requiring1).toEqual('Requiring external module ./preload_one'); - var requiring2 = eraseTime(headLines(stdout, 1, 1)); - expect(requiring2).toEqual('Requiring external module ./preload_two'); - var preload1 = eraseTime(headLines(stdout, 1, 4)); - expect(preload1).toEqual('preload one!'); - var preload2 = eraseTime(headLines(stdout, 1, 5)); - expect(preload2).toEqual('preload two!'); - done(err); - } - }); - - it('Should configure with a string in a .gulp.* file', function(done) { - runner - .chdir('flags/require/string') - .gulp() - .run(cb); - - function cb(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - var requiring = eraseTime(headLines(stdout, 1)); - expect(requiring).toEqual('Requiring external module ./preload'); - var preload1 = eraseTime(headLines(stdout, 1, 3)); - expect(preload1).toEqual('hello preload!'); - done(err); - } - }); - - it('Combines --require flag with .gulp.* file flags.require', function(done) { - runner - .chdir('flags/require/join-flags') - .gulp('--require ./preload_one') - .run(cb); - - function cb(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - - var requiring1 = eraseTime(headLines(stdout, 1)); - expect(requiring1).toEqual('Requiring external module ./preload_one'); - var requiring2 = eraseTime(headLines(stdout, 1, 1)); - expect(requiring2).toEqual('Requiring external module ./preload_two'); - var preload1 = eraseTime(headLines(stdout, 1, 4)); - expect(preload1).toEqual('preload one!'); - var preload2 = eraseTime(headLines(stdout, 1, 5)); - expect(preload2).toEqual('preload two!'); - done(err); - } - }); - - it('resolves relative requires against cwd', function(done) { - runner - .gulp('--cwd flags/require/with-cwd') - .run(cb); - - function cb(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - var requiring = eraseTime(headLines(stdout, 1)); - expect(requiring).toEqual('Requiring external module ../preload'); - var preload1 = eraseTime(headLines(stdout, 1, 4)); - expect(preload1).toEqual('hello preload!'); - done(err); - } - }); - - it('works with absolute paths, ignoring cwd', function(done) { - runner - .gulp('--cwd flags/require/with-absolute') - .run(cb); - - function cb(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - - var absolute = path.join(__dirname, './fixtures/config/flags/require/preload'); - var requiring = eraseTime(headLines(stdout, 1)); - expect(requiring).toEqual('Requiring external module ' + absolute); - var preload1 = eraseTime(headLines(stdout, 1, 4)); - expect(preload1).toEqual('hello preload!'); - done(err); - } - }); -}); - diff --git a/test/config-flags-series.js b/test/config-flags-series.js index f6145712..b298322a 100644 --- a/test/config-flags-series.js +++ b/test/config-flags-series.js @@ -1,75 +1,60 @@ 'use strict'; var expect = require('expect'); +var exec = require('child_process').exec; 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 sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); -var fixturesDir = path.join(__dirname, 'fixtures/config'); -var runner = require('gulp-test-tools').gulpRunner({ verbose: false }).basedir(fixturesDir); +var baseDir = path.join(__dirname, 'fixtures/config/flags/series'); describe('config: flags.series', function() { - it('Should run in series if `flags.series` is true in .gulp.*', - function(done) { - runner - .chdir('flags/series/t') - .gulp('task1 task2') - .run(cb); + it('Should run in series if `flags.series` is true in .gulp.*', function(done) { + var opts = { cwd: path.join(baseDir, 't') }; + exec(gulp('task1', 'task2'), opts, cb); - function cb(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - - stdout = eraseLapse(eraseTime(skipLines(stdout, 1))); - expect(stdout).toEqual( - 'Starting \'task1\'...\n' + - 'Finished \'task1\' after ?\n' + - 'Starting \'task2\'...\n' + - 'Finished \'task2\' after ?\n' + - '' - ); - done(); - } - }); - - it('Should run in parallel if `flags.series` is false in .gulp.*', - function(done) { - runner - .chdir('flags/series/f') - .gulp('task1 task2') - .run(cb); + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(sliceLines(stdout, 1)).toEqual( + 'Starting \'task1\'...\n' + + 'Finished \'task1\' after ?\n' + + 'Starting \'task2\'...\n' + + 'Finished \'task2\' after ?\n' + + '' + ); + done(); + } + }); - function cb(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); + it('Should run in parallel if `flags.series` is false in .gulp.*', function(done) { + var opts = { cwd: path.join(baseDir, 'f') }; + exec(gulp('task1', 'task2'), opts, cb); - stdout = eraseLapse(eraseTime(skipLines(stdout, 1))); - expect(stdout).toEqual( - 'Starting \'task1\'...\n' + - 'Starting \'task2\'...\n' + - 'Finished \'task2\' after ?\n' + - 'Finished \'task1\' after ?\n' + - '' - ); - done(); - } - }); + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(sliceLines(stdout, 1)).toEqual( + 'Starting \'task1\'...\n' + + 'Starting \'task2\'...\n' + + 'Finished \'task2\' after ?\n' + + 'Finished \'task1\' after ?\n' + + '' + ); + done(); + } + }); it('Should overridden by cli flag: --series', function(done) { - runner - .chdir('flags/series/f') - .gulp('--series', 'task1 task2') - .run(cb); + var opts = { cwd: path.join(baseDir, 'f') }; + exec(gulp('--series', 'task1', 'task2'), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - - stdout = eraseLapse(eraseTime(skipLines(stdout, 1))); - expect(stdout).toEqual( + expect(sliceLines(stdout, 1)).toEqual( 'Starting \'task1\'...\n' + 'Finished \'task1\' after ?\n' + 'Starting \'task2\'...\n' + @@ -81,17 +66,13 @@ describe('config: flags.series', function() { }); it('Should overridden by cli flag: --no-series', function(done) { - runner - .chdir('flags/series/t') - .gulp('--no-series', 'task1 task2') - .run(cb); + var opts = { cwd: path.join(baseDir, 't') }; + exec(gulp('--no-series', 'task1', 'task2'), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - - stdout = eraseLapse(eraseTime(skipLines(stdout, 1))); - expect(stdout).toEqual( + expect(sliceLines(stdout, 1)).toEqual( 'Starting \'task1\'...\n' + 'Starting \'task2\'...\n' + 'Finished \'task2\' after ?\n' + diff --git a/test/config-flags-silent.js b/test/config-flags-silent.js index 4be02492..527bbc8f 100644 --- a/test/config-flags-silent.js +++ b/test/config-flags-silent.js @@ -1,43 +1,36 @@ 'use strict'; var expect = require('expect'); +var exec = require('child_process').exec; 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 fixturesDir = path.join(__dirname, 'fixtures/config'); -var runner = require('gulp-test-tools').gulpRunner().basedir(fixturesDir); +var sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, 'fixtures/config/flags/silent'); describe('config: flags.silent', function() { - it('Should be silent if `flags.silent` is true in .gulp.*', - function(done) { - runner - .chdir('flags/silent/t') - .gulp() - .run(cb); + it('Should be silent if `flags.silent` is true in .gulp.*', function(done) { + var opts = { cwd: path.join(baseDir, 't') }; + exec(gulp(), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(stdout).toEqual(''); done(err); } }); - it('Should not be silent if `flags.silent` is false in .gulp.*', - function(done) { - runner - .chdir('flags/silent/f') - .gulp() - .run(cb); + it('Should not be silent if `flags.silent` is false in .gulp.*', function(done) { + var opts = { cwd: path.join(baseDir, 'f') }; + exec(gulp(), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - stdout = eraseLapse(eraseTime(skipLines(stdout, 1))); - expect(stdout).toEqual( + expect(sliceLines(stdout, 1)).toEqual( 'Starting \'default\'...\n' + 'Finished \'default\' after ?\n' + '' @@ -47,13 +40,11 @@ describe('config: flags.silent', function() { }); it('Should overridden by cli flag: --silent', function(done) { - runner - .chdir('flags/silent/f') - .gulp('--silent') - .run(cb); + var opts = { cwd: path.join(baseDir, 'f') }; + exec(gulp('--silent'), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(stdout).toEqual(''); done(err); @@ -61,16 +52,13 @@ describe('config: flags.silent', function() { }); it('Should overridden by cli flag: --no-silent', function(done) { - runner - .chdir('flags/silent/t') - .gulp('--no-silent') - .run(cb); + var opts = { cwd: path.join(baseDir, 't') }; + exec(gulp('--no-silent'), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - stdout = eraseLapse(eraseTime(skipLines(stdout, 1))); - expect(stdout).toEqual( + expect(sliceLines(stdout, 1)).toEqual( 'Starting \'default\'...\n' + 'Finished \'default\' after ?\n' + '' diff --git a/test/config-flags-sortTasks.js b/test/config-flags-sort-tasks.js similarity index 51% rename from test/config-flags-sortTasks.js rename to test/config-flags-sort-tasks.js index d087dacd..01eada8d 100644 --- a/test/config-flags-sortTasks.js +++ b/test/config-flags-sort-tasks.js @@ -1,90 +1,65 @@ 'use strict'; var expect = require('expect'); +var exec = require('child_process').exec; var path = require('path'); var fs = require('fs'); -var skipLines = require('gulp-test-tools').skipLines; -var eraseTime = require('gulp-test-tools').eraseTime; -var fixturesDir = path.join(__dirname, 'fixtures/config'); +var sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, 'fixtures/config/flags/sortTasks'); var expectedDir = path.join(__dirname, 'expected'); -var runner = require('gulp-test-tools').gulpRunner().basedir(fixturesDir); -describe ('config: flags.sortTasks', function() { +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') - .run(cb); + it('Should sort top tasks in task list when `flags.sortTasks` is true in .gulp.*', function(done) { + var opts = { cwd: path.join(baseDir, 't') }; + exec(gulp('--tasks'), opts, cb); function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-sorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expected = skipLines(expected, 1); - - stdout = eraseTime(skipLines(stdout, 1)); - - expect(stdout).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); expect(stderr).toEqual(''); done(err); } }); - it('Should sort top tasks in task list when `flags.sortTasks` is false in ' + - '.gulp.*', function(done) { - runner - .chdir('flags/sortTasks/f') - .gulp('--tasks') - .run(cb); + it('Should sort top tasks in task list when `flags.sortTasks` is false in .gulp.*', function(done) { + var opts = { cwd: path.join(baseDir, 'f') }; + exec(gulp('--tasks'), opts, cb); function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-unsorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expected = skipLines(expected, 1); - - stdout = eraseTime(skipLines(stdout, 1)); - - expect(stdout).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); expect(stderr).toEqual(''); done(err); } }); it('Should overridden by cli flag: --sort-tasks', function(done) { - runner - .chdir('flags/sortTasks/f') - .gulp('--tasks --sort-tasks') - .run(cb); + var opts = { cwd: path.join(baseDir, 'f') }; + exec(gulp('--tasks', '--sort-tasks'), opts, cb); function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-sorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expected = skipLines(expected, 1); - - stdout = eraseTime(skipLines(stdout, 1)); - - expect(stdout).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); expect(stderr).toEqual(''); done(err); } }); it('Should overridden by cli flag: --no-sort-tasks', function(done) { - runner - .chdir('flags/sortTasks/t') - .gulp('--tasks --no-sort-tasks') - .run(cb); + var opts = { cwd: path.join(baseDir, 't') }; + exec(gulp('--tasks', '--no-sort-tasks'), opts, cb); function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-unsorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - expected = skipLines(expected, 1); - - stdout = eraseTime(skipLines(stdout, 1)); - - expect(stdout).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); expect(stderr).toEqual(''); done(err); } diff --git a/test/config-flags-tasks-depth.js b/test/config-flags-tasks-depth.js new file mode 100644 index 00000000..944766c2 --- /dev/null +++ b/test/config-flags-tasks-depth.js @@ -0,0 +1,41 @@ +'use strict'; + +var expect = require('expect'); +var exec = require('child_process').exec; +var path = require('path'); +var fs = require('fs'); + +var sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, 'fixtures/config/flags/tasksDepth'); +var expectedDir = path.join(__dirname, 'expected'); + +describe('config: flags.tasksDepth', function() { + + it('Should limit depth of task list when `flags.tasksDepth` is specified', function(done) { + var opts = { cwd: baseDir }; + exec(gulp('--tasks'), opts, cb); + + function cb(err, stdout, stderr) { + var filepath = path.join(expectedDir, 'flags-tasks-depth4.txt'); + var expected = fs.readFileSync(filepath, 'utf-8'); + expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); + expect(stderr).toEqual(''); + done(err); + } + }); + + it('Should overridden by cli flag: --tasks-depth', function(done) { + var opts = { cwd: baseDir }; + exec(gulp('--tasks', '--tasks-depth', '2'), opts, cb); + + function cb(err, stdout, stderr) { + var filepath = path.join(expectedDir, 'flags-tasks-depth2.txt'); + var expected = fs.readFileSync(filepath, 'utf-8'); + expect(sliceLines(stdout, 1)).toEqual(sliceLines(expected, 1)); + expect(stderr).toEqual(''); + done(err); + } + }); +}); diff --git a/test/config-flags-tasksDepth.js b/test/config-flags-tasksDepth.js deleted file mode 100644 index 6c915ed1..00000000 --- a/test/config-flags-tasksDepth.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var expect = require('expect'); -var path = require('path'); -var fs = require('fs'); -var skipLines = require('gulp-test-tools').skipLines; -var eraseTime = require('gulp-test-tools').eraseTime; - -var fixturesDir = path.join(__dirname, 'fixtures/config'); -var expectedDir = path.join(__dirname, 'expected'); -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) { - runner - .chdir('flags/tasksDepth') - .gulp('--tasks') - .run(cb); - - function cb(err, stdout, stderr) { - var filepath = path.join(expectedDir, 'flags-tasks-depth4.txt'); - var expected = fs.readFileSync(filepath, 'utf-8'); - expected = skipLines(expected, 1); - - stdout = eraseTime(skipLines(stdout, 1)); - - expect(stdout).toEqual(expected); - expect(stderr).toEqual(''); - done(err); - } - }); - - it('Should overridden by cli flag: --tasks-depth', function(done) { - runner - .chdir('flags/tasksDepth') - .gulp('--tasks', '--tasks-depth 2') - .run(cb); - - function cb(err, stdout, stderr) { - var filepath = path.join(expectedDir, 'flags-tasks-depth2.txt'); - var expected = fs.readFileSync(filepath, 'utf-8'); - expected = skipLines(expected, 1); - - stdout = eraseTime(skipLines(stdout, 1)); - - expect(stdout).toEqual(expected); - expect(stderr).toEqual(''); - done(err); - } - }); -}); diff --git a/test/esm.js b/test/esm.js index bd27094b..52affdab 100644 --- a/test/esm.js +++ b/test/esm.js @@ -1,39 +1,61 @@ 'use strict'; var expect = require('expect'); +var exec = require('child_process').exec; var fs = require('fs'); var path = require('path'); var semver = require('semver'); -var skipLines = require('gulp-test-tools').skipLines; -var eraseTime = require('gulp-test-tools').eraseTime; -var runner = require('gulp-test-tools').gulpRunner; +var os = require('os'); + +var baseDir = path.join(__dirname, '..'); +var sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); var expectedDir = path.join(__dirname, 'expected'); +function shouldSkip() { + switch (os.platform()) { + case 'win32': { + return semver.satisfies(process.version, '^11.2.0') || + (process.env.CI && semver.satisfies(process.version, '10.x.x')); + } + case 'darwin': { + return semver.satisfies(process.version, '>=11.0.0 <11.11.0'); + } + case 'linux': { + return semver.satisfies(process.version, '>=11.2.0 <11.4.0'); + } + } + return semver.satisfies(process.version, '12.8.x || >=12.11.0 <12.18.0 || >=13.0.0 <13.8.0'); +} + describe('ESM', function() { it('prints the task list', function(done) { - if (semver.lt(process.version, '10.15.3')) { + if (shouldSkip()) { this.skip(); } - var options = '--tasks --sort-tasks ' + - '--gulpfile ./test/fixtures/gulpfiles/gulpfile.mjs'; + var options = '--tasks --sort-tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile.mjs'; var trailingLines = 1; if (!semver.satisfies(process.version, '^12.17.0 || >=13.2.0')) { options += ' --experimental-modules'; trailingLines += 2; } - runner({ verbose: false }).gulp(options).run(cb); + var opts = { cwd: baseDir }; + exec(gulp(options), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toMatch(/^(.*ExperimentalWarning: The ESM module loader is experimental\.\n)?$/); + expect(err).toBeNull(); + if (!semver.satisfies(process.version, '^12.20.0 || >=13.14.0')) { + expect(stderr).toMatch('ExperimentalWarning: The ESM module loader is experimental.\n'); + } else { + expect(stderr).toEqual(''); + } var filepath = path.join(expectedDir, 'esm.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - stdout = eraseTime(skipLines(stdout, trailingLines)); - expect(stdout).toEqual(expected); + expect(sliceLines(stdout, trailingLines)).toEqual(expected); done(err); } }); diff --git a/test/execution-errors.js b/test/execution-errors.js index cf4a50ad..35027883 100644 --- a/test/execution-errors.js +++ b/test/execution-errors.js @@ -1,83 +1,90 @@ 'use strict'; var expect = require('expect'); -var eraseTime = require('gulp-test-tools').eraseTime; -var eraseLapse = require('gulp-test-tools').eraseLapse; -var runner = require('gulp-test-tools').gulpRunner; +var exec = require('child_process').exec; var path = require('path'); var os = require('os'); + var tildify = require('../lib/shared/tildify'); +var eraseTime = require('./tool/erase-time'); +var eraseLapse = require('./tool/erase-lapse'); +var sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); + describe('execution error', function() { it('should output an error if a task is not defined', function(done) { - runner({ verbose: false }) - .chdir('test/fixtures/gulpfiles') - .gulp('a') - .run(function(err, stdout, stderr) { - expect(err).toNotEqual(null); - expect(err.code).toEqual(1); - expect(eraseTime(stdout)).toMatch('Using gulpfile '); - expect(eraseTime(stderr)).toEqual( - 'Task never defined: a\n' + - 'To list available tasks, try running: gulp --tasks\n'); - done(); - }); + var opts = { cwd: path.join(__dirname, './fixtures/gulpfiles') }; + exec(gulp('a'), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(err.code).toEqual(1); + expect(eraseTime(stdout)).toMatch('Using gulpfile '); + expect(eraseTime(stderr)).toEqual( + 'Task never defined: a\n' + + 'To list available tasks, try running: gulp --tasks\n'); + done(); + } }); it('should output an error if gulp version is unsupported', function(done) { - runner({ verbose: false }) - .chdir('test/fixtures/errors/bad-gulp-version') - .gulp() - .run(function(err, stdout, stderr) { - expect(err).toNotEqual(null); - expect(err.code).toEqual(1); - expect(eraseTime(stdout)).toEqual(''); - expect(eraseTime(stderr)).toEqual('Unsupported gulp version\n'); - done(); - }); + var opts = { cwd: path.join(__dirname, './fixtures/errors/bad-gulp-version') }; + exec(gulp(), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(err.code).toEqual(1); + expect(eraseTime(stdout)).toEqual(''); + expect(eraseTime(stderr)).toEqual('Unsupported gulp version 1.2.3\n'); + done(); + } }); it('should output an error if gulp is not found', function(done) { - runner({ verbose: false }) - .chdir(os.tmpdir()) - .gulp() - .run(function(err, stdout, stderr) { - expect(err).toNotEqual(null); - expect(err.code).toEqual(1); - expect(eraseTime(stdout)).toEqual(''); - stderr = eraseTime(stderr).split(/[\r\n]+/); - expect(stderr[0]).toMatch('Local gulp not found in '); - expect(stderr[1]).toEqual('Try running: npm install gulp'); - done(); - }); + var tmpdir = os.tmpdir(); + if (os.platform() === 'win32') { + var moveDrive = tmpdir.slice(0, 2); + exec(moveDrive + '& cd ' + tmpdir + ' & ' + gulp(), cb); + } else { + exec(gulp(), { cwd: tmpdir }, cb); + } + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(err.code).toEqual(1); + expect(sliceLines(stderr, 0, 1)).toMatch('Local gulp not found in '); + expect(sliceLines(stderr, 1, 2)).toEqual('Try running: npm install gulp'); + done(); + } }); it('should log a same error once', function(done) { var dir = path.join(__dirname, 'fixtures/gulpfiles'); var gulpfileName = 'gulpfile-dedup-errorlog.js'; - runner({ verbose: false }) - .chdir(dir) - .gulp('--gulpfile', gulpfileName) - .run(function(err, stdout, stderr) { - expect(err).toNotEqual(null); - expect(err.code).toEqual(1); - stdout = eraseLapse(eraseTime(stdout)); - expect(stdout).toEqual( - 'Using gulpfile ' + tildify(path.join(dir, gulpfileName)) + '\n' + - 'Starting \'default\'...\n' + - 'Starting \'b\'...\n' + - 'Starting \'a\'...\n' + - ''); - stderr = eraseLapse(eraseTime(stderr)).split(/[\r\n]+/); - var n = stderr.length; - expect(stderr[0]).toEqual('\'a\' errored after ?'); - expect(stderr[1]).toEqual('Error: Task \'a\' failed!'); - expect(stderr[n - 3]).toEqual('\'b\' errored after ?'); - expect(stderr[n - 2]).toEqual('\'default\' errored after ?'); - expect(stderr[n - 1]).toEqual(''); - done(); - }); + + exec(gulp( + '--gulpfile', gulpfileName + ), { cwd: dir }, cb); + + function cb(err, stdout, stderr) { + expect(err).not.toBeNull(); + expect(err.code).toEqual(1); + expect(sliceLines(stdout)).toEqual( + 'Using gulpfile ' + tildify(path.join(dir, gulpfileName)) + '\n' + + 'Starting \'default\'...\n' + + 'Starting \'b\'...\n' + + 'Starting \'a\'...\n' + + ''); + stderr = eraseLapse(eraseTime(stderr)).split(/[\r\n]+/); + var n = stderr.length; + expect(stderr[0]).toEqual('\'a\' errored after ?'); + expect(stderr[1]).toEqual('Error: Task \'a\' failed!'); + expect(stderr[n - 3]).toEqual('\'b\' errored after ?'); + expect(stderr[n - 2]).toEqual('\'default\' errored after ?'); + expect(stderr[n - 1]).toEqual(''); + done(); + } }); }); - diff --git a/test/expected/config/output2.txt b/test/expected/config/output2.txt new file mode 100644 index 00000000..a0d45083 --- /dev/null +++ b/test/expected/config/output2.txt @@ -0,0 +1,2 @@ +DESCRIPTION BY .gulp.babel.js in directory foo/bar/quux +└── default diff --git a/test/expected/flags-help.txt b/test/expected/flags-help.txt index eb275983..fed71d76 100644 --- a/test/expected/flags-help.txt +++ b/test/expected/flags-help.txt @@ -2,37 +2,41 @@ Usage: gulp [options] tasks Options: - --help, -h Show this help. [boolean] - --version, -v Print the global and local gulp versions. [boolean] - --require Will require a module before running the gulpfile. - This is useful for transpilers but also has other - applications. [string] - --gulpfile, -f Manually set path of gulpfile. Useful if you have - multiple gulpfiles. This will set the CWD to the - gulpfile directory as well. [string] - --cwd Manually set the CWD. The search for the gulpfile, as - well as the relativity of all requires will be from - here. [string] - --verify Will verify plugins referenced in project's - package.json against the plugins blacklist. - --tasks, -T Print the task dependency tree for the loaded - gulpfile. [boolean] - --tasks-simple Print a plaintext list of tasks for the loaded - gulpfile. [boolean] - --tasks-json Print the task dependency tree, in JSON format, for - the loaded gulpfile. - --tasks-depth, --depth Specify the depth of the task dependency tree.[number] - --compact-tasks Reduce the output of task dependency tree by printing - only top tasks and their child tasks. [boolean] - --sort-tasks Will sort top tasks of task dependency tree. [boolean] - --color Will force gulp and gulp plugins to display colors, - even when no color support is detected. [boolean] - --no-color Will force gulp and gulp plugins to not display - colors, even when color support is detected. [boolean] - --silent, -S Suppress all gulp logging. [boolean] - --continue Continue execution of tasks upon failure. [boolean] - --series Run tasks given on the CLI in series (the default is - parallel). [boolean] - --log-level, -L Set the loglevel. -L for least verbose and -LLLL for - most verbose. -LLL is default. [count] - + -h, --help Show this help. [boolean] + -v, --version Print the global and local gulp versions.[boolean] + --preload Will preload a module before running the gulpfile. + This is useful for transpilers but also has other + applications. [string] + -f, --gulpfile Manually set path of gulpfile. Useful if you have + multiple gulpfiles. This will set the CWD to the + gulpfile directory as well. [string] + --cwd Manually set the CWD. The search for the gulpfile, + as well as the relativity of all requires will be + from here. [string] + --verify Will verify plugins referenced in project's + package.json against the plugins blacklist. + -T, --tasks Print the task dependency tree for the loaded + gulpfile. [boolean] + --tasks-simple Print a plaintext list of tasks for the loaded + gulpfile. [boolean] + --tasks-json Print the task dependency tree, in JSON format, + for the loaded gulpfile. + --tasks-depth, --depth Specify the depth of the task dependency tree. + [number] + --compact-tasks Reduce the output of task dependency tree by + printing only top tasks and their child tasks. + [boolean] + --sort-tasks Will sort top tasks of task dependency tree. + [boolean] + --color Will force gulp and gulp plugins to display + colors, even when no color support is detected. + [boolean] + --no-color Will force gulp and gulp plugins to not display + colors, even when color support is detected. + [boolean] + -S, --silent Suppress all gulp logging. [boolean] + --continue Continue execution of tasks upon failure.[boolean] + --series Run tasks given on the CLI in series (the default + is parallel). [boolean] + -L, --log-level Set the loglevel. -L for least verbose and -LLLL + for most verbose. -LLL is default. [count] diff --git a/test/expected/with-desc-and-flags.txt b/test/expected/with-desc-and-flags.txt index 6d65313d..34e85d2c 100644 --- a/test/expected/with-desc-and-flags.txt +++ b/test/expected/with-desc-and-flags.txt @@ -1,6 +1,6 @@ gulp-cli/test/fixtures ├─┬ build Build all the things! -│ │ --dev …un-minified +│ │ --dev │ │ --production …compressed into single bundle │ └─┬ │ ├── clean diff --git a/test/exports-as-tasks.js b/test/exports-as-tasks.js index b94ff0e5..81bee75e 100644 --- a/test/exports-as-tasks.js +++ b/test/exports-as-tasks.js @@ -1,12 +1,14 @@ 'use strict'; var expect = require('expect'); +var exec = require('child_process').exec; var fs = require('fs'); 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 sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, '..'); var expectedDir = path.join(__dirname, 'expected'); // Long timeout is required because parse time is slow @@ -14,19 +16,20 @@ describe('exports as tasks', function() { this.timeout(0); it('prints the task list', function(done) { - runner({ verbose: false }) - .gulp('--tasks', '--sort-tasks', - '--gulpfile ./test/fixtures/gulpfiles/gulpfile-exports.babel.js') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--tasks', + '--sort-tasks', + '--gulpfile', './test/fixtures/gulpfiles/gulpfile-exports.babel.js' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'tasks-as-exports.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); // Remove babel/register lines - stdout = eraseTime(skipLines(stdout, 2)); - expect(stdout).toEqual(expected); + expect(sliceLines(stdout, 2)).toEqual(expected); done(err); } }); diff --git a/test/fixtures/.babelrc b/test/fixtures/.babelrc deleted file mode 100644 index c13c5f62..00000000 --- a/test/fixtures/.babelrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "presets": ["es2015"] -} diff --git a/test/fixtures/config/flags/gulpfile/.gulp.json b/test/fixtures/config/flags/gulpfile/.gulp.json deleted file mode 100644 index b2089dc7..00000000 --- a/test/fixtures/config/flags/gulpfile/.gulp.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "flags": { - "gulpfile": "./is/here/mygulpfile.js" - } -} diff --git a/test/fixtures/config/flags/gulpfile/autoload-fail/.gulp.json b/test/fixtures/config/flags/gulpfile/autoload-fail/.gulp.json new file mode 100644 index 00000000..10707925 --- /dev/null +++ b/test/fixtures/config/flags/gulpfile/autoload-fail/.gulp.json @@ -0,0 +1,5 @@ +{ + "flags": { + "gulpfile": "./other_dir/gulpfile.coffee" + } +} diff --git a/test/fixtures/config/flags/gulpfile/autoload-fail/other_dir/gulpfile.coffee b/test/fixtures/config/flags/gulpfile/autoload-fail/other_dir/gulpfile.coffee new file mode 100644 index 00000000..1f8b8541 --- /dev/null +++ b/test/fixtures/config/flags/gulpfile/autoload-fail/other_dir/gulpfile.coffee @@ -0,0 +1 @@ +console.log 'hello' diff --git a/test/fixtures/config/flags/gulpfile/cwd/.gulp.json b/test/fixtures/config/flags/gulpfile/cwd/.gulp.json new file mode 100644 index 00000000..231d1a67 --- /dev/null +++ b/test/fixtures/config/flags/gulpfile/cwd/.gulp.json @@ -0,0 +1,5 @@ +{ + "flags": { + "gulpfile": "../is/here/gulpfile-by-cwd-cfg.js" + } +} diff --git a/test/fixtures/config/flags/gulpfile/cwd/findup/.gitkeep b/test/fixtures/config/flags/gulpfile/cwd/findup/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/test/fixtures/config/flags/gulpfile/cwd/gulpfile.js b/test/fixtures/config/flags/gulpfile/cwd/gulpfile.js deleted file mode 100644 index 3b6476b6..00000000 --- a/test/fixtures/config/flags/gulpfile/cwd/gulpfile.js +++ /dev/null @@ -1,8 +0,0 @@ -'use strict'; - -var gulp = require('gulp'); - -gulp.task('default', function(done) { - console.log('Another gulpfile : ' + __filename); - done(); -}); diff --git a/test/fixtures/config/flags/gulpfile/is/here/mygulpfile.js b/test/fixtures/config/flags/gulpfile/is/here/gulpfile-by-cwd-cfg.js similarity index 100% rename from test/fixtures/config/flags/gulpfile/is/here/mygulpfile.js rename to test/fixtures/config/flags/gulpfile/is/here/gulpfile-by-cwd-cfg.js diff --git a/test/fixtures/config/flags/gulpfile/is/here/gulpfile-by-prj-cfg.js b/test/fixtures/config/flags/gulpfile/is/here/gulpfile-by-prj-cfg.js new file mode 100644 index 00000000..61b4199a --- /dev/null +++ b/test/fixtures/config/flags/gulpfile/is/here/gulpfile-by-prj-cfg.js @@ -0,0 +1,9 @@ +'use strict'; + +var gulp = require('gulp'); + +gulp.task('default', function(done) { + console.log('This gulpfile : ' + __filename); + console.log('The current directory : ' + process.cwd()); + done(); +}); diff --git a/test/fixtures/config/flags/gulpfile/is/here/gulpfile.js b/test/fixtures/config/flags/gulpfile/is/here/gulpfile.js new file mode 100644 index 00000000..61b4199a --- /dev/null +++ b/test/fixtures/config/flags/gulpfile/is/here/gulpfile.js @@ -0,0 +1,9 @@ +'use strict'; + +var gulp = require('gulp'); + +gulp.task('default', function(done) { + console.log('This gulpfile : ' + __filename); + console.log('The current directory : ' + process.cwd()); + done(); +}); diff --git a/test/fixtures/config/flags/gulpfile/prj/.gulp.json b/test/fixtures/config/flags/gulpfile/prj/.gulp.json new file mode 100644 index 00000000..64535ec4 --- /dev/null +++ b/test/fixtures/config/flags/gulpfile/prj/.gulp.json @@ -0,0 +1,5 @@ +{ + "flags": { + "gulpfile": "../is/here/gulpfile-by-prj-cfg.js" + } +} diff --git a/test/fixtures/config/flags/gulpfile/prj/findup/.gitkeep b/test/fixtures/config/flags/gulpfile/prj/findup/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/test/fixtures/config/flags/require/array/.gulp.json b/test/fixtures/config/flags/preload/array/.gulp.json similarity index 80% rename from test/fixtures/config/flags/require/array/.gulp.json rename to test/fixtures/config/flags/preload/array/.gulp.json index 42aaa0da..0031374c 100644 --- a/test/fixtures/config/flags/require/array/.gulp.json +++ b/test/fixtures/config/flags/preload/array/.gulp.json @@ -1,6 +1,6 @@ { "flags": { - "require": [ + "preload": [ "./preload_one", "./preload_two" ] diff --git a/test/fixtures/config/flags/require/array/gulpfile.js b/test/fixtures/config/flags/preload/array/gulpfile.js similarity index 100% rename from test/fixtures/config/flags/require/array/gulpfile.js rename to test/fixtures/config/flags/preload/array/gulpfile.js diff --git a/test/fixtures/config/flags/require/array/preload_one.js b/test/fixtures/config/flags/preload/array/preload_one.js similarity index 100% rename from test/fixtures/config/flags/require/array/preload_one.js rename to test/fixtures/config/flags/preload/array/preload_one.js diff --git a/test/fixtures/config/flags/require/array/preload_two.js b/test/fixtures/config/flags/preload/array/preload_two.js similarity index 100% rename from test/fixtures/config/flags/require/array/preload_two.js rename to test/fixtures/config/flags/preload/array/preload_two.js diff --git a/test/fixtures/config/flags/require/join-flags/.gulp.json b/test/fixtures/config/flags/preload/join-flags/.gulp.json similarity index 74% rename from test/fixtures/config/flags/require/join-flags/.gulp.json rename to test/fixtures/config/flags/preload/join-flags/.gulp.json index 61f4f87a..83d17ccf 100644 --- a/test/fixtures/config/flags/require/join-flags/.gulp.json +++ b/test/fixtures/config/flags/preload/join-flags/.gulp.json @@ -1,6 +1,6 @@ { "flags": { - "require": [ + "preload": [ "./preload_two" ] } diff --git a/test/fixtures/config/flags/require/join-flags/gulpfile.js b/test/fixtures/config/flags/preload/join-flags/gulpfile.js similarity index 100% rename from test/fixtures/config/flags/require/join-flags/gulpfile.js rename to test/fixtures/config/flags/preload/join-flags/gulpfile.js diff --git a/test/fixtures/config/flags/require/join-flags/preload_one.js b/test/fixtures/config/flags/preload/join-flags/preload_one.js similarity index 100% rename from test/fixtures/config/flags/require/join-flags/preload_one.js rename to test/fixtures/config/flags/preload/join-flags/preload_one.js diff --git a/test/fixtures/config/flags/require/join-flags/preload_two.js b/test/fixtures/config/flags/preload/join-flags/preload_two.js similarity index 100% rename from test/fixtures/config/flags/require/join-flags/preload_two.js rename to test/fixtures/config/flags/preload/join-flags/preload_two.js diff --git a/test/fixtures/config/flags/require/preload.js b/test/fixtures/config/flags/preload/preload.js similarity index 100% rename from test/fixtures/config/flags/require/preload.js rename to test/fixtures/config/flags/preload/preload.js diff --git a/test/fixtures/config/flags/preload/string/.gulp.json b/test/fixtures/config/flags/preload/string/.gulp.json new file mode 100644 index 00000000..9b061f1f --- /dev/null +++ b/test/fixtures/config/flags/preload/string/.gulp.json @@ -0,0 +1,5 @@ +{ + "flags": { + "preload": "./preload" + } +} diff --git a/test/fixtures/config/flags/require/string/gulpfile.js b/test/fixtures/config/flags/preload/string/gulpfile.js similarity index 100% rename from test/fixtures/config/flags/require/string/gulpfile.js rename to test/fixtures/config/flags/preload/string/gulpfile.js diff --git a/test/fixtures/config/flags/require/string/preload.js b/test/fixtures/config/flags/preload/string/preload.js similarity index 100% rename from test/fixtures/config/flags/require/string/preload.js rename to test/fixtures/config/flags/preload/string/preload.js diff --git a/test/fixtures/config/flags/require/with-absolute/.gulp.js b/test/fixtures/config/flags/preload/with-absolute/.gulp.js similarity index 57% rename from test/fixtures/config/flags/require/with-absolute/.gulp.js rename to test/fixtures/config/flags/preload/with-absolute/.gulp.js index 007b399b..c0e29e8a 100644 --- a/test/fixtures/config/flags/require/with-absolute/.gulp.js +++ b/test/fixtures/config/flags/preload/with-absolute/.gulp.js @@ -2,6 +2,6 @@ var path = require('path'); module.exports = { flags: { - require: path.join(__dirname, '../preload'), + preload: path.join(__dirname, '../preload'), }, }; diff --git a/test/fixtures/config/flags/require/with-absolute/gulpfile.js b/test/fixtures/config/flags/preload/with-absolute/gulpfile.js similarity index 100% rename from test/fixtures/config/flags/require/with-absolute/gulpfile.js rename to test/fixtures/config/flags/preload/with-absolute/gulpfile.js diff --git a/test/fixtures/config/flags/preload/with-cwd/.gulp.json b/test/fixtures/config/flags/preload/with-cwd/.gulp.json new file mode 100644 index 00000000..d43feab5 --- /dev/null +++ b/test/fixtures/config/flags/preload/with-cwd/.gulp.json @@ -0,0 +1,5 @@ +{ + "flags": { + "preload": "../preload" + } +} diff --git a/test/fixtures/config/flags/require/with-cwd/gulpfile.js b/test/fixtures/config/flags/preload/with-cwd/gulpfile.js similarity index 100% rename from test/fixtures/config/flags/require/with-cwd/gulpfile.js rename to test/fixtures/config/flags/preload/with-cwd/gulpfile.js diff --git a/test/fixtures/config/flags/require/string/.gulp.json b/test/fixtures/config/flags/require/string/.gulp.json deleted file mode 100644 index 3fbb4b37..00000000 --- a/test/fixtures/config/flags/require/string/.gulp.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "flags": { - "require": "./preload" - } -} diff --git a/test/fixtures/config/flags/require/with-cwd/.gulp.json b/test/fixtures/config/flags/require/with-cwd/.gulp.json deleted file mode 100644 index 743fb112..00000000 --- a/test/fixtures/config/flags/require/with-cwd/.gulp.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "flags": { - "require": "../preload" - } -} diff --git a/test/fixtures/config/foo/bar/baz/.gitkeep b/test/fixtures/config/foo/bar/baz/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/test/fixtures/config/foo/bar/baz/.gulp.babel.js b/test/fixtures/config/foo/bar/quux/.gulp.babel.js similarity index 66% rename from test/fixtures/config/foo/bar/baz/.gulp.babel.js rename to test/fixtures/config/foo/bar/quux/.gulp.babel.js index 4e6e98c4..92986942 100644 --- a/test/fixtures/config/foo/bar/baz/.gulp.babel.js +++ b/test/fixtures/config/foo/bar/quux/.gulp.babel.js @@ -1,3 +1 @@ -// jscs:disable - -exports.description = 'DESCRIPTION BY .gulp.babel.js in directory foo/bar/baz' +exports.description = 'DESCRIPTION BY .gulp.babel.js in directory foo/bar/quux' diff --git a/test/fixtures/gulpfiles/with-desc-and-flags.js b/test/fixtures/gulpfiles/with-desc-and-flags.js index 5b2792c2..8a6937f4 100644 --- a/test/fixtures/gulpfiles/with-desc-and-flags.js +++ b/test/fixtures/gulpfiles/with-desc-and-flags.js @@ -17,7 +17,7 @@ gulp.task('styles').description = 'Compiles and bundles CSS'; var build = gulp.series('clean', 'scripts', 'styles'); build.description = 'Build all the things!'; build.flags = { - '--dev': 'un-minified', + '--dev': '', '--production': 'compressed into single bundle', '': 'dummy-empty-string', }; diff --git a/test/fixtures/logging.js b/test/fixtures/logging.js index 705b482a..aff166e0 100644 --- a/test/fixtures/logging.js +++ b/test/fixtures/logging.js @@ -1,10 +1,7 @@ var log = require('gulplog'); -var yargs = require('yargs'); var toConsole = require('../../lib/shared/log/to-console'); -var cliOptions = require('../../lib/shared/cli-options'); -var parser = yargs.usage('', cliOptions); -var opts = parser.argv; +var opts = require('../../lib/shared/options/parser').argv; toConsole(log, opts); diff --git a/test/flags-continue.js b/test/flags-continue.js index fbfe644a..cbf8a94f 100644 --- a/test/flags-continue.js +++ b/test/flags-continue.js @@ -1,32 +1,34 @@ 'use strict'; var expect = require('expect'); -var runner = require('gulp-test-tools').gulpRunner; -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 exec = require('child_process').exec; +var path = require('path'); + +var sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, '..'); describe('flag: --continue', function() { it('continues execution when flag is set', function(done) { - runner({ verbose: false }) - .gulp('test4', '--continue', '--cwd ./test/fixtures/gulpfiles') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + 'test4', + '--continue', + '--cwd ./test/fixtures/gulpfiles' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); - stdout = eraseLapse(eraseTime(skipLines(stdout, 2))); - expect(stdout).toEqual( + expect(err).not.toBeNull(); + expect(sliceLines(stdout, 2)).toEqual( 'Starting \'test4\'...\n' + 'Starting \'errorFunction\'...\n' + 'Starting \'anon\'...\n' + 'Finished \'anon\' after ?\n' + '' ); - - stderr = eraseLapse(eraseTime(headLines(stderr, 2))); - expect(stderr).toEqual( + expect(sliceLines(stderr, 0, 2)).toEqual( '\'errorFunction\' errored after ?\n' + 'Error: Error!' ); @@ -35,22 +37,19 @@ describe('flag: --continue', function() { }); it('stops execution when flag is not set', function(done) { - runner({ verbose: false }) - .gulp('test4', '--cwd ./test/fixtures/gulpfiles') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp('test4', '--cwd ./test/fixtures/gulpfiles'), opts, cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); - expect(stdout).toNotMatch('Starting \'anon\''); - stdout = eraseLapse(eraseTime(skipLines(stdout, 2))); + expect(err).not.toBeNull(); + expect(stdout).not.toMatch('Starting \'anon\''); + stdout = sliceLines(stdout, 2); expect(stdout).toEqual( 'Starting \'test4\'...\n' + 'Starting \'errorFunction\'...\n' + '' ); - - stderr = eraseLapse(eraseTime(headLines(stderr, 2))); - expect(stderr).toEqual( + expect(sliceLines(stderr, 0, 2)).toEqual( '\'errorFunction\' errored after ?\n' + 'Error: Error!' ); diff --git a/test/flags-gulpfile.js b/test/flags-gulpfile.js index 876f7f9c..7c9316b7 100644 --- a/test/flags-gulpfile.js +++ b/test/flags-gulpfile.js @@ -1,32 +1,32 @@ 'use strict'; var expect = require('expect'); -var runner = require('gulp-test-tools').gulpRunner; -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 exec = require('child_process').exec; var path = require('path'); +var sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, '..'); + describe('flag: --gulpfile', function() { it('Manually set path of gulpfile using --gulpfile', function(done) { var gulpfilePath = 'test/fixtures/gulpfiles/gulpfile-2.js'; - runner({ verbose: false }) - .gulp('--gulpfile', gulpfilePath) - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp('--gulpfile', gulpfilePath), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - var chgWorkdirLog = headLines(stdout, 1); + var chgWorkdirLog = sliceLines(stdout, 0, 1); 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 = sliceLines(stdout, 2); expect(stdout).toEqual( 'Starting \'default\'...\n' + 'Starting \'logGulpfilePath\'...\n' + @@ -42,20 +42,19 @@ describe('flag: --gulpfile', function() { it('Manually set path of gulpfile using -f', function(done) { var gulpfilePath = 'test/fixtures/gulpfiles/gulpfile-2.js'; - runner({ verbose: false }) - .gulp('-f', gulpfilePath) - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp('-f', gulpfilePath), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - var chgWorkdirLog = headLines(stdout, 1); + var chgWorkdirLog = sliceLines(stdout, 0, 1); 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 = sliceLines(stdout, 2); expect(stdout).toEqual( 'Starting \'default\'...\n' + 'Starting \'logGulpfilePath\'...\n' + diff --git a/test/flags-help.js b/test/flags-help.js index e781665b..b1947b41 100644 --- a/test/flags-help.js +++ b/test/flags-help.js @@ -1,58 +1,58 @@ 'use strict'; var expect = require('expect'); -var runner = require('gulp-test-tools').gulpRunner; - +var exec = require('child_process').exec; 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 gulp = require('./tool/gulp-cmd'); +var baseDir = path.join(__dirname, '..'); 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') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--help', + '--cwd ./test/fixtures/gulpfiles' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - stdout = eraseFirstSpace(stdout); expect(stdout).toEqual(outputText); done(err); } }); it('shows help using short --h', function(done) { - runner({ verbose: false }) - .gulp('--h', '--cwd ./test/fixtures/gulpfiles') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--h', + '--cwd ./test/fixtures/gulpfiles' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - stdout = eraseFirstSpace(stdout); expect(stdout).toEqual(outputText); done(err); } }); it('avoids printing "Requiring external module *"', function(done) { - runner({ verbose: false }) - .gulp('--help --gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--help', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - stdout = eraseFirstSpace(stdout); expect(stdout).toEqual(outputText); done(err); } diff --git a/test/flags-preload.js b/test/flags-preload.js new file mode 100644 index 00000000..8a666ddc --- /dev/null +++ b/test/flags-preload.js @@ -0,0 +1,157 @@ +'use strict'; + +var expect = require('expect'); +var exec = require('child_process').exec; +var path = require('path'); + +var sliceLines = require('./tool/slice-lines'); +var eraseTime = require('./tool/erase-time'); +var eraseLapse = require('./tool/erase-lapse'); +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, '..'); + +describe('flag: --preload', function() { + + it('preloads module before running gulpfile', function(done) { + var opts = { cwd: baseDir }; + exec(gulp( + '--preload ../test-module.js', + '--cwd ./test/fixtures/gulpfiles' + ), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(sliceLines(stdout, 0, 1)).toEqual('Preloading external module: ../test-module.js'); + expect(sliceLines(stdout, 1, 2)).toEqual('inside test module'); + expect(sliceLines(stdout, 2, 3)).toEqual('Preloaded external module: ../test-module.js'); + + var chgWorkdirLog = sliceLines(stdout, 3, 4); + var workdir = 'test/fixtures/gulpfiles'.replace(/\//g, path.sep); + expect(chgWorkdirLog).toMatch('Working directory changed to '); + expect(chgWorkdirLog).toMatch(workdir); + + stdout = sliceLines(stdout, 5); + expect(stdout).toEqual( + 'Starting \'default\'...\n' + + 'Starting \'test1\'...\n' + + 'Starting \'noop\'...\n' + + 'Finished \'noop\' after ?\n' + + 'Finished \'test1\' after ?\n' + + 'Starting \'test3\'...\n' + + 'Starting \'described\'...\n' + + 'Finished \'described\' after ?\n' + + 'Finished \'test3\' after ?\n' + + 'Starting \'noop\'...\n' + + 'Finished \'noop\' after ?\n' + + 'Finished \'default\' after ?\n' + + '' + ); + done(err); + } + }); + + it('can preload multiple modules before running gulpfile', function(done) { + var opts = { cwd: baseDir }; + exec(gulp( + '--preload ../test-module.js', + '--preload ../test-module-2.js', + '--cwd ./test/fixtures/gulpfiles' + ), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(sliceLines(stdout, 0, 1)).toEqual('Preloading external module: ../test-module.js'); + expect(sliceLines(stdout, 1, 2)).toEqual('inside test module'); + expect(sliceLines(stdout, 2, 3)).toEqual('Preloaded external module: ../test-module.js'); + expect(sliceLines(stdout, 3, 4)).toEqual('Preloading external module: ../test-module-2.js'); + expect(sliceLines(stdout, 4, 5)).toEqual('inside test module 2'); + expect(sliceLines(stdout, 5, 6)).toEqual('Preloaded external module: ../test-module-2.js'); + done(err); + } + }); + + it('warns if module doesn\'t exist', function(done) { + var opts = { cwd: baseDir }; + exec(gulp( + '--preload ./null-module.js', + '--cwd ./test/fixtures/gulpfiles' + ), opts, cb); + + function cb(err, stdout, stderr) { + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(sliceLines(stdout, 0, 2)).toEqual( + 'Preloading external module: ./null-module.js\n' + + 'Failed to preload external module: ./null-module.js' + ); + expect(sliceLines(stdout, 2, 3)).toMatch('Error: Cannot find module \'./null-module.js\''); + + var chgWorkdirLog = sliceLines(stdout, 3, 4); + var workdir = 'test/fixtures/gulpfiles'.replace(/\//g, path.sep); + expect(chgWorkdirLog).toMatch('Working directory changed to '); + expect(chgWorkdirLog).toMatch(workdir); + + expect(sliceLines(stdout, 5)).toEqual( + 'Starting \'default\'...\n' + + 'Starting \'test1\'...\n' + + 'Starting \'noop\'...\n' + + 'Finished \'noop\' after ?\n' + + 'Finished \'test1\' after ?\n' + + 'Starting \'test3\'...\n' + + 'Starting \'described\'...\n' + + 'Finished \'described\' after ?\n' + + 'Finished \'test3\' after ?\n' + + 'Starting \'noop\'...\n' + + 'Finished \'noop\' after ?\n' + + 'Finished \'default\' after ?\n' + + '' + ); + + done(err); + } + }); + + it('warns if module throw some error', function(done) { + var opts = { cwd: baseDir }; + exec(gulp( + '--preload ../test-error-module.js', + '--cwd ./test/fixtures/gulpfiles' + ), opts, cb); + + function cb(err, stdout, stderr) { + stdout = eraseLapse(eraseTime(stdout)); + expect(err).toBeNull(); + expect(stderr).toEqual(''); + expect(sliceLines(stdout, 1, 2)).toEqual('Failed to preload external module: ../test-error-module.js'); + expect(sliceLines(stdout, 2, 3)).toMatch('Error: from error module'); + expect(stdout).not.toMatch('inside error module'); + + var chgWorkdirLog = sliceLines(stdout, 3, 4); + var workdir = 'test/fixtures/gulpfiles'.replace(/\//g, path.sep); + expect(chgWorkdirLog).toMatch('Working directory changed to '); + expect(chgWorkdirLog).toMatch(workdir); + + expect(sliceLines(stdout, 5)).toEqual( + 'Starting \'default\'...\n' + + 'Starting \'test1\'...\n' + + 'Starting \'noop\'...\n' + + 'Finished \'noop\' after ?\n' + + 'Finished \'test1\' after ?\n' + + 'Starting \'test3\'...\n' + + 'Starting \'described\'...\n' + + 'Finished \'described\' after ?\n' + + 'Finished \'test3\' after ?\n' + + 'Starting \'noop\'...\n' + + 'Finished \'noop\' after ?\n' + + 'Finished \'default\' after ?\n' + + '' + ); + + done(err); + } + }); + +}); diff --git a/test/flags-require.js b/test/flags-require.js deleted file mode 100644 index 6cfa1d84..00000000 --- a/test/flags-require.js +++ /dev/null @@ -1,158 +0,0 @@ -'use strict'; - -var expect = require('expect'); -var runner = require('gulp-test-tools').gulpRunner; -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 path = require('path'); - -describe('flag: --require', function() { - - it('requires module before running gulpfile', function(done) { - runner({ verbose: false }) - .gulp('--require ../test-module.js', '--cwd ./test/fixtures/gulpfiles') - .run(cb); - - function cb(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - var insideLog = headLines(stdout, 1); - expect(insideLog).toEqual('inside test module'); - - var requireLog = eraseTime(headLines(stdout, 1, 1)); - expect(requireLog).toEqual( - 'Requiring external module ../test-module.js'); - - var chgWorkdirLog = headLines(stdout, 1, 2); - var workdir = 'test/fixtures/gulpfiles'.replace(/\//g, path.sep); - expect(chgWorkdirLog).toMatch('Working directory changed to '); - expect(chgWorkdirLog).toMatch(workdir); - - stdout = eraseLapse(eraseTime(skipLines(stdout, 4))); - expect(stdout).toEqual( - 'Starting \'default\'...\n' + - 'Starting \'test1\'...\n' + - 'Starting \'noop\'...\n' + - 'Finished \'noop\' after ?\n' + - 'Finished \'test1\' after ?\n' + - 'Starting \'test3\'...\n' + - 'Starting \'described\'...\n' + - 'Finished \'described\' after ?\n' + - 'Finished \'test3\' after ?\n' + - 'Starting \'noop\'...\n' + - 'Finished \'noop\' after ?\n' + - 'Finished \'default\' after ?\n' + - '' - ); - done(err); - } - }); - - it('can require multiple modules before running gulpfile', function(done) { - runner({ verbose: false }) - .gulp('--require ../test-module.js', '--require ../test-module-2.js', '--cwd ./test/fixtures/gulpfiles') - .run(cb); - - function cb(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - var insideLog = headLines(stdout, 1); - expect(insideLog).toEqual('inside test module'); - - var requireLog = eraseTime(headLines(stdout, 1, 1)); - expect(requireLog).toEqual( - 'Requiring external module ../test-module.js'); - - var insideLog2 = headLines(stdout, 1, 2); - expect(insideLog2).toEqual('inside test module 2'); - - var requireLog2 = eraseTime(headLines(stdout, 1, 3)); - expect(requireLog2).toEqual( - 'Requiring external module ../test-module-2.js'); - - done(err); - } - }); - - it('warns if module doesn\'t exist', function(done) { - runner({ verbose: false }) - .gulp('--require ./null-module.js', '--cwd ./test/fixtures/gulpfiles') - .run(cb); - - function cb(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - stdout = eraseLapse(eraseTime(stdout)); - expect(stdout).toMatch('Failed to load external module ./null-module.js'); - expect(stdout).toMatch('Error: Cannot find module \'./null-module.js\''); - expect(stdout).toNotMatch('inside test module'); - expect(stdout).toNotMatch('Requiring external module ../test-module.js'); - - var chgWorkdirLog = headLines(stdout, 3); - var workdir = 'test/fixtures/gulpfiles'.replace(/\//g, path.sep); - expect(chgWorkdirLog).toMatch('Working directory changed to '); - expect(chgWorkdirLog).toMatch(workdir); - - stdout = eraseLapse(eraseTime(skipLines(stdout, 4))); - expect(stdout).toEqual( - 'Starting \'default\'...\n' + - 'Starting \'test1\'...\n' + - 'Starting \'noop\'...\n' + - 'Finished \'noop\' after ?\n' + - 'Finished \'test1\' after ?\n' + - 'Starting \'test3\'...\n' + - 'Starting \'described\'...\n' + - 'Finished \'described\' after ?\n' + - 'Finished \'test3\' after ?\n' + - 'Starting \'noop\'...\n' + - 'Finished \'noop\' after ?\n' + - 'Finished \'default\' after ?\n' + - '' - ); - - done(err); - } - }); - - it('warns if module throw some error', function(done) { - runner({ verbose: false }) - .gulp('--require ../test-error-module.js', '--cwd ./test/fixtures/gulpfiles') - .run(cb); - - function cb(err, stdout, stderr) { - stdout = eraseLapse(eraseTime(stdout)); - expect(err).toEqual(null); - expect(stderr).toEqual(''); - expect(stdout).toMatch('Failed to load external module ../test-error-module.js'); - expect(stdout).toMatch('Error: from error module'); - expect(stdout).toNotMatch('inside error module'); - - var chgWorkdirLog = headLines(stdout, 3); - var workdir = 'test/fixtures/gulpfiles'.replace(/\//g, path.sep); - expect(chgWorkdirLog).toMatch('Working directory changed to '); - expect(chgWorkdirLog).toMatch(workdir); - - stdout = eraseLapse(eraseTime(skipLines(stdout, 4))); - expect(stdout).toEqual( - 'Starting \'default\'...\n' + - 'Starting \'test1\'...\n' + - 'Starting \'noop\'...\n' + - 'Finished \'noop\' after ?\n' + - 'Finished \'test1\' after ?\n' + - 'Starting \'test3\'...\n' + - 'Starting \'described\'...\n' + - 'Finished \'described\' after ?\n' + - 'Finished \'test3\' after ?\n' + - 'Starting \'noop\'...\n' + - 'Finished \'noop\' after ?\n' + - 'Finished \'default\' after ?\n' + - '' - ); - - done(err); - } - }); - -}); diff --git a/test/flags-series.js b/test/flags-series.js index 6ab5e694..b4ba6047 100644 --- a/test/flags-series.js +++ b/test/flags-series.js @@ -1,23 +1,28 @@ 'use strict'; var expect = require('expect'); -var runner = require('gulp-test-tools').gulpRunner; -var eraseTime = require('gulp-test-tools').eraseTime; -var eraseLapse = require('gulp-test-tools').eraseLapse; -var skipLines = require('gulp-test-tools').skipLines; +var exec = require('child_process').exec; +var path = require('path'); + +var sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, '..'); describe('flag: --series', function() { it('runs tasks in series when flag is set', function(done) { - runner({ verbose: false }) - .gulp('test5 test6', '--series', '--cwd ./test/fixtures/gulpfiles') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + 'test5 test6', + '--series', + '--cwd ./test/fixtures/gulpfiles' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - stdout = eraseLapse(eraseTime(skipLines(stdout, 2))); - expect(stdout).toEqual( + expect(sliceLines(stdout, 2)).toEqual( 'Starting \'test5\'...\n' + 'Finished \'test5\' after ?\n' + 'Starting \'test6\'...\n' + @@ -29,16 +34,17 @@ describe('flag: --series', function() { }); it('runs tasks in parallel when flag is not set', function(done) { - runner({ verbose: false }) - .gulp('test5 test6', '--cwd ./test/fixtures/gulpfiles') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + 'test5 test6', + '--cwd ./test/fixtures/gulpfiles' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - expect(stdout).toNotMatch('Starting \'anon\''); - stdout = eraseLapse(eraseTime(skipLines(stdout, 2))); - expect(stdout).toEqual( + expect(stdout).not.toMatch('Starting \'anon\''); + expect(sliceLines(stdout, 2)).toEqual( 'Starting \'test5\'...\n' + 'Starting \'test6\'...\n' + 'Finished \'test6\' after ?\n' + diff --git a/test/flags-silent.js b/test/flags-silent.js index 4396b508..c7bc12b0 100644 --- a/test/flags-silent.js +++ b/test/flags-silent.js @@ -1,17 +1,24 @@ 'use strict'; var expect = require('expect'); -var runner = require('gulp-test-tools').gulpRunner; +var exec = require('child_process').exec; +var path = require('path'); + +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, '..'); describe('flag: --silent', function() { it('prints nothing when silent flag is set', function(done) { - runner({ verbose: false }) - .gulp('--silent', '--cwd ./test/fixtures/gulpfiles') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--silent', + '--cwd ./test/fixtures/gulpfiles' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(stdout).toEqual(''); done(err); diff --git a/test/flags-tasks-json.js b/test/flags-tasks-json.js index 27b043d7..5614ac33 100644 --- a/test/flags-tasks-json.js +++ b/test/flags-tasks-json.js @@ -1,23 +1,27 @@ 'use strict'; var expect = require('expect'); +var exec = require('child_process').exec; var fs = require('fs'); var path = require('path'); var rimraf = require('rimraf'); -var skipLines = require('gulp-test-tools').skipLines; -var runner = require('gulp-test-tools').gulpRunner; +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, '..'); var expected = require(path.join(__dirname, 'expected/flags-tasks-json.json')); describe('flag: --tasks-json', function() { it('prints the task list with no args', function(done) { - runner({ verbose: false }) - .gulp('--tasks-json --gulpfile ./test/fixtures/gulpfiles/gulpfile.js') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--tasks-json', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile.js' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(JSON.parse(stdout)).toEqual(expected); done(err); @@ -27,14 +31,16 @@ describe('flag: --tasks-json', function() { it('prints the task list with the default description', function(done) { var cwdPath = __dirname; var gulpfilePath = path.join(__dirname, 'fixtures/gulpfiles/gulpfile.js'); - runner({ verbose: false }) - .gulp('--tasks-json', - '--cwd ', cwdPath, - '--gulpfile ', gulpfilePath) - .run(cb); + + var opts = { cwd: baseDir }; + exec(gulp( + '--tasks-json', + '--cwd ', cwdPath, + '--gulpfile ', gulpfilePath + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); var jsonObj = JSON.parse(stdout); expect(jsonObj.label).toMatch('Tasks for '); @@ -48,15 +54,16 @@ describe('flag: --tasks-json', function() { rimraf.sync(output); fs.mkdirSync(output); - runner({ verbose: false }) - .gulp('--tasks-json ../../output/tasks.json', - '--gulpfile ./test/fixtures/gulpfiles/gulpfile.js') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--tasks-json ../../output/tasks.json', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile.js' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - stdout = skipLines(stdout, 1); + stdout = stdout.split('\n').slice(1).join('\n'); expect(stdout).toEqual(''); var file = fs.readFileSync(path.join(output, '/tasks.json'), 'utf8'); var parsedJson = JSON.parse(file); @@ -70,12 +77,14 @@ describe('flag: --tasks-json', function() { // Disable the timeout for old node versions this.timeout(0); - runner({ verbose: false }) - .gulp('--tasks-json --gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--tasks-json', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(JSON.parse(stdout)).toEqual(expected); done(err); diff --git a/test/flags-tasks-simple.js b/test/flags-tasks-simple.js index a44bd91c..a2f54c22 100644 --- a/test/flags-tasks-simple.js +++ b/test/flags-tasks-simple.js @@ -1,22 +1,27 @@ 'use strict'; var expect = require('expect'); -var runner = require('gulp-test-tools').gulpRunner; +var exec = require('child_process').exec; var path = require('path'); var fs = require('fs'); +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, '..'); var outputFile = path.join(__dirname, 'expected/flags-tasks-simple.txt'); var outputText = fs.readFileSync(outputFile, 'utf8'); describe('flag: --tasks-simple', function() { it('prints the task list in simple format', function(done) { - runner({ verbose: false }) - .gulp('--tasks-simple', '--cwd ./test/fixtures/gulpfiles') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--tasks-simple', + '--cwd ./test/fixtures/gulpfiles' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(stdout).toEqual(outputText); done(err); @@ -27,12 +32,14 @@ describe('flag: --tasks-simple', function() { // Disable the timeout for old node versions this.timeout(0); - runner({ verbose: false }) - .gulp('--tasks-simple --gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--tasks-simple', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(stdout).toEqual(outputText); done(err); diff --git a/test/flags-tasks.js b/test/flags-tasks.js index 10662cc1..4a1c689f 100644 --- a/test/flags-tasks.js +++ b/test/flags-tasks.js @@ -1,149 +1,159 @@ 'use strict'; var expect = require('expect'); +var exec = require('child_process').exec; var fs = require('fs'); 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 sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, '..'); 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') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--tasks', + '--sort-tasks', + '--cwd ./test/fixtures/gulpfiles' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - stdout = eraseTime(skipLines(stdout, 1)); - expect(stdout).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(expected); done(err); } }); it('print the task list with description and flags', function(done) { - runner({ verbose: false }) - .gulp('--tasks', '--sort-tasks', - '--gulpfile ./test/fixtures/gulpfiles/with-desc-and-flags.js', - '--cwd ./test/fixtures') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--tasks', + '--sort-tasks', + '--gulpfile ./test/fixtures/gulpfiles/with-desc-and-flags.js', + '--cwd ./test/fixtures' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); 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)); - expect(stdout).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(expected); done(err); } }); - it('print the task list by gulp.task(s).unwrap and gulp.task(s)', - function(done) { - runner({ verbose: false }) - .gulp('--tasks', '--sort-tasks', - '--gulpfile ./test/fixtures/gulpfiles/by-unwrap-and-not-by-unwrap.js', - '--cwd ./test/fixtures') - .run(cb); + it('print the task list by gulp.task(s).unwrap and gulp.task(s)', function(done) { + var opts = { cwd: baseDir }; + exec(gulp( + '--tasks', + '--sort-tasks', + '--gulpfile ./test/fixtures/gulpfiles/by-unwrap-and-not-by-unwrap.js', + '--cwd ./test/fixtures' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); 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)); - expect(stdout).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(expected); done(err); } }); it('prints the task list without --sort-tasks flag', function(done) { - runner({ verbose: false }) - .gulp('--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--tasks', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks-unsorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - stdout = eraseTime(skipLines(stdout, 1)); - expect(stdout).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(expected); done(err); } }); 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') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--tasks', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', + '--sort-tasks' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks-sorted.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - stdout = eraseTime(skipLines(stdout, 1)); - expect(stdout).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(expected); done(err); } }); 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') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--tasks', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', + '--tasks-depth 4' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks-depth4.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - stdout = eraseTime(skipLines(stdout, 1)); - expect(stdout).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(expected); done(err); } }); it('prints the task list with --depth flag', function(done) { - runner({ verbose: false }) - .gulp('--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', - '--depth 4') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--tasks', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', + '--depth 4' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks-depth4.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - stdout = eraseTime(skipLines(stdout, 1)); - expect(stdout).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(expected); done(err); } }); 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') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--tasks', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', + '--compact-tasks' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); var filepath = path.join(expectedDir, 'flags-tasks-compact.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); - stdout = eraseTime(skipLines(stdout, 1)); - expect(stdout).toEqual(expected); + expect(sliceLines(stdout, 1)).toEqual(expected); done(err); } }); diff --git a/test/flags-v8flags.js b/test/flags-v8flags.js index 1a487980..30dec323 100644 --- a/test/flags-v8flags.js +++ b/test/flags-v8flags.js @@ -1,48 +1,38 @@ 'use strict'; var expect = require('expect'); +var exec = require('child_process').exec; var path = require('path'); -var runner = require('gulp-test-tools').gulpRunner; -var headLines = require('gulp-test-tools').headLines; -var eraseTime = require('gulp-test-tools').eraseTime; +var sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, 'fixtures/gulpfiles'); describe('flags: v8flags', function() { it('Should respawn by a v8flag: --lazy', function(done) { - runner({ verbose: false }) - .chdir(path.join(__dirname, 'fixtures/gulpfiles')) - .gulp('--lazy') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp('--lazy'), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - - var line = eraseTime(headLines(stdout, 1)); - expect(line).toEqual('Node flags detected: --lazy'); - - line = eraseTime(headLines(stdout, 2, 1)); - expect(line).toMatch('Respawned to PID: '); + expect(sliceLines(stdout, 0, 1)).toEqual('Node flags detected: --lazy'); + expect(sliceLines(stdout, 1, 3)).toMatch('Respawned to PID: '); done(err); } }); it('Should respawn by v8flags: --lazy --harmony', function(done) { - runner({ verbose: false }) - .chdir(path.join(__dirname, 'fixtures/gulpfiles')) - .gulp('--lazy --harmony') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp('--lazy --harmony'), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - - var line = eraseTime(headLines(stdout, 1)); - expect(line).toEqual('Node flags detected: --harmony, --lazy'); - - line = eraseTime(headLines(stdout, 2, 1)); - expect(line).toMatch('Respawned to PID: '); + expect(sliceLines(stdout, 0, 1)).toEqual('Node flags detected: --harmony, --lazy'); + expect(sliceLines(stdout, 1, 3)).toMatch('Respawned to PID: '); done(err); } }); diff --git a/test/flags-verify.js b/test/flags-verify.js index bb1dcbc9..b3b6f53c 100644 --- a/test/flags-verify.js +++ b/test/flags-verify.js @@ -1,25 +1,28 @@ 'use strict'; var expect = require('expect'); -var runner = require('gulp-test-tools').gulpRunner; -var eraseTime = require('gulp-test-tools').eraseTime; +var exec = require('child_process').exec; var path = require('path'); +var eraseTime = require('./tool/erase-time'); +var gulp = require('./tool/gulp-cmd'); + +var baseDir = path.join(__dirname, '..'); + describe('flag: --verify', function() { it('dependencies with invalid dependency', function(done) { - runner({ verbose: false }) - .gulp('--verify invalid-package.json', '--cwd ./test/fixtures/verify/') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--verify invalid-package.json', + '--cwd ./test/fixtures/verify/' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); + expect(err).not.toBeNull(); expect(stderr).toEqual(''); - stdout = eraseTime(stdout); - expect(stdout).toEqual( - 'Verifying plugins in ' + - path.resolve('./test/fixtures/verify/invalid-package.json') + - '\n' + + expect(eraseTime(stdout)).toEqual( + 'Verifying plugins in ' + path.resolve('./test/fixtures/verify/invalid-package.json') + '\n' + 'Blacklisted plugins found in this project:\n' + 'gulp-blink: deprecated. use `blink` instead.\n' + '' @@ -29,18 +32,17 @@ describe('flag: --verify', function() { }); it('dependencies with valid dependency', function(done) { - runner({ verbose: false }) - .gulp('--verify valid-package.json', '--cwd ./test/fixtures/verify/') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--verify valid-package.json', + '--cwd ./test/fixtures/verify/' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - stdout = eraseTime(stdout); - expect(stdout).toEqual( - 'Verifying plugins in ' + - path.resolve('./test/fixtures/verify/valid-package.json') + - '\n' + + expect(eraseTime(stdout)).toEqual( + 'Verifying plugins in ' + path.resolve('./test/fixtures/verify/valid-package.json') + '\n' + 'There are no blacklisted plugins in this project\n' + '' ); @@ -49,17 +51,17 @@ describe('flag: --verify', function() { }); it('default args with invalid dependency', function(done) { - runner({ verbose: false }) - .gulp('--verify', '--cwd', path.resolve('./test/fixtures/verify/')) - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--verify', + '--cwd', path.resolve('./test/fixtures/verify/') + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); + expect(err).not.toBeNull(); expect(stderr).toEqual(''); - stdout = eraseTime(stdout); - expect(stdout).toEqual( - 'Verifying plugins in ' + - path.resolve('./test/fixtures/verify/package.json') + '\n' + + expect(eraseTime(stdout)).toEqual( + 'Verifying plugins in ' + path.resolve('./test/fixtures/verify/package.json') + '\n' + 'Blacklisted plugins found in this project:\n' + 'gulp-blink: deprecated. use `blink` instead.\n' + '' diff --git a/test/flags-version.js b/test/flags-version.js index 9ecfc9fc..75105570 100644 --- a/test/flags-version.js +++ b/test/flags-version.js @@ -1,21 +1,27 @@ 'use strict'; var expect = require('expect'); -var runner = require('gulp-test-tools').gulpRunner; +var exec = require('child_process').exec; +var path = require('path'); var os = require('os'); +var gulp = require('./tool/gulp-cmd'); var cliVersion = require('../package.json').version; var gulpVersion = require('gulp/package.json').version; +var baseDir = path.join(__dirname, '..'); + describe('flag: --version', function() { it('prints the version of CLI and local gulp', function(done) { - runner({ verbose: false }) - .gulp('--version --cwd ./test/fixtures/gulpfiles') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--version', + '--cwd ./test/fixtures/gulpfiles' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(stdout).toEqual( 'CLI version: ' + cliVersion + '\n' + @@ -27,12 +33,14 @@ describe('flag: --version', function() { }); it('avoids printing "Requiring external module *"', function(done) { - runner({ verbose: false }) - .gulp('--version --gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js') - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp( + '--version', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js' + ), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(stdout).toEqual( 'CLI version: ' + cliVersion + '\n' + @@ -44,12 +52,11 @@ describe('flag: --version', function() { }); it('should print only CLI version when gulp is not found', function(done) { - runner({ verbose: false }) - .gulp('--version', '--cwd', os.tmpdir()) - .run(cb); + var opts = { cwd: baseDir }; + exec(gulp('--version', '--cwd', os.tmpdir()), opts, cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(stdout).toEqual( 'CLI version: ' + cliVersion + '\n' + diff --git a/test/lib/config-cli-flags.js b/test/lib/config-cli-flags.js index 97f5f236..e70a0d92 100644 --- a/test/lib/config-cli-flags.js +++ b/test/lib/config-cli-flags.js @@ -1,7 +1,7 @@ 'use strict'; var expect = require('expect'); -var mergeConfig = require('../../lib/shared/config/cli-flags'); +var mergeCliOpts = require('../../lib/shared/config/cli-flags'); describe('lib: config/cli-flags', function() { @@ -17,11 +17,12 @@ describe('lib: config/cli-flags', function() { }, }; - var result = mergeConfig(opts, config); + var result = mergeCliOpts(opts, config); expect(result).toEqual({ silent: true, continue: true, }); + expect(result).not.toBe(opts); done(); }); @@ -42,13 +43,14 @@ describe('lib: config/cli-flags', function() { }, }; - var result = mergeConfig(opts, config); + var result = mergeCliOpts(opts, config); expect(result).toEqual({ help: false, depth: 4, silent: true, tasks: false, }); + expect(result).not.toBe(opts); done(); }); @@ -62,13 +64,14 @@ describe('lib: config/cli-flags', function() { var config = {}; - var result = mergeConfig(opts, config); + var result = mergeCliOpts(opts, config); expect(result).toEqual({ help: false, depth: 4, silent: true, tasks: false, }); + expect(result).not.toBe(opts); done(); }); diff --git a/test/lib/config-env-flags.js b/test/lib/config-env-flags.js index 955b13c9..d8062c08 100644 --- a/test/lib/config-env-flags.js +++ b/test/lib/config-env-flags.js @@ -1,7 +1,7 @@ 'use strict'; var expect = require('expect'); -var mergeConfig = require('../../lib/shared/config/env-flags'); +var overrideEnvFlags = require('../../lib/shared/config/env-flags'); describe('lib: config/env-flags', function() { @@ -16,18 +16,25 @@ describe('lib: config/env-flags', function() { }, }; - var result = mergeConfig(env, config, {}); + var result = overrideEnvFlags(env, config, {}); expect(result).toEqual({ configPath: '/path/to/gulpfile', configBase: '/path/to', + config: { + description: 'DESCRIPTION.', + flags: { + silent: true, + }, + }, }); + expect(result).toBe(env); done(); }); it('Should take into account forced gulpfile opts from flags', function(done) { var env = { cwd: '/path/to/cwd', - require: 'preload', + preload: 'preload', configNameSearch: 'configNameSearch', configPath: '/path/of/config/path', configBase: '/path/of/config/base', @@ -41,7 +48,7 @@ describe('lib: config/env-flags', function() { flags: { silent: false, gulpfile: '/path/to/gulpfile', - require: ['a', 'b'], + preload: ['a', 'b'], }, }; @@ -49,24 +56,32 @@ describe('lib: config/env-flags', function() { gulpfile: env.configPath, }; - var result = mergeConfig(env, config, opts); + var result = overrideEnvFlags(env, config, opts); expect(result).toEqual({ cwd: '/path/to/cwd', - require: ['preload', 'a', 'b'], + preload: ['preload', 'a', 'b'], configNameSearch: 'configNameSearch', configPath: '/path/of/config/path', configBase: '/path/of/config/base', modulePath: '/path/of/module/path', modulePackage: { name: 'modulePackage' }, configFiles: { aaa: {} }, + config: { + description: "DESCRIPTION.", + flags: { + gulpfile: "/path/of/config/path", + silent: false, + }, + }, }); + expect(result).toBe(env); done(); }); it('Should not cause error if config is empty', function(done) { var env = { cwd: '/path/to/cwd', - require: 'preload', + preload: 'preload', configNameSearch: 'configNameSearch', configPath: '/path/of/config/path', configBase: '/path/of/config/base', @@ -77,18 +92,21 @@ describe('lib: config/env-flags', function() { var config = {}; - var result = mergeConfig(env, config, {}); + var result = overrideEnvFlags(env, config, {}); expect(result).toEqual({ cwd: '/path/to/cwd', - require: 'preload', + preload: 'preload', configNameSearch: 'configNameSearch', configPath: '/path/of/config/path', configBase: '/path/of/config/base', modulePath: '/path/of/module/path', modulePackage: { name: 'modulePackage' }, configFiles: { aaa: {} }, + config: { + flags: {}, + }, }); + expect(result).toBe(env); done(); }); - }); diff --git a/test/lib/config-load-files.js b/test/lib/config-load-files.js deleted file mode 100644 index 9d94b6fd..00000000 --- a/test/lib/config-load-files.js +++ /dev/null @@ -1,58 +0,0 @@ -'use strict'; - -var expect = require('expect'); -var path = require('path'); -var loadConfigFiles = require('../../lib/shared/config/load-files'); - -var fixturesDir = path.join(__dirname, '../fixtures/config'); - -describe('lib: config/load-files', function() { - - it('Should load config from files', function(done) { - var configFiles = { - a: path.join(fixturesDir, 'foo/bar/.gulp.json'), - b: null, - c: path.join(fixturesDir, 'qux/.gulp.js'), - }; - - var config = loadConfigFiles(configFiles, ['a', 'b', 'c']); - - expect(config).toEqual({ - description: 'description by .gulp.js in directory qux', - }); - done(); - }); - - it('Should load config files in specified order', function(done) { - var configFiles = { - a: path.join(fixturesDir, 'foo/bar/.gulp.json'), - b: null, - c: path.join(fixturesDir, 'qux/.gulp.js'), - }; - - var config = loadConfigFiles(configFiles, ['b', 'c', 'a']); - - expect(config).toEqual({ - description: 'Description by .gulp.json in directory foo/bar', - }); - done(); - }); - - it('Should convert a value of `flags.gulpfile` to absolute path', - function(done) { - var configFiles = { - a: path.join(fixturesDir, 'flags/gulpfile/.gulp.json'), - }; - - var config = loadConfigFiles(configFiles, ['a']); - - expect(config).toEqual({ - flags: { - gulpfile: path.join(fixturesDir, - 'flags/gulpfile/is/here/mygulpfile.js'), - }, - }); - done(); - }); - -}); diff --git a/test/lib/format-hrtime.js b/test/lib/format-hrtime.js new file mode 100644 index 00000000..71eb9989 --- /dev/null +++ b/test/lib/format-hrtime.js @@ -0,0 +1,238 @@ +'use strict'; + +var expect = require('expect'); +var formatHrtime = require('../../lib/shared/log/format-hrtime'); + +describe('format-hrtime', function() { + describe('should convert hrtime to string: unit is "h"', function() { + it('should be no decimal part if integer part greater than 10', function(done) { + expect(formatHrtime([36000, 100])).toEqual('10 h'); + done(); + }); + + it('should round first decimal place if integer part greather than 10', function(done) { + expect(formatHrtime([36123, 100])).toEqual('10 h'); + expect(formatHrtime([37800, 0])).toEqual('11 h'); + done(); + }); + + it('should print until second decimal place if integer part less than 10', function(done) { + expect(formatHrtime([35100, 100])).toEqual('9.75 h'); + done(); + }); + + it('should round third decimal place if integer part less than 10', function(done) { + expect(formatHrtime([35117, 0])).toEqual('9.75 h'); + expect(formatHrtime([35119, 100])).toEqual('9.76 h'); + done(); + }); + + it('should trim last "0" in decimal part', function(done) { + expect(formatHrtime([32761, 100])).toEqual('9.1 h'); + expect(formatHrtime([32725, 100])).toEqual('9.09 h'); + expect(formatHrtime([32414, 100])).toEqual('9 h'); + done(); + }); + + it('should convert minimum hrtime of unit "h" normally', function(done) { + expect(formatHrtime([3600, 0])).toEqual('1 h'); + done(); + }); + + it('should be no larger unit than `h`', function(done) { + expect(formatHrtime([360123, 100])).toEqual('100 h'); + done(); + }); + }); + + describe('should convert hrtime to string: unit is "min"', function() { + it('should be no decimal part if integer part greater than 10', function(done) { + expect(formatHrtime([600, 100])).toEqual('10 min'); + done(); + }); + + it('should round first decimal place if integer part greather than 10', function(done) { + expect(formatHrtime([624, 100])).toEqual('10 min'); + expect(formatHrtime([630, 0])).toEqual('11 min'); + done(); + }); + + it('should print until second decimal place if integer part less than 10', function(done) { + expect(formatHrtime([599, 100])).toEqual('9.98 min'); + done(); + }); + + it('should round third decimal place if integer part less than 10', function(done) { + expect(formatHrtime([585, 29e7])).toEqual('9.75 min'); + expect(formatHrtime([585, 3e8])).toEqual('9.76 min'); + done(); + }); + + it('should trim last "0" in decimal part', function(done) { + expect(formatHrtime([594, 100])).toEqual('9.9 min'); + expect(formatHrtime([540, 100])).toEqual('9 min'); + done(); + }); + + it('should convert minimum hrtime of unit "min" normally', function(done) { + expect(formatHrtime([60, 0])).toEqual('1 min'); + done(); + }); + + it('should convert maximum hrtime of unit "min" normally', function(done) { + expect(formatHrtime([3599, 999999999])).toEqual('60 min'); + done(); + }); + }); + + describe('should convert hrtime to string: unit is "s"', function() { + it('should be no decimal part if integer part greater than 10', function(done) { + expect(formatHrtime([10, 12e7])).toEqual('10 s'); + done(); + }); + + it('should round first decimal place if integer part greather than 10', function(done) { + expect(formatHrtime([10, 4e8])).toEqual('10 s'); + expect(formatHrtime([10, 5e8])).toEqual('11 s'); + done(); + }); + + it('should print until second decimal place if integer part less than 10', function(done) { + expect(formatHrtime([9, 12e7])).toEqual('9.12 s'); + done(); + }); + + it('should round third decimal place if integer part less than 10', function(done) { + expect(formatHrtime([9, 124e6])).toEqual('9.12 s'); + expect(formatHrtime([9, 125e6])).toEqual('9.13 s'); + done(); + }); + + it('should trim last "0" in decimal part', function(done) { + expect(formatHrtime([9, 100e6])).toEqual('9.1 s'); + expect(formatHrtime([9, 0])).toEqual('9 s'); + done(); + }); + + it('should convert minimum hrtime of unit "s" normally', function(done) { + expect(formatHrtime([1, 0])).toEqual('1 s'); + done(); + }); + + it('should convert maximum hrtime of unit "s" normally', function(done) { + expect(formatHrtime([59, 999999999])).toEqual('60 s'); + done(); + }); + }); + + describe('should convert hrtime to string: unit is "ms"', function() { + it('should be no decimal part if integer part greater than 10', function(done) { + expect(formatHrtime([0, 10123456])).toEqual('10 ms'); + done(); + }); + + it('should round first decimal place if integer part greather than 10', function(done) { + expect(formatHrtime([0, 10423456])).toEqual('10 ms'); + expect(formatHrtime([0, 10500000])).toEqual('11 ms'); + done(); + }); + + it('should print until second decimal place if integer part less than 10', function(done) { + expect(formatHrtime([0, 9123456])).toEqual('9.12 ms'); + done(); + }); + + it('should round third decimal place if integer part less than 10', function(done) { + expect(formatHrtime([0, 9124999])).toEqual('9.12 ms'); + expect(formatHrtime([0, 9125000])).toEqual('9.13 ms'); + done(); + }); + + it('should trim last "0" in decimal part', function(done) { + expect(formatHrtime([0, 9100000])).toEqual('9.1 ms'); + expect(formatHrtime([0, 9000000])).toEqual('9 ms'); + done(); + }); + + it('should convert minimum hrtime of unit "ms" normally', function(done) { + expect(formatHrtime([0, 1000000])).toEqual('1 ms'); + done(); + }); + + it('should convert maximum hrtime of unit "ms" normally', function(done) { + expect(formatHrtime([0, 999999999])).toEqual('1000 ms'); + done(); + }); + }); + + describe('should convert hrtime to string: unit is "μs"', function() { + it('should be no decimal part if integer part greater than 10', function(done) { + expect(formatHrtime([0, 10123])).toEqual('10 μs'); + done(); + }); + + it('should round first decimal place if integer part greather than 10', function(done) { + expect(formatHrtime([0, 10423])).toEqual('10 μs'); + expect(formatHrtime([0, 10500])).toEqual('11 μs'); + done(); + }); + + it('should print until second decimal place if integer part less than 10', function(done) { + expect(formatHrtime([0, 9123])).toEqual('9.12 μs'); + done(); + }); + + it('should round third decimal place if integer part less than 10', function(done) { + expect(formatHrtime([0, 9124])).toEqual('9.12 μs'); + expect(formatHrtime([0, 9125])).toEqual('9.13 μs'); + done(); + }); + + it('should trim last "0" in decimal part', function(done) { + expect(formatHrtime([0, 9100])).toEqual('9.1 μs'); + expect(formatHrtime([0, 9000])).toEqual('9 μs'); + done(); + }); + + it('should convert minimum hrtime of unit "μs" normally', function(done) { + expect(formatHrtime([0, 1000])).toEqual('1 μs'); + done(); + }); + + it('should convert maximum hrtime of unit "μs" normally', function(done) { + expect(formatHrtime([0, 999999])).toEqual('1000 μs'); + done(); + }); + }); + + describe('should convert hrtime to string: unit is "ns"', function() { + it('should convert minimum hrtime of unit "μs" normally', function(done) { + expect(formatHrtime([0, 1])).toEqual('1 ns'); + done(); + }); + + it('should convert maximum hrtime of unit "μs" normally', function(done) { + expect(formatHrtime([0, 999])).toEqual('999 ns'); + done(); + }); + }); + + describe('should convert irregular hrtime to an empty string', function() { + it('should convert non hrtime to an empty string', function(done) { + expect(formatHrtime(1234567890)).toEqual(''); + expect(formatHrtime('1234567890')).toEqual(''); + done(); + }); + + it('should convert bad hrtime to an empty string', function(done) { + expect(formatHrtime(['123', 123])).toEqual(''); + expect(formatHrtime([123, '123'])).toEqual(''); + done(); + }); + + it('should covert zero hrtime to an empty string', function(done) { + expect(formatHrtime([0, 0])).toEqual(''); + done(); + }); + }); +}); diff --git a/test/lib/get-remote-json.js b/test/lib/get-remote-json.js new file mode 100644 index 00000000..f610f84a --- /dev/null +++ b/test/lib/get-remote-json.js @@ -0,0 +1,34 @@ +'use strict'; + +var expect = require('expect'); +var getRemoteJson = require('../../lib/shared/blacklist/get-remote-json'); + +describe('lib: blacklist/get-remote-json', function() { + + it('should get normal json', function(done) { + var url = 'https://raw.githubusercontent.com/gulpjs/plugins/master/src/blackList.json'; + getRemoteJson(url, function(err, json) { + expect(err).toBeNull(); + expect(json['gulp-blink']).toEqual('deprecated. use `blink` instead.'); + done(); + }); + }); + + it('should get error when 404', function(done) { + var url = 'https://raw.githubusercontent.com/gulpjs/plugins/master/src/xxx.json'; + getRemoteJson(url, function(err, json) { + expect(err.message).toEqual('Request failed. Status Code: 404'); + expect(json).toBeFalsy(); + done(); + }); + }); + + it('should get error when not json', function(done) { + var url = 'https://raw.githubusercontent.com/gulpjs/plugins/master/src/README.md'; + getRemoteJson(url, function(err, json) { + expect(err.message).toEqual('Invalid Blacklist JSON.'); + expect(json).toBeFalsy(); + done(); + }); + }); +}); diff --git a/test/lib/log-copy-tree.js b/test/lib/log-copy-tree.js index ab646443..4a679a6e 100644 --- a/test/lib/log-copy-tree.js +++ b/test/lib/log-copy-tree.js @@ -16,7 +16,7 @@ describe('lib: copy-tree', function() { var opts = {}; var newTree = copyTree(srcTree, opts, nonConvertingNodeFactory); expect(newTree).toEqual({ nodes: [] }); - expect(newTree).toNotBe(srcTree); + expect(newTree).not.toBe(srcTree); done(); }); @@ -42,7 +42,7 @@ describe('lib: copy-tree', function() { }, ], }); - expect(newTree).toNotBe(srcTree); + expect(newTree).not.toBe(srcTree); done(); }); @@ -51,7 +51,7 @@ describe('lib: copy-tree', function() { var opts = {}; var newTree = copyTree(srcTree, opts, nonConvertingNodeFactory); expect(newTree).toEqual(srcTree); - expect(newTree).toNotBe(srcTree); + expect(newTree).not.toBe(srcTree); done(); }); @@ -60,7 +60,7 @@ describe('lib: copy-tree', function() { var opts = {}; var newTree = copyTree(srcTree, opts); expect(newTree).toEqual(srcTree); - expect(newTree).toNotBe(srcTree); + expect(newTree).not.toBe(srcTree); done(); }); @@ -68,7 +68,7 @@ describe('lib: copy-tree', function() { var srcTree = require('../fixtures/copy-tree'); var newTree = copyTree(srcTree); expect(newTree).toEqual(srcTree); - expect(newTree).toNotBe(srcTree); + expect(newTree).not.toBe(srcTree); done(); }); @@ -81,7 +81,7 @@ describe('lib: copy-tree', function() { var opts = { tasksDepth: 0 }; var newTree = copyTree(srcTree, opts, nonConvertingNodeFactory); expect(newTree).toEqual(expectedTree); - expect(newTree).toNotBe(srcTree); + expect(newTree).not.toBe(srcTree); done(); }); @@ -92,7 +92,7 @@ describe('lib: copy-tree', function() { var opts = { tasksDepth: 1 }; var newTree = copyTree(srcTree, opts, nonConvertingNodeFactory); expect(newTree).toEqual(expectedTree); - expect(newTree).toNotBe(srcTree); + expect(newTree).not.toBe(srcTree); done(); }); @@ -103,7 +103,7 @@ describe('lib: copy-tree', function() { var opts = { tasksDepth: 2 }; var newTree = copyTree(srcTree, opts, nonConvertingNodeFactory); expect(newTree).toEqual(expectedTree); - expect(newTree).toNotBe(srcTree); + expect(newTree).not.toBe(srcTree); done(); }); @@ -114,7 +114,7 @@ describe('lib: copy-tree', function() { var opts = { tasksDepth: 3 }; var newTree = copyTree(srcTree, opts, nonConvertingNodeFactory); expect(newTree).toEqual(expectedTree); - expect(newTree).toNotBe(srcTree); + expect(newTree).not.toBe(srcTree); done(); }); @@ -125,7 +125,7 @@ describe('lib: copy-tree', function() { var opts = { tasksDepth: 4 }; var newTree = copyTree(srcTree, opts, nonConvertingNodeFactory); expect(newTree).toEqual(expectedTree); - expect(newTree).toNotBe(srcTree); + expect(newTree).not.toBe(srcTree); done(); }); @@ -136,7 +136,7 @@ describe('lib: copy-tree', function() { var opts = { tasksDepth: 5 }; var newTree = copyTree(srcTree, opts, nonConvertingNodeFactory); expect(newTree).toEqual(expectedTree); - expect(newTree).toNotBe(srcTree); + expect(newTree).not.toBe(srcTree); done(); }); @@ -147,7 +147,7 @@ describe('lib: copy-tree', function() { var opts = { tasksDepth: -1 }; var newTree = copyTree(srcTree, opts, nonConvertingNodeFactory); expect(newTree).toEqual(expectedTree); - expect(newTree).toNotBe(srcTree); + expect(newTree).not.toBe(srcTree); done(); }); @@ -158,12 +158,12 @@ describe('lib: copy-tree', function() { var opts = { tasksDepth: null }; var newTree = copyTree(srcTree, opts, nonConvertingNodeFactory); expect(newTree).toEqual(expectedTree); - expect(newTree).toNotBe(srcTree); + expect(newTree).not.toBe(srcTree); opts = { tasksDepth: 'A' }; newTree = copyTree(srcTree, opts, nonConvertingNodeFactory); expect(newTree).toEqual(expectedTree); - expect(newTree).toNotBe(srcTree); + expect(newTree).not.toBe(srcTree); done(); }); @@ -177,7 +177,7 @@ describe('lib: copy-tree', function() { var opts = { compactTasks: true }; var newTree = copyTree(srcTree, opts, nonConvertingNodeFactory); expect(newTree).toEqual(expectedTree); - expect(newTree).toNotBe(srcTree); + expect(newTree).not.toBe(srcTree); done(); }); }); diff --git a/test/lib/merge-configs.js b/test/lib/merge-configs.js new file mode 100644 index 00000000..6d0a4bea --- /dev/null +++ b/test/lib/merge-configs.js @@ -0,0 +1,119 @@ +'use strict'; + +var expect = require('expect'); +var path = require('path'); +var mergeConfigs = require('../../lib/shared/config/merge-configs'); + +var fixturesDir = path.join(__dirname, '../fixtures/config'); + +describe('lib: config/merge-configs', function() { + + it('Should get merged config when there is only project config', function(done) { + var config = { + project: { + description: 'description by .gulp.js in directory project', + }, + userHome: {}, + }; + var configFiles = { + project: path.join(fixturesDir, 'project/.gulp.js'), + userHome: undefined, + }; + var env = { + config: config, + configFiles: configFiles, + }; + + var cfg = mergeConfigs(env); + + expect(cfg).toEqual({ + description: 'description by .gulp.js in directory project', + }); + done(); + }); + + it('Should get merged config when there is only user-home config', function(done) { + var config = { + project: {}, + userHome: { + description: 'description by .gulp.js in directory user home', + }, + }; + var configFiles = { + project: undefined, + userHome: path.join(fixturesDir, 'user/home/.gulp.js'), + }; + var env = { + config: config, + configFiles: configFiles, + }; + + var cfg = mergeConfigs(env); + + expect(cfg).toEqual({ + description: 'description by .gulp.js in directory user home', + }); + done(); + }); + + it('Should get merged config when there are both project and user-home config', function(done) { + var config = { + project: { + description: 'description by .gulp.js in directory project', + flags: { + series: true, + }, + }, + userHome: { + description: 'description by .gulp.js in directory user home', + flags: { + silent: true, + }, + }, + }; + var configFiles = { + project: path.join(fixturesDir, 'project/gulp.js'), + userHome: path.join(fixturesDir, 'user/home/.gulp.js'), + }; + var env = { + config: config, + configFiles: configFiles, + }; + + var cfg = mergeConfigs(env); + + expect(cfg).toEqual({ + description: 'description by .gulp.js in directory project', + flags: { + series: true, + silent: true, + }, + }); + done(); + }); + + it('Should convert a value of `flags.gulpfile` to absolute path', function(done) { + var config = { + project: { + flags: { gulpfile: './is/here/mygulpfile.js' }, + }, + }; + var configFiles = { + project: path.join(fixturesDir, 'flags/gulpfile/.gulp.json'), + }; + var env = { + config: config, + configFiles: configFiles, + }; + + var cfg = mergeConfigs(env); + + expect(cfg).toEqual({ + flags: { + gulpfile: path.join(fixturesDir, 'flags/gulpfile/is/here/mygulpfile.js'), + }, + }); + done(); + }); + +}); diff --git a/test/lib/task-tree.js b/test/lib/task-tree.js index 7dd46e89..ffe4dcad 100644 --- a/test/lib/task-tree.js +++ b/test/lib/task-tree.js @@ -7,7 +7,7 @@ var taskTree = require('../../lib/versioned/^3.7.0/task-tree'); describe('lib: taskTree', function() { it('forms a tree properly', function(done) { - expect(taskTree).toExist(); // Lol shutup jshint + expect(taskTree).not.toBeNull(); // Lol shutup jshint var tasks = { test: { diff --git a/test/logging.js b/test/logging.js index 9f7eac03..11d6bd5a 100644 --- a/test/logging.js +++ b/test/logging.js @@ -1,15 +1,15 @@ 'use strict'; var expect = require('expect'); -var child = require('child_process'); +var exec = require('child_process').exec; describe('logging', function() { it('log-level flag for debug: -LLLL', function(done) { - child.exec('node ' + __dirname + '/fixtures/logging.js -LLLL', cb); + exec('node ' + __dirname + '/fixtures/logging.js -LLLL', cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toMatch('test error'); stdout = stdout.replace(/\\/g, '/').split('\n'); expect(stdout[0]).toMatch('test debug'); @@ -20,10 +20,10 @@ describe('logging', function() { }); it('no log-level flag: defaults to -LLL', function(done) { - child.exec('node ' + __dirname + '/fixtures/logging.js', cb); + exec('node ' + __dirname + '/fixtures/logging.js', cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toMatch('test error'); stdout = stdout.replace(/\\/g, '/').split('\n'); expect(stdout[0]).toMatch('test info'); @@ -33,10 +33,10 @@ describe('logging', function() { }); it('log-level flag for info: -LLL', function(done) { - child.exec('node ' + __dirname + '/fixtures/logging.js -LLL', cb); + exec('node ' + __dirname + '/fixtures/logging.js -LLL', cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toMatch('test error'); stdout = stdout.replace(/\\/g, '/').split('\n'); expect(stdout[0]).toMatch('test info'); @@ -46,10 +46,10 @@ describe('logging', function() { }); it('log-level flag for warn: -LL', function(done) { - child.exec('node ' + __dirname + '/fixtures/logging.js -LL', cb); + exec('node ' + __dirname + '/fixtures/logging.js -LL', cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toMatch('test error'); stdout = stdout.replace(/\\/g, '/').split('\n'); expect(stdout[0]).toMatch('test warn'); @@ -58,10 +58,10 @@ describe('logging', function() { }); it('log-level flag for error: -L', function(done) { - child.exec('node ' + __dirname + '/fixtures/logging.js -L', cb); + exec('node ' + __dirname + '/fixtures/logging.js -L', cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toMatch('test error'); expect(stdout).toEqual(''); done(err); diff --git a/test/non-completing-tasks.js b/test/non-completing-tasks.js deleted file mode 100644 index e7a521e3..00000000 --- a/test/non-completing-tasks.js +++ /dev/null @@ -1,63 +0,0 @@ -'use strict'; - -var expect = require('expect'); -var eraseTime = require('gulp-test-tools').eraseTime; -var runner = require('gulp-test-tools').gulpRunner; - - -describe('sync-task', function() { - it('should return error code 1 if any tasks did not complete', function(done) { - // The exit code is set to 1 by setting process.exitCode = 1 which is only supported from nodejs 0.11 on - if (process.version.slice(0, 5) === 'v0.10') { - this.skip(); - } - - runner({ verbose: false }) - .chdir('test/fixtures/gulpfiles') - .gulp('test6 test7 test8') - .run(function(err) { - expect(err).toNotEqual(null); - expect(err.code).toEqual(1); - done(); - }); - }); - - it('should log tasks which did not complete', function(done) { - runner({ verbose: false }) - .chdir('test/fixtures/gulpfiles') - .gulp('test6 test7 test8') - .run(function(err, stdout) { - var lines = stdout.split('\n'); - expect(lines.length).toEqual(8); - expect(eraseTime(lines[5])).toEqual('The following tasks did not complete: test7, test8'); - done(); - }); - }); - - it('should not log false positive in case of parallel failure', function(done) { - runner({ verbose: false }) - .gulp('--gulpfile ./test/fixtures/gulpfiles/gulpfile-parallel-failure.js') - .run(function(err, stdout) { - expect(stdout).toExclude('The following tasks did not complete:'); - done(); - }); - }); - - it('should not log false positive in case of parallel failure in continue mode', function(done) { - runner({ verbose: false }) - .gulp('--continue --gulpfile ./test/fixtures/gulpfiles/gulpfile-parallel-failure.js') - .run(function(err, stdout) { - expect(stdout).toExclude('The following tasks did not complete:'); - done(); - }); - }); - - it('should log non-completing task alongside a failure in continue mode', function(done) { - runner({ verbose: false }) - .gulp('--continue --gulpfile ./test/fixtures/gulpfiles/gulpfile-parallel-failure.js broken') - .run(function(err, stdout) { - expect(stdout).toInclude('The following tasks did not complete: broken, notCompleting1\n'); - done(); - }); - }); -}); diff --git a/test/sync-task.js b/test/sync-task.js new file mode 100644 index 00000000..8f1bf677 --- /dev/null +++ b/test/sync-task.js @@ -0,0 +1,72 @@ +'use strict'; + +var expect = require('expect'); +var exec = require('child_process').exec; +var path = require('path'); + +var sliceLines = require('./tool/slice-lines'); +var gulp = require('./tool/gulp-cmd'); + +describe('sync-task', function() { + it('should return error code 1 if any tasks did not complete', function(done) { + var opts = { cwd: path.join(__dirname, 'fixtures/gulpfiles') }; + exec(gulp('test6 test7 test8'), opts, cb); + + function cb(err) { + expect(err).not.toBeNull(); + expect(err.code).toEqual(1); + done(); + } + }); + + it('should log tasks which did not complete', function(done) { + var opts = { cwd: path.join(__dirname, 'fixtures/gulpfiles') }; + exec(gulp('test6 test7 test8'), opts, cb); + + function cb(err, stdout) { + expect(sliceLines(stdout, 5, 7)).toEqual( + 'The following tasks did not complete: test7, test8\n' + + 'Did you forget to signal async completion?' + ); + done(); + } + }); + + it('should not log false positive in case of parallel failure', function(done) { + var opts = { cwd: path.join(__dirname, '..') }; + exec(gulp( + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-parallel-failure.js' + ), opts, cb); + + function cb(err, stdout) { + expect(stdout).not.toMatch('The following tasks did not complete:'); + done(); + } + }); + + it('should not log false positive in case of parallel failure in continue mode', function(done) { + var opts = { cwd: path.join(__dirname, '..') }; + exec(gulp( + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-parallel-failure.js' + ), opts, cb); + + function cb(err, stdout) { + expect(stdout).not.toMatch('The following tasks did not complete:'); + done(); + } + }); + + it('should log non-completing task alongside a failure in continue mode', function(done) { + var opts = { cwd: path.join(__dirname, '..') }; + exec(gulp( + '--continue', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-parallel-failure.js', + 'broken' + ), opts, cb); + + function cb(err, stdout) { + expect(stdout).toMatch('The following tasks did not complete: broken, notCompleting1\n'); + done(); + } + }); +}); diff --git a/test/tool/erase-lapse.js b/test/tool/erase-lapse.js new file mode 100644 index 00000000..f1345e2d --- /dev/null +++ b/test/tool/erase-lapse.js @@ -0,0 +1,7 @@ +'use strict'; + +module.exports = function(text) { + return (text + '\n') + .replace(/ after [0-9.]+ (s|ms|μs|min)(\r\n|\r|\n)/g, ' after ?\n') + .slice(0, -1); +}; diff --git a/test/tool/erase-time.js b/test/tool/erase-time.js new file mode 100644 index 00000000..444c4412 --- /dev/null +++ b/test/tool/erase-time.js @@ -0,0 +1,5 @@ +'use strict'; + +module.exports = function(text) { + return ('\n' + text).replace(/(\r\n|\r|\n)\[[0-9:]{8}\] /g, '\n').slice(1); +}; diff --git a/test/tool/gulp-cmd.js b/test/tool/gulp-cmd.js new file mode 100644 index 00000000..87540be1 --- /dev/null +++ b/test/tool/gulp-cmd.js @@ -0,0 +1,16 @@ +'use strict'; + +var path = require('path'); + +function gulp(/* ... */) { + var arr = Array.prototype.slice.apply(arguments); + arr.unshift('node ' + path.join(__dirname, '../../bin/gulp.js')); + return arr.join(' '); +} +gulp.debug = function(/* ... */) { + var s = gulp.apply(null, arguments); + console.log(s); + return s; +} + +module.exports = gulp; diff --git a/test/tool/slice-lines.js b/test/tool/slice-lines.js new file mode 100644 index 00000000..4431d3c8 --- /dev/null +++ b/test/tool/slice-lines.js @@ -0,0 +1,11 @@ +'use strict'; + +var eraseLapse = require('./erase-lapse'); +var eraseTime = require('./erase-time'); + +function sliceLines(text, start, end) { + text = eraseLapse(eraseTime(text)); + return text.split('\n').slice(start, end).join('\n'); +} + +module.exports = sliceLines;