From 3bd501df8cd6b304899464e584c84936cd2df5d2 Mon Sep 17 00:00:00 2001 From: sttk Date: Sun, 13 Nov 2022 22:57:31 +0900 Subject: [PATCH 01/35] chore: Normalize repository, dropping node <10.13 support --- .editorconfig | 13 ++---- .eslintrc | 2 +- .github/support.yml | 2 - .github/workflows/dev.yml | 75 +++++++++++++++++++++++++++++++++++ .github/workflows/release.yml | 16 ++++++++ .prettierignore | 3 ++ .travis.yml | 21 ---------- LICENSE | 2 +- README.md | 29 ++++++-------- appveyor.yml | 29 -------------- package.json | 56 ++++++++++++++------------ test/.eslintrc | 6 --- 12 files changed, 144 insertions(+), 110 deletions(-) delete mode 100644 .github/support.yml create mode 100644 .github/workflows/dev.yml create mode 100644 .github/workflows/release.yml create mode 100644 .prettierignore delete mode 100644 .travis.yml delete mode 100644 appveyor.yml delete mode 100644 test/.eslintrc 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..44f472fb --- /dev/null +++ b/.github/workflows/dev.yml @@ -0,0 +1,75 @@ +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: npm test + + - name: Coveralls + uses: coverallsapp/github-action@v1.1.2 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + flag-name: ${{matrix.os}}-node-${{ matrix.node }} + parallel: true + + coveralls: + needs: test + name: Finish up + + runs-on: ubuntu-latest + steps: + - name: Coveralls Finished + uses: coverallsapp/github-action@v1.1.2 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + parallel-finished: true 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..aae7195c 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 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..30480362 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. @@ -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/workflow/status/gulpjs/gulp-cli/dev?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/package.json b/package.json index bed47c0f..b9694488 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": { @@ -24,46 +24,52 @@ ], "scripts": { "lint": "eslint .", - "prepublish": "marked-man --name gulp docs/CLI.md > gulp.1", + "prepare": "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" + "test": "nyc mocha --async-only --timeout 5000 test/lib test" }, "dependencies": { - "ansi-colors": "^1.0.1", + "ansi-colors": "^4.1.3", "archy": "^1.0.0", "array-sort": "^1.0.0", - "concat-stream": "^1.6.0", + "concat-stream": "^2.0.0", "color-support": "^1.1.3", - "copy-props": "^2.0.1", - "fancy-log": "^1.3.2", - "gulplog": "^1.0.0", + "copy-props": "^4.0.0", + "fancy-log": "^2.0.0", + "gulplog": "^2.0.1", "interpret": "^1.4.0", - "isobject": "^3.0.1", + "isobject": "^4.0.0", "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", + "mute-stdout": "^2.0.0", + "pretty-hrtime": "^1.0.3", + "replace-homedir": "^2.0.0", + "semver-greatest-satisfied-range": "^2.0.0", "v8flags": "^3.2.0", "yargs": "^7.1.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", + "babel-register": "^6.26.0", + "eslint": "^7.32.0", + "eslint-config-gulp": "^5.0.1", "expect": "^1.20.2", - "gulp": "^4.0.0", - "gulp-test-tools": "^0.6.1", + "gulp": "^4.0.2", + "gulp-test-tools": "^0.6.2", "marked-man": "^0.2.1", - "mocha": "^3.2.0", - "nyc": "^13.3.0", - "rimraf": "^2.6.1", - "semver": "^5.7.1" + "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" - } -} From c1b50cf755fc006b6e44bdfd47add8358f228474 Mon Sep 17 00:00:00 2001 From: sttk Date: Thu, 17 Nov 2022 13:27:51 +0900 Subject: [PATCH 02/35] test: stop using gulp-test-tool --- package.json | 1 - test/completion.js | 28 +- test/config-description.js | 60 ++-- ...Tasks.js => config-flags-compact-tasks.js} | 78 ++--- test/config-flags-continue.js | 72 ++-- test/config-flags-gulpfile.js | 118 +++---- test/config-flags-log-level.js | 325 ++++++++++-------- test/config-flags-node-flags.js | 89 ++--- test/config-flags-require.js | 97 +++--- test/config-flags-series.js | 116 +++---- test/config-flags-silent.js | 57 ++- ...ortTasks.js => config-flags-sort-tasks.js} | 78 ++--- test/config-flags-tasks-depth.js | 49 +++ test/config-flags-tasksDepth.js | 53 --- test/esm.js | 21 +- test/execution-errors.js | 134 ++++---- test/exports-as-tasks.js | 23 +- test/flags-continue.js | 45 +-- test/flags-gulpfile.js | 36 +- test/flags-help.js | 40 ++- test/flags-require.js | 91 ++--- test/flags-series.js | 37 +- test/flags-silent.js | 17 +- test/flags-tasks-json.js | 50 ++- test/flags-tasks-simple.js | 24 +- test/flags-tasks.js | 116 ++++--- test/flags-v8flags.js | 43 ++- test/flags-verify.js | 54 +-- test/flags-version.js | 32 +- test/non-completing-tasks.js | 63 ---- test/sync-task.js | 81 +++++ test/tool/cmd-sep.js | 5 + test/tool/erase-lapse.js | 7 + test/tool/erase-time.js | 5 + test/tool/slice-lines.js | 11 + 35 files changed, 1149 insertions(+), 1007 deletions(-) rename test/{config-flags-compactTasks.js => config-flags-compact-tasks.js} (57%) rename test/{config-flags-sortTasks.js => config-flags-sort-tasks.js} (51%) create mode 100644 test/config-flags-tasks-depth.js delete mode 100644 test/config-flags-tasksDepth.js delete mode 100644 test/non-completing-tasks.js create mode 100644 test/sync-task.js create mode 100644 test/tool/cmd-sep.js create mode 100644 test/tool/erase-lapse.js create mode 100644 test/tool/erase-time.js create mode 100644 test/tool/slice-lines.js diff --git a/package.json b/package.json index b9694488..152e4658 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,6 @@ "eslint-config-gulp": "^5.0.1", "expect": "^1.20.2", "gulp": "^4.0.2", - "gulp-test-tools": "^0.6.2", "marked-man": "^0.2.1", "mocha": "^8.4.0", "nyc": "^15.1.0", diff --git a/test/completion.js b/test/completion.js index 745422b5..a00d9152 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 gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); + describe('flag: --completion', function() { ['bash', 'fish', 'powershell', 'zsh'].forEach(function(type) { @@ -12,9 +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([ + gulpCmd, + '--completion=' + type, + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toNotExist(); @@ -26,12 +29,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([ + gulpCmd, + '--completion=unknown', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toNotEqual(null); @@ -42,9 +45,10 @@ describe('flag: --completion', function() { }); it('shows error message for missing completion type', function(done) { - runner({ verbose: false }) - .gulp('--completion') - .run(cb); + exec([ + gulpCmd, + '--completion', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toNotEqual(null); diff --git a/test/config-description.js b/test/config-description.js index 41709909..3e904099 100644 --- a/test/config-description.js +++ b/test/config-description.js @@ -1,68 +1,66 @@ '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 cmdSep = require('./tool/cmd-sep'); -var fixturesDir = path.join(__dirname, 'fixtures', 'config'); +var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); +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); + exec([ + 'cd ' + path.join(baseDir, 'foo/bar') + cmdSep, + gulpCmd, + '--tasks', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); expect(stderr).toEqual(''); - var expected = fs.readFileSync(path.join(expectedDir, 'output0.txt'), - 'utf-8'); - stdout = eraseTime(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); + exec([ + 'cd ' + path.join(baseDir, 'foo/bar/baz') + cmdSep, + gulpCmd, + '--tasks', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); expect(stderr).toEqual(''); - var expected = fs.readFileSync(path.join(expectedDir, 'output0.txt'), - 'utf-8'); - stdout = eraseTime(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 by --cwd', function(done) { - runner({ verbose: false }) - .basedir(fixturesDir) - .chdir('qux') - .gulp('--tasks', '--gulpfile ../foo/bar/gulpfile.js', '--cwd .') - .run(cb); + exec([ + 'cd ' + path.join(baseDir, 'qux') + cmdSep, + gulpCmd, + '--tasks', + '--gulpfile ../foo/bar/gulpfile.js', + '--cwd .', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); expect(stderr).toEqual(''); - var expected = fs.readFileSync(path.join(expectedDir, 'output1.txt'), - 'utf-8'); - stdout = eraseTime(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 57% rename from test/config-flags-compactTasks.js rename to test/config-flags-compact-tasks.js index 460af741..0940a21c 100644 --- a/test/config-flags-compactTasks.js +++ b/test/config-flags-compact-tasks.js @@ -1,51 +1,49 @@ '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 cmdSep = require('./tool/cmd-sep'); + +var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); +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) { + exec([ + 'cd ' + path.join(baseDir, 't') + cmdSep, + gulpCmd, + '--tasks', + ].join(' '), 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) { + exec([ + 'cd ' + path.join(baseDir, 'f') + cmdSep, + gulpCmd, + '--tasks', + ].join(' '), 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 +51,18 @@ 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); + exec([ + 'cd ' + path.join(baseDir, 'f') + cmdSep, + gulpCmd, + '--tasks', + '--compact-tasks', + ].join(' '), 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 +70,18 @@ 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); + exec([ + 'cd ' + path.join(baseDir, 't') + cmdSep, + gulpCmd, + '--tasks', + '--no-compact-tasks', + ].join(' '), 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..1509466c 100644 --- a/test/config-flags-continue.js +++ b/test/config-flags-continue.js @@ -1,28 +1,26 @@ '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 cmdSep = require('./tool/cmd-sep'); + +var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); +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) { + exec([ + 'cd ' + path.join(baseDir, 't') + cmdSep, + gulpCmd, + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toNotEqual(null); - - stdout = eraseLapse(eraseTime(skipLines(stdout, 1))); + stdout = sliceLines(stdout, 1); expect(stdout).toEqual( 'Starting \'default\'...\n' + 'Starting \'err\'...\n' + @@ -30,7 +28,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 +37,21 @@ 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) { + exec([ + 'cd ' + path.join(baseDir, 'f') + cmdSep, + gulpCmd, + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toNotEqual(null); - - stdout = eraseLapse(eraseTime(skipLines(stdout, 1))); + 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 +61,15 @@ describe('config: flags.continue', function() { }); it('Should overridden by cli flag: --continue', function(done) { - runner - .chdir('flags/continue/f') - .gulp('--continue') - .run(cb); + exec([ + 'cd ' + path.join(baseDir, 'f') + cmdSep, + gulpCmd, + '--continue', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toNotEqual(null); - - stdout = eraseLapse(eraseTime(skipLines(stdout, 1))); + stdout = sliceLines(stdout, 1); expect(stdout).toEqual( 'Starting \'default\'...\n' + 'Starting \'err\'...\n' + @@ -81,7 +77,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 +87,21 @@ 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); + exec([ + 'cd ' + path.join(baseDir, 't') + cmdSep, + gulpCmd, + '--no-continue', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toNotEqual(null); - - stdout = eraseLapse(eraseTime(skipLines(stdout, 1))); + 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..9051d105 100644 --- a/test/config-flags-gulpfile.js +++ b/test/config-flags-gulpfile.js @@ -1,105 +1,99 @@ '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 cmdSep = require('./tool/cmd-sep'); + +var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); +var baseDir = path.join(__dirname, 'fixtures/config/flags/gulpfile'); describe('config: flags.gulpfile', function() { it('Should configure with a .gulp.* file', function(done) { - runner - .chdir('flags/gulpfile') - .gulp() - .run(cb); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); 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/mygulpfile.js') + '\n' + + 'The current directory : ' + baseDir ); 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) { + exec([ + 'cd ' + path.join(__dirname, 'fixtures/config') + cmdSep, + gulpCmd, + '--cwd ./flags/gulpfile', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); 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/mygulpfile.js') + '\n' + + 'The current directory : ' + baseDir ); 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 ignore a ./gulp.* file if another directory is specified by --cwd', function(done) { + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--cwd ./cwd', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); 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, 4)).toEqual( + 'Another gulpfile : ' + path.join(baseDir, 'cwd/gulpfile.js') ); 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 ignore a ./.gulp.* file if another gulpfile is specified by --gulpfile', function(done) { + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--gulpfile ./cwd/gulpfile.js', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); 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, 4)).toEqual( + 'Another gulpfile : ' + path.join(baseDir, 'cwd/gulpfile.js') ); done(err); } }); it('Should overridden by cli flag: --gulpfile', function(done) { - runner - .chdir('./flags/gulpfile/override-by-cliflag') - .gulp('--gulpfile mygulpfile.js') - .run(cb); + exec([ + 'cd ' + path.join(baseDir, 'override-by-cliflag') + cmdSep, + gulpCmd, + '--gulpfile mygulpfile.js', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); 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,22 +101,18 @@ 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); + exec([ + 'cd ' + path.join(baseDir, 'autoload') + cmdSep, + gulpCmd, + 'dist', + ].join(' '), 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 babel-register'); - var clean = eraseTime(headLines(stdout, 1, 4)); - expect(clean).toEqual('clean!'); - var build = eraseTime(headLines(stdout, 1, 7)); - expect(build).toEqual('build!'); - + expect(sliceLines(stdout, 0, 1)).toEqual('Requiring external module babel-register'); + expect(sliceLines(stdout, 4, 5)).toEqual('clean!'); + expect(sliceLines(stdout, 7, 8)).toEqual('build!'); done(err); } }); diff --git a/test/config-flags-log-level.js b/test/config-flags-log-level.js index c3c20918..8569f81e 100644 --- a/test/config-flags-log-level.js +++ b/test/config-flags-log-level.js @@ -1,196 +1,251 @@ '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 cmdSep = require('./tool/cmd-sep'); + +var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); +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(); - }); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--gulpfile x', + ].join(' '), cb); + + function cb(err, stdout, stderr) { + expect(err).toNotEqual(null); + expect(stdout).toEqual(''); + expect(eraseTime(stderr)).toEqual('No gulpfile found\n'); + done(); + } }); it('Should output warn log', function(done) { - 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(); - }); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--require mymodule', + ].join(' '), cb); + + function cb(err, stdout, stderr) { + expect(err).toEqual(null); + expect(stderr).toEqual(''); + expect(sliceLines(stdout, 0, 2)).toMatch( + 'Failed to load 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); - }); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--harmony', + ].join(' '), cb); + + function cb(err, stdout, stderr) { + expect(err).toEqual(null); + 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(); - }); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--gulpfile x', + ].join(' '), cb); + + function cb(err, stdout, stderr) { + expect(err).toNotEqual(null); + expect(stdout).toEqual(''); + expect(eraseTime(stderr)).toEqual('No gulpfile found\n'); + done(); + } }); it('Should output warn log', function(done) { - gulp('--require', 'mymodule') - .run(function(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - expect(stderr).toEqual(''); - done(); - }); + exec([ + 'cd ' + path.join(baseDir, 'L') + cmdSep, + gulpCmd, + '--require mymodule', + ].join(' '), cb); + + function cb(err, stdout, stderr) { + expect(err).toEqual(null); + 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); - }); + exec([ + 'cd ' + path.join(baseDir, 'L') + cmdSep, + gulpCmd, + '--harmony', + ].join(' '), cb); + + function cb(err, stdout, stderr) { + expect(err).toEqual(null); + 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(); - }); + exec([ + 'cd ' + path.join(baseDir, 'LL') + cmdSep, + gulpCmd, + '--gulpfile x', + ].join(' '), cb); + + function cb(err, stdout, stderr) { + expect(err).toNotEqual(null); + expect(stdout).toEqual(''); + expect(eraseTime(stderr)).toEqual('No gulpfile found\n'); + done(); + } }); it('Should output warn log', function(done) { - 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(); - }); + exec([ + 'cd ' + path.join(baseDir, 'LL') + cmdSep, + gulpCmd, + '--require mymodule', + ].join(' '), cb); + + function cb(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(); + } }); 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); - }); + exec([ + 'cd ' + path.join(baseDir, 'LL') + cmdSep, + gulpCmd, + '--harmony', + ].join(' '), cb); + + function cb(err, stdout, stderr) { + expect(err).toEqual(null); + 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(); - }); + exec([ + 'cd ' + path.join(baseDir, 'LLL') + cmdSep, + gulpCmd, + '--gulpfile x', + ].join(' '), cb); + + function cb(err, stdout, stderr) { + expect(err).toNotEqual(null); + expect(stdout).toEqual(''); + expect(eraseTime(stderr)).toEqual('No gulpfile found\n'); + done(); + } }); it('Should output warn log', function(done) { - 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(); - }); + exec([ + 'cd ' + path.join(baseDir, 'LLL') + cmdSep, + gulpCmd, + '--require mymodule', + ].join(' '), cb); + + function cb(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(); + } }); 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); - }); + exec([ + 'cd ' + path.join(baseDir, 'LLL') + cmdSep, + gulpCmd, + '--harmony', + ].join(' '), cb); + + function cb(err, stdout, stderr) { + expect(err).toEqual(null); + 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); - }); + exec([ + 'cd ' + path.join(baseDir, 'LLL') + cmdSep, + gulpCmd, + '-L', + '--require mymodule', + ].join(' '), cb); + + function cb(err, stdout, stderr) { + expect(err).toEqual(null); + 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); - }); + exec([ + 'cd ' + path.join(baseDir, 'L') + cmdSep, + gulpCmd, + '-LLL', + '--harmony', + ].join(' '), cb); + + function cb(err, stdout, stderr) { + expect(err).toEqual(null); + 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..0b315115 100644 --- a/test/config-flags-node-flags.js +++ b/test/config-flags-node-flags.js @@ -1,88 +1,74 @@ '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 cmdSep = require('./tool/cmd-sep'); -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 gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); +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); + exec([ + 'cd ' + path.join(baseDir, 'string') + cmdSep, + gulpCmd, + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); 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); + exec([ + 'cd ' + path.join(baseDir, 'array') + cmdSep, + gulpCmd, + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); 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); + exec([ + 'cd ' + path.join(baseDir, 'string') + cmdSep, + gulpCmd, + '--harmony', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); 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); + exec([ + 'cd ' + path.join(baseDir, 'undefined') + cmdSep, + gulpCmd, + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); expect(stderr).toEqual(''); - - stdout = eraseLapse(eraseTime(stdout)); - expect(headLines(stdout, 1)).toMatch('Using gulpfile '); - expect(skipLines(stdout, 1)).toEqual( + expect(sliceLines(stdout, 0, 1)).toMatch('Using gulpfile '); + expect(sliceLines(stdout, 1)).toEqual( 'Starting \'default\'...\n' + 'Default\n' + 'Finished \'default\' after ?\n' + @@ -92,18 +78,16 @@ 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); + exec([ + 'cd ' + path.join(baseDir, 'null') + cmdSep, + gulpCmd, + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); expect(stderr).toEqual(''); - - stdout = eraseLapse(eraseTime(stdout)); - expect(headLines(stdout, 1)).toMatch('Using gulpfile '); - expect(skipLines(stdout, 1)).toEqual( + expect(sliceLines(stdout, 0, 1)).toMatch('Using gulpfile '); + expect(sliceLines(stdout, 1)).toEqual( 'Starting \'default\'...\n' + 'Default\n' + 'Finished \'default\' after ?\n' + @@ -111,5 +95,4 @@ describe('config: nodeFlags', function() { done(err); } }); - }); diff --git a/test/config-flags-require.js b/test/config-flags-require.js index 6db4de52..abc43023 100644 --- a/test/config-flags-require.js +++ b/test/config-flags-require.js @@ -1,107 +1,96 @@ '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 cmdSep = require('./tool/cmd-sep'); + +var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); +var baseDir = path.join(__dirname, 'fixtures/config/flags/require'); 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); + exec([ + 'cd ' + path.join(baseDir, 'array') + cmdSep, + gulpCmd, + ].join(' '), 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!'); + expect(sliceLines(stdout, 0, 1)).toEqual('Requiring external module ./preload_one'); + expect(sliceLines(stdout, 1, 2)).toEqual('Requiring external module ./preload_two'); + expect(sliceLines(stdout, 4, 5)).toEqual('preload one!'); + expect(sliceLines(stdout, 5, 6)).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); + exec([ + 'cd ' + path.join(baseDir, 'string') + cmdSep, + gulpCmd, + ].join(' '), 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!'); + expect(sliceLines(stdout, 0, 1)).toEqual('Requiring external module ./preload'); + expect(sliceLines(stdout, 3, 4)).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); + exec([ + 'cd ' + path.join(baseDir, 'join-flags') + cmdSep, + gulpCmd, + '--require ./preload_one', + ].join(' '), 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!'); + expect(sliceLines(stdout, 0, 1)).toEqual('Requiring external module ./preload_one'); + expect(sliceLines(stdout, 1, 2)).toEqual('Requiring external module ./preload_two'); + expect(sliceLines(stdout, 4, 5)).toEqual('preload one!'); + expect(sliceLines(stdout, 5, 6)).toEqual('preload two!'); done(err); } }); it('resolves relative requires against cwd', function(done) { - runner - .gulp('--cwd flags/require/with-cwd') - .run(cb); + exec([ + 'cd ' + path.join(__dirname, 'fixtures/config') + cmdSep, + gulpCmd, + '--cwd flags/require/with-cwd', + ].join(' '), 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!'); + expect(sliceLines(stdout, 0, 1)).toEqual('Requiring external module ../preload'); + expect(sliceLines(stdout, 4, 5)).toEqual('hello preload!'); done(err); } }); it('works with absolute paths, ignoring cwd', function(done) { - runner - .gulp('--cwd flags/require/with-absolute') - .run(cb); + exec([ + 'cd ' + path.join(__dirname, 'fixtures/config') + cmdSep, + gulpCmd, + '--cwd flags/require/with-absolute', + ].join(' '), 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!'); + expect(sliceLines(stdout, 0, 1)).toEqual('Requiring external module ' + absolute); + expect(sliceLines(stdout, 4, 5)).toEqual('hello preload!'); done(err); } }); diff --git a/test/config-flags-series.js b/test/config-flags-series.js index f6145712..2e6c1700 100644 --- a/test/config-flags-series.js +++ b/test/config-flags-series.js @@ -1,75 +1,70 @@ '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 cmdSep = require('./tool/cmd-sep'); -var fixturesDir = path.join(__dirname, 'fixtures/config'); -var runner = require('gulp-test-tools').gulpRunner({ verbose: false }).basedir(fixturesDir); +var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); +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) { + exec([ + 'cd ' + path.join(baseDir, 't') + cmdSep, + gulpCmd, + 'task1 task2', + ].join(' '), 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).toEqual(null); + 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) { + exec([ + 'cd ' + path.join(baseDir, 'f') + cmdSep, + gulpCmd, + 'task1 task2', + ].join(' '), 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).toEqual(null); + 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); + exec([ + 'cd ' + path.join(baseDir, 'f') + cmdSep, + gulpCmd, + '--series task1 task2', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); 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 +76,16 @@ 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); + exec([ + 'cd ' + path.join(baseDir, 't') + cmdSep, + gulpCmd, + '--no-series task1 task2', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); 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..29875a7a 100644 --- a/test/config-flags-silent.js +++ b/test/config-flags-silent.js @@ -1,22 +1,22 @@ '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 cmdSep = require('./tool/cmd-sep'); + +var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); +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) { + exec([ + 'cd ' + path.join(baseDir, 't') + cmdSep, + gulpCmd, + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); @@ -26,18 +26,16 @@ describe('config: flags.silent', function() { } }); - 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) { + exec([ + 'cd ' + path.join(baseDir, 'f') + cmdSep, + gulpCmd, + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); 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,10 +45,11 @@ describe('config: flags.silent', function() { }); it('Should overridden by cli flag: --silent', function(done) { - runner - .chdir('flags/silent/f') - .gulp('--silent') - .run(cb); + exec([ + 'cd ' + path.join(baseDir, 'f') + cmdSep, + gulpCmd, + '--silent', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); @@ -61,16 +60,16 @@ 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); + exec([ + 'cd ' + path.join(baseDir, 't') + cmdSep, + gulpCmd, + '--no-silent', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); 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..3467a261 100644 --- a/test/config-flags-sortTasks.js +++ b/test/config-flags-sort-tasks.js @@ -1,90 +1,78 @@ '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 cmdSep = require('./tool/cmd-sep'); + +var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); +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) { + exec([ + 'cd ' + path.join(baseDir, 't') + cmdSep, + gulpCmd, + '--tasks', + ].join(' '), 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) { + exec([ + 'cd ' + path.join(baseDir, 'f') + cmdSep, + gulpCmd, + '--tasks', + ].join(' '), 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); + exec([ + 'cd ' + path.join(baseDir, 'f') + cmdSep, + gulpCmd, + '--tasks --sort-tasks', + ].join(' '), 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); + exec([ + 'cd ' + path.join(baseDir, 't') + cmdSep, + gulpCmd, + '--tasks --no-sort-tasks', + ].join(' '), 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..7d90c4a3 --- /dev/null +++ b/test/config-flags-tasks-depth.js @@ -0,0 +1,49 @@ +'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 cmdSep = require('./tool/cmd-sep'); + +var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); +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) { + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--tasks', + ].join(' '), 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) { + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--tasks', + '--tasks-depth 2', + ].join(' '), 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..e7e666f7 100644 --- a/test/esm.js +++ b/test/esm.js @@ -1,13 +1,16 @@ '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 baseDir = path.join(__dirname, '..'); +var sliceLines = require('./tool/slice-lines'); +var cmdSep = require('./tool/cmd-sep'); + +var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); var expectedDir = path.join(__dirname, 'expected'); describe('ESM', function() { @@ -17,23 +20,25 @@ describe('ESM', function() { 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); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + options, + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); expect(stderr).toMatch(/^(.*ExperimentalWarning: The ESM module loader is experimental\.\n)?$/); 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..67f34932 100644 --- a/test/execution-errors.js +++ b/test/execution-errors.js @@ -1,83 +1,99 @@ '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 cmdSep = require('./tool/cmd-sep'); + +var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); + 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(); - }); + exec([ + 'cd ' + path.join(__dirname, './fixtures/gulpfiles') + cmdSep, + gulpCmd, + 'a', + ].join(' '), cb); + + function cb(err, stdout, stderr) { + expect(err).toNotEqual(null); + expect(err.code).toEqual(1); + expect(eraseTime(stdout)).toMatch('Using gulpfile '); + expect(eraseTime(stderr)).toEqual( + 'Task never defined: a\n' + + 'To list available tasks, try running: gulp --tasks\n'); + done(); + } }); it('should output an error if gulp version is unsupported', function(done) { - runner({ verbose: false }) - .chdir('test/fixtures/errors/bad-gulp-version') - .gulp() - .run(function(err, stdout, stderr) { - expect(err).toNotEqual(null); - expect(err.code).toEqual(1); - expect(eraseTime(stdout)).toEqual(''); - expect(eraseTime(stderr)).toEqual('Unsupported gulp version\n'); - done(); - }); + exec([ + 'cd ' + path.join(__dirname, './fixtures/errors/bad-gulp-version') + cmdSep, + gulpCmd, + ].join(' '), cb); + + function cb(err, stdout, stderr) { + expect(err).toNotEqual(null); + expect(err.code).toEqual(1); + expect(eraseTime(stdout)).toEqual(''); + expect(eraseTime(stderr)).toEqual('Unsupported gulp version\n'); + done(); + } }); it('should output an error if gulp is not found', function(done) { - runner({ verbose: false }) - .chdir(os.tmpdir()) - .gulp() - .run(function(err, stdout, stderr) { - expect(err).toNotEqual(null); - expect(err.code).toEqual(1); - expect(eraseTime(stdout)).toEqual(''); - stderr = eraseTime(stderr).split(/[\r\n]+/); - expect(stderr[0]).toMatch('Local gulp not found in '); - expect(stderr[1]).toEqual('Try running: npm install gulp'); - done(); - }); + var tmpdir = os.tmpdir(); + exec([ + os.platform() === 'win32' ? tmpdir.slice(0, 2) + cmdSep : '', + 'cd ' + tmpdir + cmdSep, + gulpCmd, + ].join(' '), cb); + + function cb(err, stdout, stderr) { + expect(err).toNotEqual(null); + 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([ + 'cd ' + dir + cmdSep, + 'node ' + path.join(__dirname, '../bin/gulp.js'), + '--gulpfile', gulpfileName, + ].join(' '), cb); + + function cb(err, stdout, stderr) { + expect(err).toNotEqual(null); + 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/exports-as-tasks.js b/test/exports-as-tasks.js index b94ff0e5..9559afb3 100644 --- a/test/exports-as-tasks.js +++ b/test/exports-as-tasks.js @@ -1,12 +1,15 @@ '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 cmdSep = require('./tool/cmd-sep'); + +var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); +var baseDir = path.join(__dirname, '..'); var expectedDir = path.join(__dirname, 'expected'); // Long timeout is required because parse time is slow @@ -14,10 +17,13 @@ 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); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--tasks', + '--sort-tasks', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-exports.babel.js', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); @@ -25,8 +31,7 @@ describe('exports as tasks', function() { 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/flags-continue.js b/test/flags-continue.js index fbfe644a..b64385cb 100644 --- a/test/flags-continue.js +++ b/test/flags-continue.js @@ -1,32 +1,36 @@ '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 cmdSep = require('./tool/cmd-sep'); + +var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); +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); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + 'test4', + '--continue', + '--cwd ./test/fixtures/gulpfiles', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toNotEqual(null); - stdout = eraseLapse(eraseTime(skipLines(stdout, 2))); - expect(stdout).toEqual( + 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 +39,23 @@ 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); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + 'test4', + '--cwd ./test/fixtures/gulpfiles', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toNotEqual(null); expect(stdout).toNotMatch('Starting \'anon\''); - stdout = eraseLapse(eraseTime(skipLines(stdout, 2))); + 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..41eae131 100644 --- a/test/flags-gulpfile.js +++ b/test/flags-gulpfile.js @@ -1,32 +1,36 @@ '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 cmdSep = require('./tool/cmd-sep'); + +var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); +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); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--gulpfile', gulpfilePath, + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); 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 +46,22 @@ 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); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '-f', gulpfilePath, + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); 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..68317be2 100644 --- a/test/flags-help.js +++ b/test/flags-help.js @@ -1,58 +1,62 @@ '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 cmdSep = require('./tool/cmd-sep'); +var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); +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); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--help', + '--cwd ./test/fixtures/gulpfiles', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); 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); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--h', + '--cwd ./test/fixtures/gulpfiles', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); 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); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--help', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); expect(stderr).toEqual(''); - stdout = eraseFirstSpace(stdout); expect(stdout).toEqual(outputText); done(err); } diff --git a/test/flags-require.js b/test/flags-require.js index 6cfa1d84..c9165c32 100644 --- a/test/flags-require.js +++ b/test/flags-require.js @@ -1,36 +1,39 @@ '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 eraseTime = require('./tool/erase-time'); +var eraseLapse = require('./tool/erase-lapse'); +var cmdSep = require('./tool/cmd-sep'); + +var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); +var baseDir = path.join(__dirname, '..'); + 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); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--require ../test-module.js', + '--cwd ./test/fixtures/gulpfiles' + ].join(' '), 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'); + expect(sliceLines(stdout, 0, 1)).toEqual('inside test module'); + expect(sliceLines(stdout, 1, 2)).toEqual('Requiring external module ../test-module.js'); - var chgWorkdirLog = headLines(stdout, 1, 2); + var chgWorkdirLog = sliceLines(stdout, 2, 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))); + stdout = sliceLines(stdout, 4); expect(stdout).toEqual( 'Starting \'default\'...\n' + 'Starting \'test1\'...\n' + @@ -51,35 +54,32 @@ describe('flag: --require', function() { }); 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); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--require ../test-module.js', + '--require ../test-module-2.js', + '--cwd ./test/fixtures/gulpfiles', + ].join(' '), 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'); - + expect(sliceLines(stdout, 0, 1)).toEqual('inside test module'); + expect(sliceLines(stdout, 1, 2)).toEqual('Requiring external module ../test-module.js'); + expect(sliceLines(stdout, 2, 3)).toEqual('inside test module 2'); + expect(sliceLines(stdout, 3, 4)).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); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--require ./null-module.js', + '--cwd ./test/fixtures/gulpfiles', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); @@ -90,13 +90,12 @@ describe('flag: --require', function() { expect(stdout).toNotMatch('inside test module'); expect(stdout).toNotMatch('Requiring external module ../test-module.js'); - var chgWorkdirLog = headLines(stdout, 3); + var chgWorkdirLog = sliceLines(stdout, 0, 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( + expect(sliceLines(stdout, 4)).toEqual( 'Starting \'default\'...\n' + 'Starting \'test1\'...\n' + 'Starting \'noop\'...\n' + @@ -117,9 +116,12 @@ describe('flag: --require', function() { }); it('warns if module throw some error', function(done) { - runner({ verbose: false }) - .gulp('--require ../test-error-module.js', '--cwd ./test/fixtures/gulpfiles') - .run(cb); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--require ../test-error-module.js', + '--cwd ./test/fixtures/gulpfiles', + ].join(' '), cb); function cb(err, stdout, stderr) { stdout = eraseLapse(eraseTime(stdout)); @@ -129,13 +131,12 @@ describe('flag: --require', function() { expect(stdout).toMatch('Error: from error module'); expect(stdout).toNotMatch('inside error module'); - var chgWorkdirLog = headLines(stdout, 3); + var chgWorkdirLog = sliceLines(stdout, 0, 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( + expect(sliceLines(stdout, 4)).toEqual( 'Starting \'default\'...\n' + 'Starting \'test1\'...\n' + 'Starting \'noop\'...\n' + diff --git a/test/flags-series.js b/test/flags-series.js index 6ab5e694..a9b75d3c 100644 --- a/test/flags-series.js +++ b/test/flags-series.js @@ -1,23 +1,30 @@ '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 cmdSep = require('./tool/cmd-sep'); + +var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); +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); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + 'test5 test6', + '--series', + '--cwd ./test/fixtures/gulpfiles' + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); 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 +36,18 @@ 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); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + 'test5 test6', + '--cwd ./test/fixtures/gulpfiles', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); expect(stderr).toEqual(''); expect(stdout).toNotMatch('Starting \'anon\''); - stdout = eraseLapse(eraseTime(skipLines(stdout, 2))); - expect(stdout).toEqual( + 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..708a3804 100644 --- a/test/flags-silent.js +++ b/test/flags-silent.js @@ -1,14 +1,23 @@ 'use strict'; var expect = require('expect'); -var runner = require('gulp-test-tools').gulpRunner; +var exec = require('child_process').exec; +var path = require('path'); + +var cmdSep = require('./tool/cmd-sep'); + +var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); +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); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--silent', + '--cwd ./test/fixtures/gulpfiles', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); diff --git a/test/flags-tasks-json.js b/test/flags-tasks-json.js index 27b043d7..cf6a09da 100644 --- a/test/flags-tasks-json.js +++ b/test/flags-tasks-json.js @@ -1,20 +1,26 @@ '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 cmdSep = require('./tool/cmd-sep'); + +var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); +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); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--tasks-json', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile.js' + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); @@ -27,11 +33,14 @@ 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); + + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--tasks-json', + '--cwd ', cwdPath, + '--gulpfile ', gulpfilePath, + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); @@ -48,15 +57,17 @@ 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); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--tasks-json ../../output/tasks.json', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile.js', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); 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,9 +81,12 @@ 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); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--tasks-json', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); diff --git a/test/flags-tasks-simple.js b/test/flags-tasks-simple.js index a44bd91c..75ebdede 100644 --- a/test/flags-tasks-simple.js +++ b/test/flags-tasks-simple.js @@ -1,19 +1,26 @@ '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 cmdSep = require('./tool/cmd-sep'); + +var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); +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); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--tasks-simple', + '--cwd ./test/fixtures/gulpfiles', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); @@ -27,9 +34,12 @@ 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); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--tasks-simple', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js' + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); diff --git a/test/flags-tasks.js b/test/flags-tasks.js index 10662cc1..ec432920 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 cmdSep = require('./tool/cmd-sep'); + +var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); +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); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--tasks --sort-tasks --cwd ./test/fixtures/gulpfiles', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); 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); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--tasks', '--sort-tasks', + '--gulpfile ./test/fixtures/gulpfiles/with-desc-and-flags.js', + '--cwd ./test/fixtures', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); 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) { + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--tasks', '--sort-tasks', + '--gulpfile ./test/fixtures/gulpfiles/by-unwrap-and-not-by-unwrap.js', + '--cwd ./test/fixtures', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); 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); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); 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); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', + '--sort-tasks', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); 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); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', + '--tasks-depth 4', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); 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); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', + '--depth 4', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); 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); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', + '--compact-tasks', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); 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..977387f6 100644 --- a/test/flags-v8flags.js +++ b/test/flags-v8flags.js @@ -1,48 +1,45 @@ '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 cmdSep = require('./tool/cmd-sep'); + +var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); +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); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--lazy', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); 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); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--lazy --harmony' + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); 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..78a514c2 100644 --- a/test/flags-verify.js +++ b/test/flags-verify.js @@ -1,25 +1,30 @@ '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 cmdSep = require('./tool/cmd-sep'); + +var baseDir = path.join(__dirname, '..'); +var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); + 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); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--verify invalid-package.json', + '--cwd ./test/fixtures/verify/', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toNotEqual(null); 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 +34,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); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--verify valid-package.json', '--cwd ./test/fixtures/verify/', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); 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 +53,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); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--verify', '--cwd', path.resolve('./test/fixtures/verify/'), + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toNotEqual(null); 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..a9e26626 100644 --- a/test/flags-version.js +++ b/test/flags-version.js @@ -1,18 +1,26 @@ '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 cmdSep = require('./tool/cmd-sep'); + var cliVersion = require('../package.json').version; var gulpVersion = require('gulp/package.json').version; +var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); +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); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--version --cwd ./test/fixtures/gulpfiles', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); @@ -27,9 +35,11 @@ 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); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--version --gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js', + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); @@ -44,9 +54,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); + exec([ + 'cd ' + baseDir + cmdSep, + gulpCmd, + '--version', '--cwd', os.tmpdir(), + ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); 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..2b536750 --- /dev/null +++ b/test/sync-task.js @@ -0,0 +1,81 @@ +'use strict'; + +var expect = require('expect'); +var exec = require('child_process').exec; +var path = require('path'); + +var sliceLines = require('./tool/slice-lines'); +var cmdSep = require('./tool/cmd-sep'); + +var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); + +describe('sync-task', function() { + it('should return error code 1 if any tasks did not complete', function(done) { + exec([ + 'cd ' + path.join(__dirname, 'fixtures/gulpfiles') + cmdSep, + gulpCmd, + 'test6 test7 test8', + ].join(' '), cb); + + function cb(err) { + expect(err).toNotEqual(null); + expect(err.code).toEqual(1); + done(); + } + }); + + it('should log tasks which did not complete', function(done) { + exec([ + 'cd ' + path.join(__dirname, 'fixtures/gulpfiles') + cmdSep, + gulpCmd, + 'test6 test7 test8', + ].join(' '), 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) { + exec([ + 'cd ' + path.join(__dirname, '..') + cmdSep, + gulpCmd, + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-parallel-failure.js' + ].join(' '), cb); + + function cb(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) { + exec([ + 'cd ' + path.join(__dirname, '..') + cmdSep, + gulpCmd, + '--continue --gulpfile ./test/fixtures/gulpfiles/gulpfile-parallel-failure.js', + ].join(' '), cb); + + function cb(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) { + exec([ + 'cd ' + path.join(__dirname, '..') + cmdSep, + gulpCmd, + '--continue --gulpfile ./test/fixtures/gulpfiles/gulpfile-parallel-failure.js broken', + ].join(' '), cb); + + function cb(err, stdout) { + expect(stdout).toInclude('The following tasks did not complete: broken, notCompleting1\n'); + done(); + } + }); +}); diff --git a/test/tool/cmd-sep.js b/test/tool/cmd-sep.js new file mode 100644 index 00000000..7b3acfc7 --- /dev/null +++ b/test/tool/cmd-sep.js @@ -0,0 +1,5 @@ +'use strict'; + +var os = require('os'); + +module.exports = os.platform() === 'win32' ? '&' : ';'; 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/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; From 4868529aee0e681173cbc2142773dd616619dc92 Mon Sep 17 00:00:00 2001 From: sttk Date: Sun, 20 Nov 2022 18:10:08 +0900 Subject: [PATCH 03/35] update: replace ansi-colors and color-support to chalk --- index.js | 30 ++++++++++---------- lib/shared/ansi.js | 41 --------------------------- lib/shared/cli-options.js | 38 ++++++++++++------------- lib/shared/log/blacklist-error.js | 4 +-- lib/shared/log/tasks.js | 14 ++++----- lib/shared/log/verify.js | 8 +++--- lib/versioned/^3.7.0/index.js | 6 ++-- lib/versioned/^3.7.0/log/events.js | 16 +++++------ lib/versioned/^4.0.0-alpha.1/index.js | 8 +++--- lib/versioned/^4.0.0-alpha.2/index.js | 8 +++--- lib/versioned/^4.0.0/index.js | 8 +++--- lib/versioned/^4.0.0/log/events.js | 14 ++++----- lib/versioned/^4.0.0/log/sync-task.js | 8 +++--- package.json | 3 +- test/execution-errors.js | 2 +- 15 files changed, 83 insertions(+), 125 deletions(-) delete mode 100644 lib/shared/ansi.js diff --git a/index.js b/index.js index 258c86ac..73340672 100644 --- a/index.js +++ b/index.js @@ -8,7 +8,7 @@ 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'); @@ -55,8 +55,8 @@ var cli = new Liftoff({ }); var usage = - '\n' + ansi.bold('Usage:') + - ' gulp ' + ansi.blue('[options]') + ' tasks'; + '\n' + chalk.bold('Usage:') + + ' gulp ' + chalk.blue('[options]') + ' tasks'; var parser = yargs.usage(usage, cliOptions); var opts = parser.argv; @@ -66,24 +66,24 @@ cli.on('require', function(name) { // Without the .mjs require hook, rechoir blows up // However, we don't want to show the mjs-stub loader in the logs if (path.basename(name, '.js') !== 'mjs-stub') { - log.info('Requiring external module', ansi.magenta(name)); + log.info('Requiring external module', chalk.magenta(name)); } }); cli.on('requireFail', 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); }); @@ -164,8 +164,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 +177,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 +192,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,7 +201,7 @@ 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); } 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/cli-options.js b/lib/shared/cli-options.js index 09d98e3d..9e211bea 100644 --- a/lib/shared/cli-options.js +++ b/lib/shared/cli-options.js @@ -1,24 +1,24 @@ 'use strict'; -var ansi = require('./ansi'); +var chalk = require('chalk'); module.exports = { 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: { type: 'string', requiresArg: true, - desc: ansi.gray( + desc: chalk.gray( 'Will require a module before running the gulpfile. ' + 'This is useful for transpilers but also has other applications.'), }, @@ -26,35 +26,35 @@ module.exports = { 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 +63,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 +95,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,7 +115,7 @@ 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.'), }, 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/tasks.js b/lib/shared/log/tasks.js index 0b76b088..bca4016a 100644 --- a/lib/shared/log/tasks.js +++ b/lib/shared/log/tasks.js @@ -6,7 +6,7 @@ var log = require('gulplog'); var sortBy = require('array-sort'); var isObject = require('isobject'); -var ansi = require('../ansi'); +var chalk = require('chalk'); var copyTree = require('./copy-tree'); function logTasks(tree, opts, getTask) { @@ -142,20 +142,20 @@ function printTreeList(lines, spacer, lineInfos) { lines.forEach(function(branch, index) { var info = lineInfos[index]; - var line = ansi.white(branch); + var line = chalk.white(branch); if (info.type === 'top') { - line += ansi.cyan(info.name); + line += chalk.cyan(info.name); if (info.desc.length > 0) { - line += spacer(index) + ansi.white(info.desc); + line += spacer(index) + chalk.white(info.desc); } } else if (info.type === 'option') { - line += ansi.magenta(info.name); + line += chalk.magenta(info.name); if (info.desc.length > 0) { - line += spacer(index) + ansi.white('…' + info.desc); + line += spacer(index) + chalk.white('…' + info.desc); } } else { // If (info.type === 'child') { - line += ansi.white(info.name); + line += chalk.white(info.name); } log.info(line); 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/versioned/^3.7.0/index.js b/lib/versioned/^3.7.0/index.js index b3a0da55..7eade93f 100644 --- a/lib/versioned/^3.7.0/index.js +++ b/lib/versioned/^3.7.0/index.js @@ -4,13 +4,13 @@ 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'); @@ -35,7 +35,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); @@ -54,7 +54,7 @@ function execute(opts, env, config) { if (config.description && typeof config.description === 'string') { tree.label = 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; diff --git a/lib/versioned/^3.7.0/log/events.js b/lib/versioned/^3.7.0/log/events.js index b7bd00a8..d2fda5ce 100644 --- a/lib/versioned/^3.7.0/log/events.js +++ b/lib/versioned/^3.7.0/log/events.js @@ -2,8 +2,8 @@ var log = require('gulplog'); var prettyTime = require('pretty-hrtime'); +var chalk = require('chalk'); -var ansi = require('../../../shared/ansi'); var exit = require('../../../shared/exit'); var formatError = require('../format-error'); @@ -26,14 +26,14 @@ function logEvents(gulpInst) { gulpInst.on('task_start', function(e) { // TODO: batch these // so when 5 tasks start at once it only logs one time with all 5 - log.info('Starting', '\'' + ansi.cyan(e.task) + '\'...'); + log.info('Starting', '\'' + chalk.cyan(e.task) + '\'...'); }); gulpInst.on('task_stop', function(e) { var time = prettyTime(e.hrDuration); log.info( - 'Finished', '\'' + ansi.cyan(e.task) + '\'', - 'after', ansi.magenta(time) + 'Finished', '\'' + chalk.cyan(e.task) + '\'', + 'after', chalk.magenta(time) ); }); @@ -41,16 +41,16 @@ function logEvents(gulpInst) { var msg = formatError(e); var time = prettyTime(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..0b68558c 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'); @@ -55,7 +55,7 @@ function execute(opts, env, config) { if (config.description && typeof config.description === 'string') { tree.label = 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) { @@ -78,7 +78,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 +86,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..52badc80 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'); @@ -57,7 +57,7 @@ function execute(opts, env, config) { if (config.description && typeof config.description === 'string') { tree.label = 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)); @@ -78,7 +78,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 +86,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..3553c015 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'); @@ -57,7 +57,7 @@ function execute(opts, env, config) { if (config.description && typeof config.description === 'string') { tree.label = 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)); @@ -78,7 +78,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 +86,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..4b398b89 100644 --- a/lib/versioned/^4.0.0/log/events.js +++ b/lib/versioned/^4.0.0/log/events.js @@ -3,7 +3,7 @@ var log = require('gulplog'); var prettyTime = require('pretty-hrtime'); -var ansi = require('../../../shared/ansi'); +var chalk = require('chalk'); var formatError = require('../format-error'); // Wire up logging events @@ -16,7 +16,7 @@ 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) { @@ -24,8 +24,8 @@ function logEvents(gulpInst) { /* 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) ); }); @@ -34,9 +34,9 @@ function logEvents(gulpInst) { var time = prettyTime(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/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 152e4658..2ccf39f5 100644 --- a/package.json +++ b/package.json @@ -29,11 +29,10 @@ "test": "nyc mocha --async-only --timeout 5000 test/lib test" }, "dependencies": { - "ansi-colors": "^4.1.3", "archy": "^1.0.0", "array-sort": "^1.0.0", + "chalk": "^4.1.2", "concat-stream": "^2.0.0", - "color-support": "^1.1.3", "copy-props": "^4.0.0", "fancy-log": "^2.0.0", "gulplog": "^2.0.1", diff --git a/test/execution-errors.js b/test/execution-errors.js index 67f34932..8fd9ca60 100644 --- a/test/execution-errors.js +++ b/test/execution-errors.js @@ -44,7 +44,7 @@ describe('execution error', function() { expect(err).toNotEqual(null); expect(err.code).toEqual(1); expect(eraseTime(stdout)).toEqual(''); - expect(eraseTime(stderr)).toEqual('Unsupported gulp version\n'); + expect(eraseTime(stderr)).toEqual('Unsupported gulp version 1.2.3\n'); done(); } }); From da59456d54f658eb5273021173571885fe0f245c Mon Sep 17 00:00:00 2001 From: sttk Date: Sun, 20 Nov 2022 18:21:17 +0900 Subject: [PATCH 04/35] update: remove array-sort from dependencies --- lib/shared/log/tasks.js | 13 +++++++++++-- package.json | 1 - 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/shared/log/tasks.js b/lib/shared/log/tasks.js index bca4016a..b9b79828 100644 --- a/lib/shared/log/tasks.js +++ b/lib/shared/log/tasks.js @@ -3,7 +3,6 @@ var archy = require('archy'); var log = require('gulplog'); -var sortBy = require('array-sort'); var isObject = require('isobject'); var chalk = require('chalk'); @@ -11,7 +10,7 @@ var copyTree = require('./copy-tree'); function logTasks(tree, opts, getTask) { if (opts.sortTasks) { - tree.nodes = sortBy(tree.nodes, 'label'); + tree.nodes = tree.nodes.sort(compareByLabel); } var lineInfos = []; @@ -162,5 +161,15 @@ function printTreeList(lines, spacer, lineInfos) { }); } +function compareByLabel(a, b) { + if (!b.label) { + return -1; + } else if (!a.label) { + return 1; + } else { + return (a.label <= b.label) ? -1 : 1; + } +} + module.exports = logTasks; diff --git a/package.json b/package.json index 2ccf39f5..f0e808b8 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,6 @@ }, "dependencies": { "archy": "^1.0.0", - "array-sort": "^1.0.0", "chalk": "^4.1.2", "concat-stream": "^2.0.0", "copy-props": "^4.0.0", From 3a03cff712e5d2fa3dc4709ecfda9310c4b33d5e Mon Sep 17 00:00:00 2001 From: sttk Date: Sun, 20 Nov 2022 20:34:56 +0900 Subject: [PATCH 05/35] update: remove isobject from dependencies --- lib/shared/is-object.js | 7 +++++++ lib/shared/log/tasks.js | 2 +- lib/versioned/^4.0.0/log/get-task.js | 2 +- package.json | 1 - 4 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 lib/shared/is-object.js 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/tasks.js b/lib/shared/log/tasks.js index b9b79828..d6842353 100644 --- a/lib/shared/log/tasks.js +++ b/lib/shared/log/tasks.js @@ -3,7 +3,7 @@ var archy = require('archy'); var log = require('gulplog'); -var isObject = require('isobject'); +var isObject = require('../is-object'); var chalk = require('chalk'); var copyTree = require('./copy-tree'); 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/package.json b/package.json index f0e808b8..6b0454bf 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,6 @@ "fancy-log": "^2.0.0", "gulplog": "^2.0.1", "interpret": "^1.4.0", - "isobject": "^4.0.0", "liftoff": "^3.1.0", "matchdep": "^2.0.0", "mute-stdout": "^2.0.0", From 9db1f81d63ffc409bfb1ce40aae1dad5bcc23d9b Mon Sep 17 00:00:00 2001 From: sttk Date: Sat, 26 Nov 2022 17:39:29 +0900 Subject: [PATCH 06/35] update: upgrade yargs to 16.2.0 --- index.js | 9 +-- .../{cli-options.js => options/parser.js} | 15 +++- package.json | 2 +- test/expected/flags-help.txt | 72 ++++++++++--------- test/fixtures/logging.js | 5 +- 5 files changed, 55 insertions(+), 48 deletions(-) rename lib/shared/{cli-options.js => options/parser.js} (92%) diff --git a/index.js b/index.js index 73340672..55229a52 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ 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'); @@ -12,7 +12,7 @@ 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; @@ -54,11 +54,6 @@ var cli = new Liftoff({ }, }); -var usage = - '\n' + chalk.bold('Usage:') + - ' gulp ' + chalk.blue('[options]') + ' tasks'; - -var parser = yargs.usage(usage, cliOptions); var opts = parser.argv; cli.on('require', function(name) { diff --git a/lib/shared/cli-options.js b/lib/shared/options/parser.js similarity index 92% rename from lib/shared/cli-options.js rename to lib/shared/options/parser.js index 9e211bea..2864fd04 100644 --- a/lib/shared/cli-options.js +++ b/lib/shared/options/parser.js @@ -1,8 +1,13 @@ 'use strict'; 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', @@ -118,5 +123,11 @@ module.exports = { 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/package.json b/package.json index 6b0454bf..1cb1a02e 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "replace-homedir": "^2.0.0", "semver-greatest-satisfied-range": "^2.0.0", "v8flags": "^3.2.0", - "yargs": "^7.1.0" + "yargs": "^16.2.0" }, "devDependencies": { "babel-preset-es2015": "^6.5.0", diff --git a/test/expected/flags-help.txt b/test/expected/flags-help.txt index eb275983..6bcc51fd 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] + --require Will require 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/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); From 4b7598842a94af4f87d42b5717a2fb11793341cd Mon Sep 17 00:00:00 2001 From: sttk Date: Sat, 26 Nov 2022 19:40:37 +0900 Subject: [PATCH 07/35] update: upgrade liftoff to 4.0.0 --- index.js | 65 ++++++++--- lib/shared/config/env-flags.js | 4 +- lib/shared/config/load-files.js | 30 ----- lib/shared/config/normalize-config.js | 17 +++ lib/shared/options/parser.js | 4 +- package.json | 11 +- test/config-description.js | 16 +++ test/config-flags-gulpfile.js | 6 +- test/config-flags-log-level.js | 18 +-- test/config-flags-preload.js | 105 ++++++++++++++++++ test/config-flags-require.js | 98 ---------------- test/expected/config/output2.txt | 2 + test/expected/flags-help.txt | 2 +- test/fixtures/.babelrc | 3 - .../{require => preload}/array/.gulp.json | 2 +- .../{require => preload}/array/gulpfile.js | 0 .../{require => preload}/array/preload_one.js | 0 .../{require => preload}/array/preload_two.js | 0 .../join-flags/.gulp.json | 2 +- .../join-flags/gulpfile.js | 0 .../join-flags/preload_one.js | 0 .../join-flags/preload_two.js | 0 .../flags/{require => preload}/preload.js | 0 .../config/flags/preload/string/.gulp.json | 5 + .../{require => preload}/string/gulpfile.js | 0 .../{require => preload}/string/preload.js | 0 .../with-absolute/.gulp.js | 2 +- .../with-absolute/gulpfile.js | 0 .../config/flags/preload/with-cwd/.gulp.json | 5 + .../{require => preload}/with-cwd/gulpfile.js | 0 .../config/flags/require/string/.gulp.json | 5 - .../config/flags/require/with-cwd/.gulp.json | 5 - test/fixtures/config/foo/bar/baz/.gitkeep | 0 .../foo/bar/{baz => quux}/.gulp.babel.js | 2 - test/{flags-require.js => flags-preload.js} | 57 +++++----- test/lib/config-env-flags.js | 10 +- test/lib/config-load-files.js | 58 ---------- test/lib/normalize-config.js | 52 +++++++++ 38 files changed, 313 insertions(+), 273 deletions(-) delete mode 100644 lib/shared/config/load-files.js create mode 100644 lib/shared/config/normalize-config.js create mode 100644 test/config-flags-preload.js delete mode 100644 test/config-flags-require.js create mode 100644 test/expected/config/output2.txt delete mode 100644 test/fixtures/.babelrc rename test/fixtures/config/flags/{require => preload}/array/.gulp.json (80%) rename test/fixtures/config/flags/{require => preload}/array/gulpfile.js (100%) rename test/fixtures/config/flags/{require => preload}/array/preload_one.js (100%) rename test/fixtures/config/flags/{require => preload}/array/preload_two.js (100%) rename test/fixtures/config/flags/{require => preload}/join-flags/.gulp.json (74%) rename test/fixtures/config/flags/{require => preload}/join-flags/gulpfile.js (100%) rename test/fixtures/config/flags/{require => preload}/join-flags/preload_one.js (100%) rename test/fixtures/config/flags/{require => preload}/join-flags/preload_two.js (100%) rename test/fixtures/config/flags/{require => preload}/preload.js (100%) create mode 100644 test/fixtures/config/flags/preload/string/.gulp.json rename test/fixtures/config/flags/{require => preload}/string/gulpfile.js (100%) rename test/fixtures/config/flags/{require => preload}/string/preload.js (100%) rename test/fixtures/config/flags/{require => preload}/with-absolute/.gulp.js (57%) rename test/fixtures/config/flags/{require => preload}/with-absolute/gulpfile.js (100%) create mode 100644 test/fixtures/config/flags/preload/with-cwd/.gulp.json rename test/fixtures/config/flags/{require => preload}/with-cwd/gulpfile.js (100%) delete mode 100644 test/fixtures/config/flags/require/string/.gulp.json delete mode 100644 test/fixtures/config/flags/require/with-cwd/.gulp.json create mode 100644 test/fixtures/config/foo/bar/baz/.gitkeep rename test/fixtures/config/foo/bar/{baz => quux}/.gulp.babel.js (82%) rename test/{flags-require.js => flags-preload.js} (66%) delete mode 100644 test/lib/config-load-files.js create mode 100644 test/lib/normalize-config.js diff --git a/index.js b/index.js index 55229a52..c5d2212d 100644 --- a/index.js +++ b/index.js @@ -19,7 +19,7 @@ var cliVersion = require('./package.json').version; var getBlacklist = require('./lib/shared/get-blacklist'); var toConsole = require('./lib/shared/log/to-console'); -var loadConfigFiles = require('./lib/shared/config/load-files'); +var normalizeConfig = require('./lib/shared/config/normalize-config'); var mergeConfigToCliFlags = require('./lib/shared/config/cli-flags'); var mergeConfigToEnvFlags = require('./lib/shared/config/env-flags'); @@ -41,33 +41,64 @@ var cli = new Liftoff({ extensions: interpret.jsVariants, v8flags: v8flags, configFiles: { - '.gulp': { - home: { - path: '~', + '.gulp': [ + { + path: '.', extensions: interpret.extensions, + findUp: true, }, - cwd: { - path: '.', + { + path: '~', extensions: interpret.extensions, }, - }, + ], }, }); var opts = parser.argv; -cli.on('require', function(name) { +cli.on('preload:before', 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 if (path.basename(name, '.js') !== 'mjs-stub') { - log.info('Requiring external module', chalk.magenta(name)); + log.info('Preloading external module:', chalk.magenta(name)); } }); -cli.on('requireFail', function(name, error) { +cli.on('preload: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 + if (path.basename(name, '.js') !== 'mjs-stub') { + log.info('Preloaded external module:', chalk.magenta(name)); + } +}); + +cli.on('preload:failure', function(name, error) { log.warn( - chalk.yellow('Failed to load external module'), + 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('Loaded external module:', chalk.magenta(name)); + } +}); + +cli.on('loader:failure', function(name, error) { + log.warn( + chalk.yellow('Failed to load external module:'), chalk.magenta(name) ); /* istanbul ignore else */ @@ -87,14 +118,16 @@ 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); + var key = '.gulp'; + var cfgPath = env.configFiles[key]; + var cfg = normalizeConfig(env.config[key], cfgPath); + env.config[key] = cfg; + opts = mergeConfigToCliFlags(opts, cfg); env = mergeConfigToEnvFlags(env, cfg, opts); - env.configProps = cfg; // Set up event listeners for logging again after configuring. toConsole(log, opts); @@ -203,5 +236,5 @@ function handleArguments(env) { // Load and execute the CLI version var versionedDir = path.join(__dirname, '/lib/versioned/', range, '/'); - require(versionedDir)(opts, env, env.configProps); + require(versionedDir)(opts, env, env.config['.gulp']); } diff --git a/lib/shared/config/env-flags.js b/lib/shared/config/env-flags.js index a5a4abd7..583f0de2 100644 --- a/lib/shared/config/env-flags.js +++ b/lib/shared/config/env-flags.js @@ -6,7 +6,7 @@ var copyProps = require('copy-props'); var toFrom = { configPath: 'flags.gulpfile', configBase: 'flags.gulpfile', - require: 'flags.require', + preload: 'flags.preload', nodeFlags: 'flags.nodeFlags', }; @@ -30,7 +30,7 @@ function mergeConfigToEnvFlags(env, config, cliOpts) { return; } - if (envInfo.keyChain === 'require') { + if (envInfo.keyChain === 'preload') { return [].concat(envInfo.value, configInfo.value); } 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/normalize-config.js b/lib/shared/config/normalize-config.js new file mode 100644 index 00000000..caece43c --- /dev/null +++ b/lib/shared/config/normalize-config.js @@ -0,0 +1,17 @@ +'use strict'; + +var copyProps = require('copy-props'); +var path = require('path'); + +function normalizeConfig(config, filePath) { + return copyProps(config, {}, convert); + + function convert(loadedInfo) { + if (loadedInfo.keyChain === 'flags.gulpfile') { + return path.resolve(path.dirname(filePath), loadedInfo.value); + } + return loadedInfo.value; + } +} + +module.exports = normalizeConfig; diff --git a/lib/shared/options/parser.js b/lib/shared/options/parser.js index 2864fd04..94801742 100644 --- a/lib/shared/options/parser.js +++ b/lib/shared/options/parser.js @@ -20,11 +20,11 @@ var options = { desc: chalk.gray( 'Print the global and local gulp versions.'), }, - require: { + preload: { type: 'string', requiresArg: true, desc: chalk.gray( - 'Will require a module before running the gulpfile. ' + + 'Will preload a module before running the gulpfile. ' + 'This is useful for transpilers but also has other applications.'), }, gulpfile: { diff --git a/package.json b/package.json index 1cb1a02e..1ba6ad54 100644 --- a/package.json +++ b/package.json @@ -35,19 +35,20 @@ "copy-props": "^4.0.0", "fancy-log": "^2.0.0", "gulplog": "^2.0.1", - "interpret": "^1.4.0", - "liftoff": "^3.1.0", + "interpret": "^3.1.1", + "liftoff": "^4.0.0", "matchdep": "^2.0.0", "mute-stdout": "^2.0.0", "pretty-hrtime": "^1.0.3", "replace-homedir": "^2.0.0", "semver-greatest-satisfied-range": "^2.0.0", - "v8flags": "^3.2.0", + "v8flags": "^4.0.0", "yargs": "^16.2.0" }, "devDependencies": { - "babel-preset-es2015": "^6.5.0", - "babel-register": "^6.26.0", + "@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": "^1.20.2", diff --git a/test/config-description.js b/test/config-description.js index 3e904099..5e1f3e56 100644 --- a/test/config-description.js +++ b/test/config-description.js @@ -47,6 +47,22 @@ describe('config: description', function() { } }); + it('Should configure with a .gulp.* file in cwd even if it is not a project root', function(done) { + exec([ + 'cd ' + path.join(baseDir, 'foo/bar/quux') + cmdSep, + gulpCmd, + '--tasks', + ].join(' '), cb); + + function cb(err, stdout, stderr) { + expect(err).toEqual(null); + 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) { exec([ 'cd ' + path.join(baseDir, 'qux') + cmdSep, diff --git a/test/config-flags-gulpfile.js b/test/config-flags-gulpfile.js index 9051d105..1cfc2d06 100644 --- a/test/config-flags-gulpfile.js +++ b/test/config-flags-gulpfile.js @@ -47,7 +47,7 @@ describe('config: flags.gulpfile', function() { } }); - it('Should ignore a ./gulp.* file if another directory is specified by --cwd', function(done) { + it('Should load a ./gulp.* file in a directory specified by --cwd', function(done) { exec([ 'cd ' + baseDir + cmdSep, gulpCmd, @@ -58,7 +58,7 @@ describe('config: flags.gulpfile', function() { expect(err).toEqual(null); expect(stderr).toEqual(''); expect(sliceLines(stdout, 3, 4)).toEqual( - 'Another gulpfile : ' + path.join(baseDir, 'cwd/gulpfile.js') + 'This gulpfile : ' + path.join(baseDir, 'is/here/mygulpfile.js') ); done(err); } @@ -110,7 +110,7 @@ describe('config: flags.gulpfile', function() { function cb(err, stdout, stderr) { expect(err).toEqual(null); expect(stderr).toEqual(''); - expect(sliceLines(stdout, 0, 1)).toEqual('Requiring external module babel-register'); + 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); diff --git a/test/config-flags-log-level.js b/test/config-flags-log-level.js index 8569f81e..0cf72ebf 100644 --- a/test/config-flags-log-level.js +++ b/test/config-flags-log-level.js @@ -34,14 +34,14 @@ describe('config: flag.logLevel', function() { exec([ 'cd ' + baseDir + cmdSep, gulpCmd, - '--require mymodule', + '--preload mymodule', ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); expect(stderr).toEqual(''); - expect(sliceLines(stdout, 0, 2)).toMatch( - 'Failed to load external module mymodule\n' + + expect(sliceLines(stdout, 1, 3)).toMatch( + 'Failed to preload external module: mymodule\n' + 'Error: Cannot find module \'mymodule\' from \''); done(); } @@ -86,7 +86,7 @@ describe('config: flag.logLevel', function() { exec([ 'cd ' + path.join(baseDir, 'L') + cmdSep, gulpCmd, - '--require mymodule', + '--preload mymodule', ].join(' '), cb); function cb(err, stdout, stderr) { @@ -133,14 +133,14 @@ describe('config: flag.logLevel', function() { exec([ 'cd ' + path.join(baseDir, 'LL') + cmdSep, gulpCmd, - '--require mymodule', + '--preload mymodule', ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); expect(stderr).toEqual(''); expect(eraseTime(stdout)).toMatch( - 'Failed to load external module mymodule\n' + + 'Failed to preload external module: mymodule\n' + 'Error: Cannot find module \'mymodule\' from \''); done(); } @@ -182,14 +182,14 @@ describe('config: flag.logLevel', function() { exec([ 'cd ' + path.join(baseDir, 'LLL') + cmdSep, gulpCmd, - '--require mymodule', + '--preload mymodule', ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); expect(stderr).toEqual(''); expect(eraseTime(stdout)).toMatch( - 'Failed to load external module mymodule\n' + + 'Failed to preload external module: mymodule\n' + 'Error: Cannot find module \'mymodule\' from \''); done(); } @@ -219,7 +219,7 @@ describe('config: flag.logLevel', function() { 'cd ' + path.join(baseDir, 'LLL') + cmdSep, gulpCmd, '-L', - '--require mymodule', + '--preload mymodule', ].join(' '), cb); function cb(err, stdout, stderr) { diff --git a/test/config-flags-preload.js b/test/config-flags-preload.js new file mode 100644 index 00000000..917551e6 --- /dev/null +++ b/test/config-flags-preload.js @@ -0,0 +1,105 @@ +'use strict'; + +var expect = require('expect'); +var exec = require('child_process').exec; +var path = require('path'); + +var sliceLines = require('./tool/slice-lines'); +var cmdSep = require('./tool/cmd-sep'); + +var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); +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) { + exec([ + 'cd ' + path.join(baseDir, 'array') + cmdSep, + gulpCmd, + ].join(' '), cb); + + function cb(err, stdout, stderr) { + expect(err).toEqual(null); + 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) { + exec([ + 'cd ' + path.join(baseDir, 'string') + cmdSep, + gulpCmd, + ].join(' '), cb); + + function cb(err, stdout, stderr) { + expect(err).toEqual(null); + 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.require', function(done) { + exec([ + 'cd ' + path.join(baseDir, 'join-flags') + cmdSep, + gulpCmd, + '--preload ./preload_one', + ].join(' '), cb); + + function cb(err, stdout, stderr) { + expect(err).toEqual(null); + 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) { + exec([ + 'cd ' + path.join(__dirname, 'fixtures/config') + cmdSep, + gulpCmd, + '--cwd flags/preload/with-cwd', + ].join(' '), cb); + + function cb(err, stdout, stderr) { + expect(err).toEqual(null); + 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) { + exec([ + 'cd ' + path.join(__dirname, 'fixtures/config') + cmdSep, + gulpCmd, + '--cwd flags/preload/with-absolute', + ].join(' '), cb); + + function cb(err, stdout, stderr) { + expect(err).toEqual(null); + 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 abc43023..00000000 --- a/test/config-flags-require.js +++ /dev/null @@ -1,98 +0,0 @@ -'use strict'; - -var expect = require('expect'); -var exec = require('child_process').exec; -var path = require('path'); - -var sliceLines = require('./tool/slice-lines'); -var cmdSep = require('./tool/cmd-sep'); - -var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); -var baseDir = path.join(__dirname, 'fixtures/config/flags/require'); - -describe('config: flags.require', function() { - - it('Should configure with an array in a .gulp.* file', function(done) { - exec([ - 'cd ' + path.join(baseDir, 'array') + cmdSep, - gulpCmd, - ].join(' '), cb); - - function cb(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - expect(sliceLines(stdout, 0, 1)).toEqual('Requiring external module ./preload_one'); - expect(sliceLines(stdout, 1, 2)).toEqual('Requiring external module ./preload_two'); - expect(sliceLines(stdout, 4, 5)).toEqual('preload one!'); - expect(sliceLines(stdout, 5, 6)).toEqual('preload two!'); - done(err); - } - }); - - it('Should configure with a string in a .gulp.* file', function(done) { - exec([ - 'cd ' + path.join(baseDir, 'string') + cmdSep, - gulpCmd, - ].join(' '), cb); - - function cb(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - expect(sliceLines(stdout, 0, 1)).toEqual('Requiring external module ./preload'); - expect(sliceLines(stdout, 3, 4)).toEqual('hello preload!'); - done(err); - } - }); - - it('Combines --require flag with .gulp.* file flags.require', function(done) { - exec([ - 'cd ' + path.join(baseDir, 'join-flags') + cmdSep, - gulpCmd, - '--require ./preload_one', - ].join(' '), cb); - - function cb(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - expect(sliceLines(stdout, 0, 1)).toEqual('Requiring external module ./preload_one'); - expect(sliceLines(stdout, 1, 2)).toEqual('Requiring external module ./preload_two'); - expect(sliceLines(stdout, 4, 5)).toEqual('preload one!'); - expect(sliceLines(stdout, 5, 6)).toEqual('preload two!'); - done(err); - } - }); - - it('resolves relative requires against cwd', function(done) { - exec([ - 'cd ' + path.join(__dirname, 'fixtures/config') + cmdSep, - gulpCmd, - '--cwd flags/require/with-cwd', - ].join(' '), cb); - - function cb(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - expect(sliceLines(stdout, 0, 1)).toEqual('Requiring external module ../preload'); - expect(sliceLines(stdout, 4, 5)).toEqual('hello preload!'); - done(err); - } - }); - - it('works with absolute paths, ignoring cwd', function(done) { - exec([ - 'cd ' + path.join(__dirname, 'fixtures/config') + cmdSep, - gulpCmd, - '--cwd flags/require/with-absolute', - ].join(' '), cb); - - function cb(err, stdout, stderr) { - expect(err).toEqual(null); - expect(stderr).toEqual(''); - var absolute = path.join(__dirname, './fixtures/config/flags/require/preload'); - expect(sliceLines(stdout, 0, 1)).toEqual('Requiring external module ' + absolute); - expect(sliceLines(stdout, 4, 5)).toEqual('hello preload!'); - done(err); - } - }); -}); - diff --git a/test/expected/config/output2.txt b/test/expected/config/output2.txt new file mode 100644 index 00000000..2d9cbf29 --- /dev/null +++ b/test/expected/config/output2.txt @@ -0,0 +1,2 @@ +DESCRIPTION BY .gulp.babel.js in directory foo/bar/baz +└── default diff --git a/test/expected/flags-help.txt b/test/expected/flags-help.txt index 6bcc51fd..fed71d76 100644 --- a/test/expected/flags-help.txt +++ b/test/expected/flags-help.txt @@ -4,7 +4,7 @@ Usage: gulp [options] tasks Options: -h, --help Show this help. [boolean] -v, --version Print the global and local gulp versions.[boolean] - --require Will require a module before running the gulpfile. + --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 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/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 82% rename from test/fixtures/config/foo/bar/baz/.gulp.babel.js rename to test/fixtures/config/foo/bar/quux/.gulp.babel.js index 4e6e98c4..2c0f43e5 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' diff --git a/test/flags-require.js b/test/flags-preload.js similarity index 66% rename from test/flags-require.js rename to test/flags-preload.js index c9165c32..116a0490 100644 --- a/test/flags-require.js +++ b/test/flags-preload.js @@ -12,28 +12,29 @@ var cmdSep = require('./tool/cmd-sep'); var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); var baseDir = path.join(__dirname, '..'); -describe('flag: --require', function() { +describe('flag: --preload', function() { - it('requires module before running gulpfile', function(done) { + it('preloads module before running gulpfile', function(done) { exec([ 'cd ' + baseDir + cmdSep, gulpCmd, - '--require ../test-module.js', + '--preload ../test-module.js', '--cwd ./test/fixtures/gulpfiles' ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); expect(stderr).toEqual(''); - expect(sliceLines(stdout, 0, 1)).toEqual('inside test module'); - expect(sliceLines(stdout, 1, 2)).toEqual('Requiring external module ../test-module.js'); + 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, 2, 3); + 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, 4); + stdout = sliceLines(stdout, 5); expect(stdout).toEqual( 'Starting \'default\'...\n' + 'Starting \'test1\'...\n' + @@ -53,22 +54,24 @@ describe('flag: --require', function() { } }); - it('can require multiple modules before running gulpfile', function(done) { + it('can preload multiple modules before running gulpfile', function(done) { exec([ 'cd ' + baseDir + cmdSep, gulpCmd, - '--require ../test-module.js', - '--require ../test-module-2.js', + '--preload ../test-module.js', + '--preload ../test-module-2.js', '--cwd ./test/fixtures/gulpfiles', ].join(' '), cb); function cb(err, stdout, stderr) { expect(err).toEqual(null); expect(stderr).toEqual(''); - expect(sliceLines(stdout, 0, 1)).toEqual('inside test module'); - expect(sliceLines(stdout, 1, 2)).toEqual('Requiring external module ../test-module.js'); - expect(sliceLines(stdout, 2, 3)).toEqual('inside test module 2'); - expect(sliceLines(stdout, 3, 4)).toEqual('Requiring external module ../test-module-2.js'); + 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); } }); @@ -77,25 +80,27 @@ describe('flag: --require', function() { exec([ 'cd ' + baseDir + cmdSep, gulpCmd, - '--require ./null-module.js', + '--preload ./null-module.js', '--cwd ./test/fixtures/gulpfiles', ].join(' '), 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(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\''); expect(stdout).toNotMatch('inside test module'); - expect(stdout).toNotMatch('Requiring external module ../test-module.js'); + expect(stdout).toNotMatch('Preloaded external module: ../null-module.js'); - var chgWorkdirLog = sliceLines(stdout, 0, 3); + 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, 4)).toEqual( + expect(sliceLines(stdout, 5)).toEqual( 'Starting \'default\'...\n' + 'Starting \'test1\'...\n' + 'Starting \'noop\'...\n' + @@ -119,7 +124,7 @@ describe('flag: --require', function() { exec([ 'cd ' + baseDir + cmdSep, gulpCmd, - '--require ../test-error-module.js', + '--preload ../test-error-module.js', '--cwd ./test/fixtures/gulpfiles', ].join(' '), cb); @@ -127,16 +132,16 @@ describe('flag: --require', function() { 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(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).toNotMatch('inside error module'); - var chgWorkdirLog = sliceLines(stdout, 0, 3); + 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, 4)).toEqual( + expect(sliceLines(stdout, 5)).toEqual( 'Starting \'default\'...\n' + 'Starting \'test1\'...\n' + 'Starting \'noop\'...\n' + diff --git a/test/lib/config-env-flags.js b/test/lib/config-env-flags.js index 955b13c9..dfc43d48 100644 --- a/test/lib/config-env-flags.js +++ b/test/lib/config-env-flags.js @@ -27,7 +27,7 @@ describe('lib: config/env-flags', function() { 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 +41,7 @@ describe('lib: config/env-flags', function() { flags: { silent: false, gulpfile: '/path/to/gulpfile', - require: ['a', 'b'], + preload: ['a', 'b'], }, }; @@ -52,7 +52,7 @@ describe('lib: config/env-flags', function() { var result = mergeConfig(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', @@ -66,7 +66,7 @@ describe('lib: config/env-flags', function() { 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', @@ -80,7 +80,7 @@ describe('lib: config/env-flags', function() { var result = mergeConfig(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', 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/normalize-config.js b/test/lib/normalize-config.js new file mode 100644 index 00000000..95e4a931 --- /dev/null +++ b/test/lib/normalize-config.js @@ -0,0 +1,52 @@ +'use strict'; + +var expect = require('expect'); +var path = require('path'); +var normalizeConfig = require('../../lib/shared/config/normalize-config'); + +var fixturesDir = path.join(__dirname, '../fixtures/config'); + +describe('lib: config/normalize-config', function() { + + it('Should normalize config', function(done) { + var config = { + '.gulp': { + description: 'description by .gulp.js in directory qux', + }, + }; + var configFiles = { + '.gulp': path.join(fixturesDir, 'qux/.gulp.js'), + }; + + var key = '.gulp'; + var cfg = normalizeConfig(config[key], configFiles[key]); + + expect(cfg).toEqual({ + description: 'description by .gulp.js in directory qux', + }); + done(); + }); + + it('Should convert a value of `flags.gulpfile` to absolute path', function(done) { + var config = { + '.gulp': { + flags: { gulpfile: './is/here/mygulpfile.js' }, + }, + }; + var configFiles = { + '.gulp': path.join(fixturesDir, 'flags/gulpfile/.gulp.json'), + }; + + var key = '.gulp'; + var cfg = normalizeConfig(config[key], configFiles[key]); + + expect(cfg).toEqual({ + flags: { + gulpfile: path.join(fixturesDir, + 'flags/gulpfile/is/here/mygulpfile.js'), + }, + }); + done(); + }); + +}); From 76d058164e9252e7798fee634d3a7401b2401cfd Mon Sep 17 00:00:00 2001 From: sttk Date: Sat, 26 Nov 2022 19:47:02 +0900 Subject: [PATCH 08/35] doc: modify README.md --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 30480362..310949fe 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Command Line Utility for Gulp ## Install ```bash -npm install --global gulp-cli +npm install gulp-cli ``` ## Usage @@ -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)] From 40b487e1fab1dc9de68ec81ebbb27c142dd41538 Mon Sep 17 00:00:00 2001 From: sttk Date: Sun, 10 Sep 2023 11:37:26 +0900 Subject: [PATCH 09/35] update: modify for coverage --- index.js | 2 ++ lib/shared/log/tasks.js | 3 ++- lib/shared/require-or-import.js | 1 + test/config-flags-gulpfile.js | 16 ++++++++++++++++ test/expected/with-desc-and-flags.txt | 2 +- .../flags/gulpfile/autoload-fail/.gulp.json | 5 +++++ .../autoload-fail/other_dir/gulpfile.coffee | 1 + test/fixtures/gulpfiles/with-desc-and-flags.js | 2 +- 8 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 test/fixtures/config/flags/gulpfile/autoload-fail/.gulp.json create mode 100644 test/fixtures/config/flags/gulpfile/autoload-fail/other_dir/gulpfile.coffee diff --git a/index.js b/index.js index c5d2212d..ae624d19 100644 --- a/index.js +++ b/index.js @@ -61,6 +61,7 @@ cli.on('preload:before', 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('Preloading external module:', chalk.magenta(name)); } @@ -70,6 +71,7 @@ cli.on('preload: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('Preloaded external module:', chalk.magenta(name)); } diff --git a/lib/shared/log/tasks.js b/lib/shared/log/tasks.js index d6842353..6a3e17e1 100644 --- a/lib/shared/log/tasks.js +++ b/lib/shared/log/tasks.js @@ -162,9 +162,10 @@ function printTreeList(lines, spacer, lineInfos) { } function compareByLabel(a, b) { + /* istanbul ignore if */ if (!b.label) { return -1; - } else if (!a.label) { + } else /* istanbul ignore if */ if (!a.label) { return 1; } else { return (a.label <= b.label) ? -1 : 1; diff --git a/lib/shared/require-or-import.js b/lib/shared/require-or-import.js index 6970ae42..a4016654 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; } diff --git a/test/config-flags-gulpfile.js b/test/config-flags-gulpfile.js index 1cfc2d06..4a8c9ed3 100644 --- a/test/config-flags-gulpfile.js +++ b/test/config-flags-gulpfile.js @@ -117,5 +117,21 @@ describe('config: flags.gulpfile', function() { } }); + it('Should output error logs of autoload if fail to load module for a specified gulpfile', function(done) { + exec([ + 'cd ' + path.join(baseDir, 'autoload-fail') + cmdSep, + gulpCmd, + 'dist', + ].join(' '), cb); + + function cb(err, stdout, stderr) { + expect(err).toNotEqual(null); + expect(stderr).toNotEqual(''); + 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/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/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/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', }; From 52e568a1c962feb940fa86d9f279c0bdd7b19f80 Mon Sep 17 00:00:00 2001 From: sttk Date: Sun, 10 Sep 2023 11:57:04 +0900 Subject: [PATCH 10/35] fix: suppress error on CI --- .github/workflows/dev.yml | 29 ++++++++++++++++++++--------- lib/shared/require-or-import.js | 16 +++++++++++----- package.json | 3 ++- test/esm.js | 3 ++- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index 44f472fb..90a12261 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -53,23 +53,34 @@ jobs: 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 - - name: Coveralls - uses: coverallsapp/github-action@v1.1.2 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - flag-name: ${{matrix.os}}-node-${{ matrix.node }} - parallel: true - coveralls: needs: test name: Finish up runs-on: ubuntu-latest steps: - - name: Coveralls Finished + - 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 }} - parallel-finished: true diff --git a/lib/shared/require-or-import.js b/lib/shared/require-or-import.js index a4016654..4cf5877e 100644 --- a/lib/shared/require-or-import.js +++ b/lib/shared/require-or-import.js @@ -19,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/package.json b/package.json index 1ba6ad54..20e58080 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,8 @@ "lint": "eslint .", "prepare": "marked-man --name gulp docs/CLI.md > gulp.1", "pretest": "npm run lint", - "test": "nyc mocha --async-only --timeout 5000 test/lib test" + "test": "mocha --async-only --timeout 5000 test/lib test", + "cover": "nyc mocha --async-only --timeout 5000 test/lib test" }, "dependencies": { "archy": "^1.0.0", diff --git a/test/esm.js b/test/esm.js index e7e666f7..93b63e13 100644 --- a/test/esm.js +++ b/test/esm.js @@ -16,7 +16,8 @@ var expectedDir = path.join(__dirname, 'expected'); describe('ESM', function() { it('prints the task list', function(done) { - if (semver.lt(process.version, '10.15.3')) { + // Segmentation fault is caused only v10.15.3. + if (semver.eq(process.version, '10.15.3')) { this.skip(); } From 61701677e236d3524621b9d1fa37d1dfe5908268 Mon Sep 17 00:00:00 2001 From: sttk Date: Sun, 27 Nov 2022 16:23:03 +0900 Subject: [PATCH 11/35] test: upgrade expect to 27.5.1 --- package.json | 2 +- test/completion.js | 6 +++--- test/config-description.js | 8 ++++---- test/config-flags-continue.js | 8 ++++---- test/config-flags-gulpfile.js | 16 ++++++++-------- test/config-flags-log-level.js | 28 ++++++++++++++-------------- test/config-flags-node-flags.js | 10 +++++----- test/config-flags-preload.js | 10 +++++----- test/config-flags-series.js | 8 ++++---- test/config-flags-silent.js | 8 ++++---- test/esm.js | 2 +- test/execution-errors.js | 8 ++++---- test/exports-as-tasks.js | 2 +- test/flags-continue.js | 6 +++--- test/flags-gulpfile.js | 4 ++-- test/flags-help.js | 6 +++--- test/flags-preload.js | 14 +++++++------- test/flags-series.js | 6 +++--- test/flags-silent.js | 2 +- test/flags-tasks-json.js | 8 ++++---- test/flags-tasks-simple.js | 4 ++-- test/flags-tasks.js | 16 ++++++++-------- test/flags-v8flags.js | 4 ++-- test/flags-verify.js | 6 +++--- test/flags-version.js | 6 +++--- test/lib/log-copy-tree.js | 30 +++++++++++++++--------------- test/lib/task-tree.js | 2 +- test/logging.js | 10 +++++----- test/sync-task.js | 14 ++++++++++---- 29 files changed, 130 insertions(+), 124 deletions(-) diff --git a/package.json b/package.json index 20e58080..8562f286 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "@babel/register": "^7.18.9", "eslint": "^7.32.0", "eslint-config-gulp": "^5.0.1", - "expect": "^1.20.2", + "expect": "^27.5.1", "gulp": "^4.0.2", "marked-man": "^0.2.1", "mocha": "^8.4.0", diff --git a/test/completion.js b/test/completion.js index a00d9152..2b670d9c 100644 --- a/test/completion.js +++ b/test/completion.js @@ -20,7 +20,7 @@ describe('flag: --completion', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toNotExist(); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(stdout).toEqual(expected); done(err); @@ -37,7 +37,7 @@ describe('flag: --completion', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); + expect(err).not.toBeNull(); expect(stderr).toEqual(''); expect(stdout).toEqual(expected); done(); @@ -51,7 +51,7 @@ describe('flag: --completion', function() { ].join(' '), 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 5e1f3e56..a4cd534a 100644 --- a/test/config-description.js +++ b/test/config-description.js @@ -23,7 +23,7 @@ describe('config: description', function() { ].join(' '), 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'); expect(eraseTime(stdout)).toEqual(expected); @@ -39,7 +39,7 @@ describe('config: description', function() { ].join(' '), 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'); expect(sliceLines(stdout, 1)).toEqual(expected); @@ -55,7 +55,7 @@ describe('config: description', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); var expected = fs.readFileSync(path.join(expectedDir, 'output2.txt'), 'utf-8'); expect(sliceLines(stdout, 1)).toEqual(expected); @@ -73,7 +73,7 @@ describe('config: description', function() { ].join(' '), 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'); expect(eraseTime(stdout)).toEqual(expected); diff --git a/test/config-flags-continue.js b/test/config-flags-continue.js index 1509466c..0a6b42c4 100644 --- a/test/config-flags-continue.js +++ b/test/config-flags-continue.js @@ -19,7 +19,7 @@ describe('config: flags.continue', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); + expect(err).not.toBeNull(); stdout = sliceLines(stdout, 1); expect(stdout).toEqual( 'Starting \'default\'...\n' + @@ -44,7 +44,7 @@ describe('config: flags.continue', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); + expect(err).not.toBeNull(); stdout = sliceLines(stdout, 1); expect(stdout).toEqual( 'Starting \'default\'...\n' + @@ -68,7 +68,7 @@ describe('config: flags.continue', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); + expect(err).not.toBeNull(); stdout = sliceLines(stdout, 1); expect(stdout).toEqual( 'Starting \'default\'...\n' + @@ -94,7 +94,7 @@ describe('config: flags.continue', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); + expect(err).not.toBeNull(); stdout = sliceLines(stdout, 1); expect(stdout).toEqual( 'Starting \'default\'...\n' + diff --git a/test/config-flags-gulpfile.js b/test/config-flags-gulpfile.js index 4a8c9ed3..84c01a35 100644 --- a/test/config-flags-gulpfile.js +++ b/test/config-flags-gulpfile.js @@ -19,7 +19,7 @@ describe('config: flags.gulpfile', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(sliceLines(stdout, 2, 4)).toEqual( 'This gulpfile : ' + path.join(baseDir, 'is/here/mygulpfile.js') + '\n' + @@ -37,7 +37,7 @@ describe('config: flags.gulpfile', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(sliceLines(stdout, 3, 5)).toEqual( 'This gulpfile : ' + path.join(baseDir, 'is/here/mygulpfile.js') + '\n' + @@ -55,7 +55,7 @@ describe('config: flags.gulpfile', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(sliceLines(stdout, 3, 4)).toEqual( 'This gulpfile : ' + path.join(baseDir, 'is/here/mygulpfile.js') @@ -72,7 +72,7 @@ describe('config: flags.gulpfile', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(sliceLines(stdout, 3, 4)).toEqual( 'Another gulpfile : ' + path.join(baseDir, 'cwd/gulpfile.js') @@ -89,7 +89,7 @@ describe('config: flags.gulpfile', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(sliceLines(stdout, 2, 3)).toEqual( 'Gulpfile : ' + path.join(baseDir, 'override-by-cliflag/mygulpfile.js') @@ -108,7 +108,7 @@ describe('config: flags.gulpfile', function() { ].join(' '), 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!'); @@ -125,8 +125,8 @@ describe('config: flags.gulpfile', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); - expect(stderr).toNotEqual(''); + 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 0cf72ebf..9535834a 100644 --- a/test/config-flags-log-level.js +++ b/test/config-flags-log-level.js @@ -23,7 +23,7 @@ describe('config: flag.logLevel', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); + expect(err).not.toBeNull(); expect(stdout).toEqual(''); expect(eraseTime(stderr)).toEqual('No gulpfile found\n'); done(); @@ -38,7 +38,7 @@ describe('config: flag.logLevel', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(sliceLines(stdout, 1, 3)).toMatch( 'Failed to preload external module: mymodule\n' + @@ -55,7 +55,7 @@ describe('config: flag.logLevel', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(sliceLines(stdout, 0, 2)).toMatch( 'Node flags detected: --harmony\n' + @@ -75,7 +75,7 @@ describe('config: flag.logLevel', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); + expect(err).not.toBeNull(); expect(stdout).toEqual(''); expect(eraseTime(stderr)).toEqual('No gulpfile found\n'); done(); @@ -90,7 +90,7 @@ describe('config: flag.logLevel', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(stderr).toEqual(''); done(); @@ -105,7 +105,7 @@ describe('config: flag.logLevel', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(stdout).toEqual(''); done(err); @@ -122,7 +122,7 @@ describe('config: flag.logLevel', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); + expect(err).not.toBeNull(); expect(stdout).toEqual(''); expect(eraseTime(stderr)).toEqual('No gulpfile found\n'); done(); @@ -137,7 +137,7 @@ describe('config: flag.logLevel', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(eraseTime(stdout)).toMatch( 'Failed to preload external module: mymodule\n' + @@ -154,7 +154,7 @@ describe('config: flag.logLevel', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(stdout).toEqual(''); done(err); @@ -171,7 +171,7 @@ describe('config: flag.logLevel', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); + expect(err).not.toBeNull(); expect(stdout).toEqual(''); expect(eraseTime(stderr)).toEqual('No gulpfile found\n'); done(); @@ -186,7 +186,7 @@ describe('config: flag.logLevel', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(eraseTime(stdout)).toMatch( 'Failed to preload external module: mymodule\n' + @@ -203,7 +203,7 @@ describe('config: flag.logLevel', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(sliceLines(stdout, 0, 2)).toMatch( 'Node flags detected: --harmony\n' + @@ -223,7 +223,7 @@ describe('config: flag.logLevel', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stdout).toEqual(''); expect(stderr).toEqual(''); done(err); @@ -239,7 +239,7 @@ describe('config: flag.logLevel', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(sliceLines(stdout, 0, 2)).toMatch( 'Node flags detected: --harmony\n' + diff --git a/test/config-flags-node-flags.js b/test/config-flags-node-flags.js index 0b315115..37ace292 100644 --- a/test/config-flags-node-flags.js +++ b/test/config-flags-node-flags.js @@ -19,7 +19,7 @@ describe('config: nodeFlags', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(sliceLines(stdout, 0, 1)).toEqual('Node flags detected: --lazy'); expect(sliceLines(stdout, 1, 3)).toMatch('Respawned to PID: '); @@ -34,7 +34,7 @@ describe('config: nodeFlags', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(sliceLines(stdout, 0, 1)).toEqual('Node flags detected: --lazy, --trace-deprecation'); expect(sliceLines(stdout, 1, 3)).toMatch('Respawned to PID: '); @@ -50,7 +50,7 @@ describe('config: nodeFlags', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(sliceLines(stdout, 0, 1)).toEqual('Node flags detected: --lazy, --harmony'); expect(sliceLines(stdout, 1, 3)).toMatch('Respawned to PID: '); @@ -65,7 +65,7 @@ describe('config: nodeFlags', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(sliceLines(stdout, 0, 1)).toMatch('Using gulpfile '); expect(sliceLines(stdout, 1)).toEqual( @@ -84,7 +84,7 @@ describe('config: nodeFlags', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(sliceLines(stdout, 0, 1)).toMatch('Using gulpfile '); expect(sliceLines(stdout, 1)).toEqual( diff --git a/test/config-flags-preload.js b/test/config-flags-preload.js index 917551e6..43e3ead8 100644 --- a/test/config-flags-preload.js +++ b/test/config-flags-preload.js @@ -19,7 +19,7 @@ describe('config: flags.preload', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + 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'); @@ -38,7 +38,7 @@ describe('config: flags.preload', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + 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'); @@ -55,7 +55,7 @@ describe('config: flags.preload', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + 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'); @@ -75,7 +75,7 @@ describe('config: flags.preload', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + 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'); @@ -92,7 +92,7 @@ describe('config: flags.preload', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + 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); diff --git a/test/config-flags-series.js b/test/config-flags-series.js index 2e6c1700..e8bcacf1 100644 --- a/test/config-flags-series.js +++ b/test/config-flags-series.js @@ -20,7 +20,7 @@ describe('config: flags.series', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(sliceLines(stdout, 1)).toEqual( 'Starting \'task1\'...\n' + @@ -41,7 +41,7 @@ describe('config: flags.series', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(sliceLines(stdout, 1)).toEqual( 'Starting \'task1\'...\n' + @@ -62,7 +62,7 @@ describe('config: flags.series', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(sliceLines(stdout, 1)).toEqual( 'Starting \'task1\'...\n' + @@ -83,7 +83,7 @@ describe('config: flags.series', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(sliceLines(stdout, 1)).toEqual( 'Starting \'task1\'...\n' + diff --git a/test/config-flags-silent.js b/test/config-flags-silent.js index 29875a7a..ca911345 100644 --- a/test/config-flags-silent.js +++ b/test/config-flags-silent.js @@ -19,7 +19,7 @@ describe('config: flags.silent', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(stdout).toEqual(''); done(err); @@ -33,7 +33,7 @@ describe('config: flags.silent', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(sliceLines(stdout, 1)).toEqual( 'Starting \'default\'...\n' + @@ -52,7 +52,7 @@ describe('config: flags.silent', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(stdout).toEqual(''); done(err); @@ -67,7 +67,7 @@ describe('config: flags.silent', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(sliceLines(stdout, 1)).toEqual( 'Starting \'default\'...\n' + diff --git a/test/esm.js b/test/esm.js index 93b63e13..1828523c 100644 --- a/test/esm.js +++ b/test/esm.js @@ -35,7 +35,7 @@ describe('ESM', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toMatch(/^(.*ExperimentalWarning: The ESM module loader is experimental\.\n)?$/); var filepath = path.join(expectedDir, 'esm.txt'); var expected = fs.readFileSync(filepath, 'utf-8'); diff --git a/test/execution-errors.js b/test/execution-errors.js index 8fd9ca60..6f13df8a 100644 --- a/test/execution-errors.js +++ b/test/execution-errors.js @@ -24,7 +24,7 @@ describe('execution error', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); + expect(err).not.toBeNull(); expect(err.code).toEqual(1); expect(eraseTime(stdout)).toMatch('Using gulpfile '); expect(eraseTime(stderr)).toEqual( @@ -41,7 +41,7 @@ describe('execution error', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); + expect(err).not.toBeNull(); expect(err.code).toEqual(1); expect(eraseTime(stdout)).toEqual(''); expect(eraseTime(stderr)).toEqual('Unsupported gulp version 1.2.3\n'); @@ -58,7 +58,7 @@ describe('execution error', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); + 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'); @@ -77,7 +77,7 @@ describe('execution error', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); + expect(err).not.toBeNull(); expect(err.code).toEqual(1); expect(sliceLines(stdout)).toEqual( 'Using gulpfile ' + tildify(path.join(dir, gulpfileName)) + '\n' + diff --git a/test/exports-as-tasks.js b/test/exports-as-tasks.js index 9559afb3..0f88b600 100644 --- a/test/exports-as-tasks.js +++ b/test/exports-as-tasks.js @@ -26,7 +26,7 @@ describe('exports as tasks', function() { ].join(' '), 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'); diff --git a/test/flags-continue.js b/test/flags-continue.js index b64385cb..3627d6b9 100644 --- a/test/flags-continue.js +++ b/test/flags-continue.js @@ -22,7 +22,7 @@ describe('flag: --continue', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); + expect(err).not.toBeNull(); expect(sliceLines(stdout, 2)).toEqual( 'Starting \'test4\'...\n' + 'Starting \'errorFunction\'...\n' + @@ -47,8 +47,8 @@ describe('flag: --continue', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); - expect(stdout).toNotMatch('Starting \'anon\''); + expect(err).not.toBeNull(); + expect(stdout).not.toMatch('Starting \'anon\''); stdout = sliceLines(stdout, 2); expect(stdout).toEqual( 'Starting \'test4\'...\n' + diff --git a/test/flags-gulpfile.js b/test/flags-gulpfile.js index 41eae131..f4979bb9 100644 --- a/test/flags-gulpfile.js +++ b/test/flags-gulpfile.js @@ -22,7 +22,7 @@ describe('flag: --gulpfile', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); var chgWorkdirLog = sliceLines(stdout, 0, 1); @@ -53,7 +53,7 @@ describe('flag: --gulpfile', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); var chgWorkdirLog = sliceLines(stdout, 0, 1); diff --git a/test/flags-help.js b/test/flags-help.js index 68317be2..7ebd93bf 100644 --- a/test/flags-help.js +++ b/test/flags-help.js @@ -23,7 +23,7 @@ describe('flag: --help', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(stdout).toEqual(outputText); done(err); @@ -39,7 +39,7 @@ describe('flag: --help', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(stdout).toEqual(outputText); done(err); @@ -55,7 +55,7 @@ describe('flag: --help', function() { ].join(' '), 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-preload.js b/test/flags-preload.js index 116a0490..9e7d9e7f 100644 --- a/test/flags-preload.js +++ b/test/flags-preload.js @@ -23,7 +23,7 @@ describe('flag: --preload', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + 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'); @@ -64,7 +64,7 @@ describe('flag: --preload', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + 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'); @@ -85,15 +85,15 @@ describe('flag: --preload', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + 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\''); - expect(stdout).toNotMatch('inside test module'); - expect(stdout).toNotMatch('Preloaded external module: ../null-module.js'); + expect(stdout).not.toMatch('inside test module'); + expect(stdout).not.toMatch('Preloaded external module: ../null-module.js'); var chgWorkdirLog = sliceLines(stdout, 3, 4); var workdir = 'test/fixtures/gulpfiles'.replace(/\//g, path.sep); @@ -130,11 +130,11 @@ describe('flag: --preload', function() { function cb(err, stdout, stderr) { stdout = eraseLapse(eraseTime(stdout)); - expect(err).toEqual(null); + 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).toNotMatch('inside error module'); + expect(stdout).not.toMatch('inside error module'); var chgWorkdirLog = sliceLines(stdout, 3, 4); var workdir = 'test/fixtures/gulpfiles'.replace(/\//g, path.sep); diff --git a/test/flags-series.js b/test/flags-series.js index a9b75d3c..bf22f6b4 100644 --- a/test/flags-series.js +++ b/test/flags-series.js @@ -22,7 +22,7 @@ describe('flag: --series', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(sliceLines(stdout, 2)).toEqual( 'Starting \'test5\'...\n' + @@ -44,9 +44,9 @@ describe('flag: --series', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); - expect(stdout).toNotMatch('Starting \'anon\''); + expect(stdout).not.toMatch('Starting \'anon\''); expect(sliceLines(stdout, 2)).toEqual( 'Starting \'test5\'...\n' + 'Starting \'test6\'...\n' + diff --git a/test/flags-silent.js b/test/flags-silent.js index 708a3804..d12088ac 100644 --- a/test/flags-silent.js +++ b/test/flags-silent.js @@ -20,7 +20,7 @@ describe('flag: --silent', function() { ].join(' '), 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 cf6a09da..295f4bfc 100644 --- a/test/flags-tasks-json.js +++ b/test/flags-tasks-json.js @@ -23,7 +23,7 @@ describe('flag: --tasks-json', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(JSON.parse(stdout)).toEqual(expected); done(err); @@ -43,7 +43,7 @@ describe('flag: --tasks-json', function() { ].join(' '), 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 '); @@ -65,7 +65,7 @@ describe('flag: --tasks-json', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); stdout = stdout.split('\n').slice(1).join('\n'); expect(stdout).toEqual(''); @@ -89,7 +89,7 @@ describe('flag: --tasks-json', function() { ].join(' '), 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 75ebdede..73e8e28a 100644 --- a/test/flags-tasks-simple.js +++ b/test/flags-tasks-simple.js @@ -23,7 +23,7 @@ describe('flag: --tasks-simple', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(stdout).toEqual(outputText); done(err); @@ -42,7 +42,7 @@ describe('flag: --tasks-simple', function() { ].join(' '), 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 ec432920..1e10641a 100644 --- a/test/flags-tasks.js +++ b/test/flags-tasks.js @@ -22,7 +22,7 @@ describe('flag: --tasks', function() { ].join(' '), 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'); @@ -41,7 +41,7 @@ describe('flag: --tasks', function() { ].join(' '), 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'); @@ -60,7 +60,7 @@ describe('flag: --tasks', function() { ].join(' '), 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'); @@ -77,7 +77,7 @@ describe('flag: --tasks', function() { ].join(' '), 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'); @@ -95,7 +95,7 @@ describe('flag: --tasks', function() { ].join(' '), 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'); @@ -113,7 +113,7 @@ describe('flag: --tasks', function() { ].join(' '), 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'); @@ -131,7 +131,7 @@ describe('flag: --tasks', function() { ].join(' '), 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'); @@ -149,7 +149,7 @@ describe('flag: --tasks', function() { ].join(' '), 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'); diff --git a/test/flags-v8flags.js b/test/flags-v8flags.js index 977387f6..6a49afa1 100644 --- a/test/flags-v8flags.js +++ b/test/flags-v8flags.js @@ -20,7 +20,7 @@ describe('flags: v8flags', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(sliceLines(stdout, 0, 1)).toEqual('Node flags detected: --lazy'); expect(sliceLines(stdout, 1, 3)).toMatch('Respawned to PID: '); @@ -36,7 +36,7 @@ describe('flags: v8flags', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(sliceLines(stdout, 0, 1)).toEqual('Node flags detected: --harmony, --lazy'); expect(sliceLines(stdout, 1, 3)).toMatch('Respawned to PID: '); diff --git a/test/flags-verify.js b/test/flags-verify.js index 78a514c2..061f78c2 100644 --- a/test/flags-verify.js +++ b/test/flags-verify.js @@ -21,7 +21,7 @@ describe('flag: --verify', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); + expect(err).not.toBeNull(); expect(stderr).toEqual(''); expect(eraseTime(stdout)).toEqual( 'Verifying plugins in ' + path.resolve('./test/fixtures/verify/invalid-package.json') + '\n' + @@ -41,7 +41,7 @@ describe('flag: --verify', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(eraseTime(stdout)).toEqual( 'Verifying plugins in ' + path.resolve('./test/fixtures/verify/valid-package.json') + '\n' + @@ -60,7 +60,7 @@ describe('flag: --verify', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toNotEqual(null); + expect(err).not.toBeNull(); expect(stderr).toEqual(''); expect(eraseTime(stdout)).toEqual( 'Verifying plugins in ' + path.resolve('./test/fixtures/verify/package.json') + '\n' + diff --git a/test/flags-version.js b/test/flags-version.js index a9e26626..e47612aa 100644 --- a/test/flags-version.js +++ b/test/flags-version.js @@ -23,7 +23,7 @@ describe('flag: --version', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(stdout).toEqual( 'CLI version: ' + cliVersion + '\n' + @@ -42,7 +42,7 @@ describe('flag: --version', function() { ].join(' '), cb); function cb(err, stdout, stderr) { - expect(err).toEqual(null); + expect(err).toBeNull(); expect(stderr).toEqual(''); expect(stdout).toEqual( 'CLI version: ' + cliVersion + '\n' + @@ -61,7 +61,7 @@ describe('flag: --version', function() { ].join(' '), 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/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/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..c00049c4 100644 --- a/test/logging.js +++ b/test/logging.js @@ -9,7 +9,7 @@ describe('logging', function() { child.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'); @@ -23,7 +23,7 @@ describe('logging', function() { child.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'); @@ -36,7 +36,7 @@ describe('logging', function() { child.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'); @@ -49,7 +49,7 @@ describe('logging', function() { child.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'); @@ -61,7 +61,7 @@ describe('logging', function() { child.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/sync-task.js b/test/sync-task.js index 2b536750..5451567d 100644 --- a/test/sync-task.js +++ b/test/sync-task.js @@ -18,7 +18,7 @@ describe('sync-task', function() { ].join(' '), cb); function cb(err) { - expect(err).toNotEqual(null); + expect(err).not.toBeNull(); expect(err.code).toEqual(1); done(); } @@ -48,7 +48,9 @@ describe('sync-task', function() { ].join(' '), cb); function cb(err, stdout) { - expect(stdout).toExclude('The following tasks did not complete:'); + expect(stdout).toEqual(expect.not.stringContaining( + 'The following tasks did not complete:' + )); done(); } }); @@ -61,7 +63,9 @@ describe('sync-task', function() { ].join(' '), cb); function cb(err, stdout) { - expect(stdout).toExclude('The following tasks did not complete:'); + expect(stdout).toEqual(expect.not.stringContaining( + 'The following tasks did not complete:' + )); done(); } }); @@ -74,7 +78,9 @@ describe('sync-task', function() { ].join(' '), cb); function cb(err, stdout) { - expect(stdout).toInclude('The following tasks did not complete: broken, notCompleting1\n'); + expect(stdout).toEqual(expect.stringContaining( + 'The following tasks did not complete: broken, notCompleting1\n' + )); done(); } }); From 5e80a3ff1da06bbfecd5402736c9dd72528166f6 Mon Sep 17 00:00:00 2001 From: sttk Date: Sun, 10 Sep 2023 12:16:53 +0900 Subject: [PATCH 12/35] chore: upgrade marked-man to 0.7.0 --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 8562f286..ab6b69a2 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,8 @@ "eslint-config-gulp": "^5.0.1", "expect": "^27.5.1", "gulp": "^4.0.2", - "marked-man": "^0.2.1", + "marked-man": "^0.7.0", + "marked": "^0.7.0", "mocha": "^8.4.0", "nyc": "^15.1.0", "rimraf": "^3.0.2", From 8afc851263e6f0415362627c41256dbc486625f5 Mon Sep 17 00:00:00 2001 From: sttk Date: Sun, 10 Sep 2023 12:34:33 +0900 Subject: [PATCH 13/35] fix: modify Liftoff.configFiles and change normalize-config to merge-configs --- index.js | 35 ++++---- lib/shared/config/merge-configs.js | 28 ++++++ lib/shared/config/normalize-config.js | 17 ---- test/lib/merge-configs.js | 119 ++++++++++++++++++++++++++ test/lib/normalize-config.js | 52 ----------- 5 files changed, 166 insertions(+), 85 deletions(-) create mode 100644 lib/shared/config/merge-configs.js delete mode 100644 lib/shared/config/normalize-config.js create mode 100644 test/lib/merge-configs.js delete mode 100644 test/lib/normalize-config.js diff --git a/index.js b/index.js index ae624d19..1c8c7ca8 100644 --- a/index.js +++ b/index.js @@ -19,7 +19,7 @@ var cliVersion = require('./package.json').version; var getBlacklist = require('./lib/shared/get-blacklist'); var toConsole = require('./lib/shared/log/to-console'); -var normalizeConfig = require('./lib/shared/config/normalize-config'); +var mergeProjectAndUserHomeConfigs = require('./lib/shared/config/merge-configs'); var mergeConfigToCliFlags = require('./lib/shared/config/cli-flags'); var mergeConfigToEnvFlags = require('./lib/shared/config/env-flags'); @@ -41,13 +41,17 @@ var cli = new Liftoff({ extensions: interpret.jsVariants, v8flags: v8flags, configFiles: { - '.gulp': [ + project: [ { + name: '.gulp', path: '.', extensions: interpret.extensions, findUp: true, }, + ], + userHome: [ { + name: '.gulp', path: '~', extensions: interpret.extensions, }, @@ -122,26 +126,25 @@ function run() { configPath: opts.gulpfile, preload: opts.preload, completion: opts.completion, - }, function(env) { - var key = '.gulp'; - var cfgPath = env.configFiles[key]; - var cfg = normalizeConfig(env.config[key], cfgPath); - env.config[key] = cfg; + }, onPrepare); +} + +module.exports = run; - opts = mergeConfigToCliFlags(opts, cfg); - env = mergeConfigToEnvFlags(env, cfg, opts); +function onPrepare(env) { + var cfg = mergeProjectAndUserHomeConfigs(env); + opts = mergeConfigToCliFlags(opts, cfg); + env = mergeConfigToEnvFlags(env, cfg, opts); + env.config['.gulp'] = cfg; - // Set up event listeners for logging again after configuring. - toConsole(log, opts); + // Set up event listeners for logging again after configuring. + toConsole(log, opts); - cli.execute(env, env.nodeFlags, handleArguments); - }); + cli.execute(env, env.nodeFlags, onExecute); } -module.exports = run; - // The actual logic -function handleArguments(env) { +function onExecute(env) { // This translates the --continue flag in gulp // To the settle env variable for undertaker diff --git a/lib/shared/config/merge-configs.js b/lib/shared/config/merge-configs.js new file mode 100644 index 00000000..deca60ff --- /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.project) { + copyConfig(env.config.project, cfg, env.configFiles.project); + } + if (env.configFiles.userHome) { + copyConfig(env.config.userHome, cfg, env.configFiles.userHome); + } + 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/config/normalize-config.js b/lib/shared/config/normalize-config.js deleted file mode 100644 index caece43c..00000000 --- a/lib/shared/config/normalize-config.js +++ /dev/null @@ -1,17 +0,0 @@ -'use strict'; - -var copyProps = require('copy-props'); -var path = require('path'); - -function normalizeConfig(config, filePath) { - return copyProps(config, {}, convert); - - function convert(loadedInfo) { - if (loadedInfo.keyChain === 'flags.gulpfile') { - return path.resolve(path.dirname(filePath), loadedInfo.value); - } - return loadedInfo.value; - } -} - -module.exports = normalizeConfig; diff --git a/test/lib/merge-configs.js b/test/lib/merge-configs.js new file mode 100644 index 00000000..d8721da2 --- /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 user home', + 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/normalize-config.js b/test/lib/normalize-config.js deleted file mode 100644 index 95e4a931..00000000 --- a/test/lib/normalize-config.js +++ /dev/null @@ -1,52 +0,0 @@ -'use strict'; - -var expect = require('expect'); -var path = require('path'); -var normalizeConfig = require('../../lib/shared/config/normalize-config'); - -var fixturesDir = path.join(__dirname, '../fixtures/config'); - -describe('lib: config/normalize-config', function() { - - it('Should normalize config', function(done) { - var config = { - '.gulp': { - description: 'description by .gulp.js in directory qux', - }, - }; - var configFiles = { - '.gulp': path.join(fixturesDir, 'qux/.gulp.js'), - }; - - var key = '.gulp'; - var cfg = normalizeConfig(config[key], configFiles[key]); - - expect(cfg).toEqual({ - description: 'description by .gulp.js in directory qux', - }); - done(); - }); - - it('Should convert a value of `flags.gulpfile` to absolute path', function(done) { - var config = { - '.gulp': { - flags: { gulpfile: './is/here/mygulpfile.js' }, - }, - }; - var configFiles = { - '.gulp': path.join(fixturesDir, 'flags/gulpfile/.gulp.json'), - }; - - var key = '.gulp'; - var cfg = normalizeConfig(config[key], configFiles[key]); - - expect(cfg).toEqual({ - flags: { - gulpfile: path.join(fixturesDir, - 'flags/gulpfile/is/here/mygulpfile.js'), - }, - }); - done(); - }); - -}); From f3fa77c0bbe42f6cfc81ab719b5e0a62dd0175ec Mon Sep 17 00:00:00 2001 From: sttk Date: Sun, 10 Sep 2023 12:36:33 +0900 Subject: [PATCH 14/35] Update LICENSE --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index aae7195c..a11cf32d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015, 2017-2020, 2022 Blaine Bublitz and Eric Schoffstall . +Copyright (c) 2015, 2017-2020, 2022 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 From fa088ebf32dd8795cf6cd47f8f89a5ce893d9b1b Mon Sep 17 00:00:00 2001 From: sttk Date: Sun, 10 Sep 2023 12:37:32 +0900 Subject: [PATCH 15/35] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 310949fe..bc3e1faf 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Command Line Utility for Gulp ## Install ```bash -npm install gulp-cli +npm install --global gulp-cli ``` ## Usage From 225beb035a8d1de828af3c81c097cb1f6c09c2e5 Mon Sep 17 00:00:00 2001 From: sttk Date: Sun, 10 Sep 2023 12:42:08 +0900 Subject: [PATCH 16/35] chore: modify ci badge url in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bc3e1faf..71f4d7a7 100644 --- a/README.md +++ b/README.md @@ -236,7 +236,7 @@ MIT [npm-image]: https://img.shields.io/npm/v/gulp-cli.svg?style=flat-square [ci-url]: https://github.com/gulpjs/gulp-cli/actions?query=workflow:dev -[ci-image]: https://img.shields.io/github/workflow/status/gulpjs/gulp-cli/dev?style=flat-square +[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]: https://img.shields.io/coveralls/gulpjs/gulp-cli.svg?style=flat-square From 002d0faef9b4b8ea9c7dd9dde69810b6fef19a83 Mon Sep 17 00:00:00 2001 From: Takayuki Sato Date: Sat, 7 Oct 2023 10:37:49 +0900 Subject: [PATCH 17/35] Update LICENSE Co-authored-by: Blaine Bublitz --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index a11cf32d..6443cad0 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015, 2017-2020, 2022 Blaine Bublitz and Eric Schoffstall +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 From 18d348bb0b31c6ba7f5fb6eceee0d43119afc441 Mon Sep 17 00:00:00 2001 From: Takayuki Sato Date: Sat, 7 Oct 2023 14:18:40 +0900 Subject: [PATCH 18/35] Update package.json Co-authored-by: Blaine Bublitz --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ab6b69a2..747aa9f3 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ ], "scripts": { "lint": "eslint .", - "prepare": "marked-man --name gulp docs/CLI.md > gulp.1", + "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 mocha --async-only --timeout 5000 test/lib test" From 95f93c239f0e6074bcb1fd155a38de6e4d97feae Mon Sep 17 00:00:00 2001 From: Takayuki Sato Date: Sat, 7 Oct 2023 18:30:35 +0900 Subject: [PATCH 19/35] Update test/config-flags-preload.js Co-authored-by: Blaine Bublitz --- test/config-flags-preload.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/config-flags-preload.js b/test/config-flags-preload.js index 43e3ead8..836e5468 100644 --- a/test/config-flags-preload.js +++ b/test/config-flags-preload.js @@ -47,7 +47,7 @@ describe('config: flags.preload', function() { } }); - it('Combines --preload flag with .gulp.* file flags.require', function(done) { + it('Combines --preload flag with .gulp.* file flags.preload', function(done) { exec([ 'cd ' + path.join(baseDir, 'join-flags') + cmdSep, gulpCmd, From f46d7cda5db6527f1d190bfb959bc142f048730c Mon Sep 17 00:00:00 2001 From: sttk Date: Sat, 7 Oct 2023 17:27:26 +0900 Subject: [PATCH 20/35] fix: remove dependency on concat-stream and change getting blacklist --- index.js | 2 +- lib/shared/blacklist/get-remote-json.js | 39 ++++++++++++++++ lib/shared/blacklist/index.js | 11 +++++ lib/shared/get-blacklist.js | 62 ------------------------- package.json | 1 - test/lib/get-remote-json.js | 34 ++++++++++++++ 6 files changed, 85 insertions(+), 64 deletions(-) create mode 100644 lib/shared/blacklist/get-remote-json.js create mode 100644 lib/shared/blacklist/index.js delete mode 100644 lib/shared/get-blacklist.js create mode 100644 test/lib/get-remote-json.js diff --git a/index.js b/index.js index 1c8c7ca8..9c7e7b81 100644 --- a/index.js +++ b/index.js @@ -16,7 +16,7 @@ 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 mergeProjectAndUserHomeConfigs = require('./lib/shared/config/merge-configs'); 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/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/package.json b/package.json index 747aa9f3..4ecd2191 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,6 @@ "dependencies": { "archy": "^1.0.0", "chalk": "^4.1.2", - "concat-stream": "^2.0.0", "copy-props": "^4.0.0", "fancy-log": "^2.0.0", "gulplog": "^2.0.1", 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(); + }); + }); +}); From 1f935142460f494de6395663c2bbb49ec7cd8973 Mon Sep 17 00:00:00 2001 From: sttk Date: Sat, 7 Oct 2023 14:16:13 +0900 Subject: [PATCH 21/35] fix: modify that project config overrides userHome config --- lib/shared/config/merge-configs.js | 6 +++--- test/lib/merge-configs.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/shared/config/merge-configs.js b/lib/shared/config/merge-configs.js index deca60ff..8202f182 100644 --- a/lib/shared/config/merge-configs.js +++ b/lib/shared/config/merge-configs.js @@ -5,12 +5,12 @@ var path = require('path'); function mergeConfigs(env) { var cfg = {}; - if (env.configFiles.project) { - copyConfig(env.config.project, cfg, env.configFiles.project); - } 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; } diff --git a/test/lib/merge-configs.js b/test/lib/merge-configs.js index d8721da2..6d0a4bea 100644 --- a/test/lib/merge-configs.js +++ b/test/lib/merge-configs.js @@ -83,7 +83,7 @@ describe('lib: config/merge-configs', function() { var cfg = mergeConfigs(env); expect(cfg).toEqual({ - description: 'description by .gulp.js in directory user home', + description: 'description by .gulp.js in directory project', flags: { series: true, silent: true, From bb25f489dd7c3cc7b8d85e49c168dd1bc97327dc Mon Sep 17 00:00:00 2001 From: sttk Date: Sat, 7 Oct 2023 18:38:07 +0900 Subject: [PATCH 22/35] fix: modify mistakes of descriptions in test fixtures and expected --- test/expected/config/output2.txt | 2 +- test/fixtures/config/foo/bar/quux/.gulp.babel.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/expected/config/output2.txt b/test/expected/config/output2.txt index 2d9cbf29..a0d45083 100644 --- a/test/expected/config/output2.txt +++ b/test/expected/config/output2.txt @@ -1,2 +1,2 @@ -DESCRIPTION BY .gulp.babel.js in directory foo/bar/baz +DESCRIPTION BY .gulp.babel.js in directory foo/bar/quux └── default diff --git a/test/fixtures/config/foo/bar/quux/.gulp.babel.js b/test/fixtures/config/foo/bar/quux/.gulp.babel.js index 2c0f43e5..92986942 100644 --- a/test/fixtures/config/foo/bar/quux/.gulp.babel.js +++ b/test/fixtures/config/foo/bar/quux/.gulp.babel.js @@ -1 +1 @@ -exports.description = 'DESCRIPTION BY .gulp.babel.js in directory foo/bar/baz' +exports.description = 'DESCRIPTION BY .gulp.babel.js in directory foo/bar/quux' From 4ce1c2a3a635294aeca325b92214a5ba87a8dc13 Mon Sep 17 00:00:00 2001 From: sttk Date: Sat, 7 Oct 2023 19:12:18 +0900 Subject: [PATCH 23/35] fix: remove `if` conditions for mjs-stub in preload:before and preload:success --- index.js | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index 9c7e7b81..997ea1c2 100644 --- a/index.js +++ b/index.js @@ -62,23 +62,11 @@ var cli = new Liftoff({ var opts = parser.argv; cli.on('preload:before', 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('Preloading external module:', chalk.magenta(name)); - } + log.info('Preloading external module:', chalk.magenta(name)); }); cli.on('preload: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('Preloaded external module:', chalk.magenta(name)); - } + log.info('Preloaded external module:', chalk.magenta(name)); }); cli.on('preload:failure', function(name, error) { From 7414f329920488053b0274ab223758c82a4276c9 Mon Sep 17 00:00:00 2001 From: sttk Date: Sun, 8 Oct 2023 15:28:40 +0900 Subject: [PATCH 24/35] fix: change gulp execution by using helper function --- test/completion.js | 17 ++---- test/config-description.js | 29 +++------- test/config-flags-compact-tasks.js | 29 ++-------- test/config-flags-continue.js | 25 ++------- test/config-flags-gulpfile.js | 45 +++------------ test/config-flags-log-level.js | 89 +++++------------------------- test/config-flags-node-flags.js | 29 ++-------- test/config-flags-preload.js | 32 ++--------- test/config-flags-series.js | 27 ++------- test/config-flags-silent.js | 25 ++------- test/config-flags-sort-tasks.js | 27 ++------- test/config-flags-tasks-depth.js | 16 +----- test/esm.js | 9 +-- test/execution-errors.js | 35 ++++-------- test/exports-as-tasks.js | 11 ++-- test/flags-continue.js | 18 ++---- test/flags-gulpfile.js | 15 +---- test/flags-help.js | 27 ++++----- test/flags-preload.js | 33 ++++------- test/flags-series.js | 17 ++---- test/flags-silent.js | 11 ++-- test/flags-tasks-json.js | 33 ++++------- test/flags-tasks-simple.js | 17 ++---- test/flags-tasks.js | 88 ++++++++++++++--------------- test/flags-v8flags.js | 15 +---- test/flags-verify.js | 29 ++++------ test/flags-version.js | 28 ++++------ test/logging.js | 12 ++-- test/sync-task.js | 41 +++++--------- test/tool/cmd-sep.js | 5 -- test/tool/gulp-cmd.js | 32 +++++++++++ 31 files changed, 266 insertions(+), 600 deletions(-) delete mode 100644 test/tool/cmd-sep.js create mode 100644 test/tool/gulp-cmd.js diff --git a/test/completion.js b/test/completion.js index 2b670d9c..705387d8 100644 --- a/test/completion.js +++ b/test/completion.js @@ -5,7 +5,7 @@ var exec = require('child_process').exec; var path = require('path'); var fs = require('fs'); -var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); +var gulp = require('./tool/gulp-cmd').gulp; describe('flag: --completion', function() { @@ -14,10 +14,7 @@ describe('flag: --completion', function() { var file = path.resolve(__dirname, '../completion', type); var expected = fs.readFileSync(file, 'utf8') + '\n'; - exec([ - gulpCmd, - '--completion=' + type, - ].join(' '), cb); + exec(gulp('--completion=' + type), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -31,10 +28,7 @@ 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'; - exec([ - gulpCmd, - '--completion=unknown', - ].join(' '), cb); + exec(gulp('--completion=unknown'), cb); function cb(err, stdout, stderr) { expect(err).not.toBeNull(); @@ -45,10 +39,7 @@ describe('flag: --completion', function() { }); it('shows error message for missing completion type', function(done) { - exec([ - gulpCmd, - '--completion', - ].join(' '), cb); + exec(gulp('--completion'), cb); function cb(err, stdout, stderr) { expect(err).not.toBeNull(); diff --git a/test/config-description.js b/test/config-description.js index a4cd534a..8fc80ecc 100644 --- a/test/config-description.js +++ b/test/config-description.js @@ -7,20 +7,15 @@ var fs = require('fs'); var sliceLines = require('./tool/slice-lines'); var eraseTime = require('./tool/erase-time'); -var cmdSep = require('./tool/cmd-sep'); +var cd = require('./tool/gulp-cmd').cd; -var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); 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) { - exec([ - 'cd ' + path.join(baseDir, 'foo/bar') + cmdSep, - gulpCmd, - '--tasks', - ].join(' '), cb); + exec(cd(baseDir, 'foo/bar').gulp('--tasks'), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -32,11 +27,7 @@ describe('config: description', function() { }); it('Should configure with a .gulp.* file in cwd found up', function(done) { - exec([ - 'cd ' + path.join(baseDir, 'foo/bar/baz') + cmdSep, - gulpCmd, - '--tasks', - ].join(' '), cb); + exec(cd(baseDir, 'foo/bar/baz').gulp('--tasks'), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -48,11 +39,7 @@ describe('config: description', function() { }); it('Should configure with a .gulp.* file in cwd even if it is not a project root', function(done) { - exec([ - 'cd ' + path.join(baseDir, 'foo/bar/quux') + cmdSep, - gulpCmd, - '--tasks', - ].join(' '), cb); + exec(cd(baseDir, 'foo/bar/quux').gulp('--tasks'), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -64,13 +51,11 @@ describe('config: description', function() { }); it('Should configure with a .gulp.* file in cwd by --cwd', function(done) { - exec([ - 'cd ' + path.join(baseDir, 'qux') + cmdSep, - gulpCmd, + exec(cd(baseDir, 'qux').gulp( '--tasks', '--gulpfile ../foo/bar/gulpfile.js', - '--cwd .', - ].join(' '), cb); + '--cwd .' + ), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); diff --git a/test/config-flags-compact-tasks.js b/test/config-flags-compact-tasks.js index 0940a21c..bfdbb023 100644 --- a/test/config-flags-compact-tasks.js +++ b/test/config-flags-compact-tasks.js @@ -6,20 +6,15 @@ var path = require('path'); var fs = require('fs'); var sliceLines = require('./tool/slice-lines'); -var cmdSep = require('./tool/cmd-sep'); +var cd = require('./tool/gulp-cmd').cd; -var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); var baseDir = path.join(__dirname, 'fixtures/config/flags/compactTasks'); var expectedDir = path.join(__dirname, 'expected'); describe('config: flags.compactTasks', function() { it('Should compact task lists when `flags.compactTasks` is true in .gulp.*', function(done) { - exec([ - 'cd ' + path.join(baseDir, 't') + cmdSep, - gulpCmd, - '--tasks', - ].join(' '), cb); + exec(cd(baseDir, 't').gulp('--tasks'), cb); function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-compact.txt'); @@ -33,11 +28,7 @@ describe('config: flags.compactTasks', function() { }); it('Should not compact task lists when `flags.compactTasks` is false in .gulp.*', function(done) { - exec([ - 'cd ' + path.join(baseDir, 'f') + cmdSep, - gulpCmd, - '--tasks', - ].join(' '), cb); + exec(cd(baseDir, 'f').gulp('--tasks'), cb); function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-unsorted.txt'); @@ -51,12 +42,7 @@ describe('config: flags.compactTasks', function() { }); it('Should overridden by cli flag: --compact-tasks', function(done) { - exec([ - 'cd ' + path.join(baseDir, 'f') + cmdSep, - gulpCmd, - '--tasks', - '--compact-tasks', - ].join(' '), cb); + exec(cd(baseDir, 'f').gulp('--tasks', '--compact-tasks'), cb); function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-compact.txt'); @@ -70,12 +56,7 @@ describe('config: flags.compactTasks', function() { }); it('Should overridden by cli flag: --no-compact-tasks', function(done) { - exec([ - 'cd ' + path.join(baseDir, 't') + cmdSep, - gulpCmd, - '--tasks', - '--no-compact-tasks', - ].join(' '), cb); + exec(cd(baseDir, 't').gulp('--tasks', '--no-compact-tasks'), cb); function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-unsorted.txt'); diff --git a/test/config-flags-continue.js b/test/config-flags-continue.js index 0a6b42c4..4f607cea 100644 --- a/test/config-flags-continue.js +++ b/test/config-flags-continue.js @@ -5,18 +5,14 @@ var exec = require('child_process').exec; var path = require('path'); var sliceLines = require('./tool/slice-lines'); -var cmdSep = require('./tool/cmd-sep'); +var cd = require('./tool/gulp-cmd').cd; -var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); 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) { - exec([ - 'cd ' + path.join(baseDir, 't') + cmdSep, - gulpCmd, - ].join(' '), cb); + exec(cd(baseDir, 't').gulp(), cb); function cb(err, stdout, stderr) { expect(err).not.toBeNull(); @@ -38,10 +34,7 @@ describe('config: flags.continue', function() { }); it('Should not continue if `flags.continue` is false in .gulp.*', function(done) { - exec([ - 'cd ' + path.join(baseDir, 'f') + cmdSep, - gulpCmd, - ].join(' '), cb); + exec(cd(baseDir, 'f').gulp(), cb); function cb(err, stdout, stderr) { expect(err).not.toBeNull(); @@ -61,11 +54,7 @@ describe('config: flags.continue', function() { }); it('Should overridden by cli flag: --continue', function(done) { - exec([ - 'cd ' + path.join(baseDir, 'f') + cmdSep, - gulpCmd, - '--continue', - ].join(' '), cb); + exec(cd(baseDir, 'f').gulp('--continue'), cb); function cb(err, stdout, stderr) { expect(err).not.toBeNull(); @@ -87,11 +76,7 @@ describe('config: flags.continue', function() { }); it('Should overridden by cli flag: --no-continue', function(done) { - exec([ - 'cd ' + path.join(baseDir, 't') + cmdSep, - gulpCmd, - '--no-continue', - ].join(' '), cb); + exec(cd(baseDir, 't').gulp('--no-continue'), cb); function cb(err, stdout, stderr) { expect(err).not.toBeNull(); diff --git a/test/config-flags-gulpfile.js b/test/config-flags-gulpfile.js index 84c01a35..0dcb09f5 100644 --- a/test/config-flags-gulpfile.js +++ b/test/config-flags-gulpfile.js @@ -5,18 +5,14 @@ var exec = require('child_process').exec; var path = require('path'); var sliceLines = require('./tool/slice-lines'); -var cmdSep = require('./tool/cmd-sep'); +var cd = require('./tool/gulp-cmd').cd; -var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); var baseDir = path.join(__dirname, 'fixtures/config/flags/gulpfile'); describe('config: flags.gulpfile', function() { it('Should configure with a .gulp.* file', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, - ].join(' '), cb); + exec(cd(baseDir).gulp(), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -30,11 +26,7 @@ describe('config: flags.gulpfile', function() { }); it('Should configure with a .gulp.* file in the directory specified by --cwd', function(done) { - exec([ - 'cd ' + path.join(__dirname, 'fixtures/config') + cmdSep, - gulpCmd, - '--cwd ./flags/gulpfile', - ].join(' '), cb); + exec(cd(__dirname, 'fixtures/config').gulp('--cwd ./flags/gulpfile'), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -48,11 +40,7 @@ describe('config: flags.gulpfile', function() { }); it('Should load a ./gulp.* file in a directory specified by --cwd', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, - '--cwd ./cwd', - ].join(' '), cb); + exec(cd(baseDir).gulp('--cwd ./cwd'), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -65,11 +53,7 @@ describe('config: flags.gulpfile', function() { }); it('Should ignore a ./.gulp.* file if another gulpfile is specified by --gulpfile', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, - '--gulpfile ./cwd/gulpfile.js', - ].join(' '), cb); + exec(cd(baseDir).gulp('--gulpfile ./cwd/gulpfile.js'), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -82,11 +66,7 @@ describe('config: flags.gulpfile', function() { }); it('Should overridden by cli flag: --gulpfile', function(done) { - exec([ - 'cd ' + path.join(baseDir, 'override-by-cliflag') + cmdSep, - gulpCmd, - '--gulpfile mygulpfile.js', - ].join(' '), cb); + exec(cd(baseDir, 'override-by-cliflag').gulp('--gulpfile mygulpfile.js'), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -101,11 +81,7 @@ describe('config: flags.gulpfile', function() { it('Should autoload a module for loading a specified gulpfile', function(done) { this.timeout(0); - exec([ - 'cd ' + path.join(baseDir, 'autoload') + cmdSep, - gulpCmd, - 'dist', - ].join(' '), cb); + exec(cd(baseDir, 'autoload').gulp('dist'), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -118,11 +94,7 @@ describe('config: flags.gulpfile', function() { }); it('Should output error logs of autoload if fail to load module for a specified gulpfile', function(done) { - exec([ - 'cd ' + path.join(baseDir, 'autoload-fail') + cmdSep, - gulpCmd, - 'dist', - ].join(' '), cb); + exec(cd(baseDir, 'autoload-fail').gulp('dist'), cb); function cb(err, stdout, stderr) { expect(err).not.toBeNull(); @@ -134,4 +106,3 @@ describe('config: flags.gulpfile', function() { }); }); - diff --git a/test/config-flags-log-level.js b/test/config-flags-log-level.js index 9535834a..42d602c6 100644 --- a/test/config-flags-log-level.js +++ b/test/config-flags-log-level.js @@ -6,9 +6,8 @@ var path = require('path'); var sliceLines = require('./tool/slice-lines'); var eraseTime = require('./tool/erase-time'); -var cmdSep = require('./tool/cmd-sep'); +var cd = require('./tool/gulp-cmd').cd; -var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); var baseDir = path.join(__dirname, 'fixtures/config/flags/logLevel'); describe('config: flag.logLevel', function() { @@ -16,11 +15,7 @@ describe('config: flag.logLevel', function() { describe('log level 3 by default', function() { it('Should output error log', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, - '--gulpfile x', - ].join(' '), cb); + exec(cd(baseDir).gulp('--gulpfile x'), cb); function cb(err, stdout, stderr) { expect(err).not.toBeNull(); @@ -31,11 +26,7 @@ describe('config: flag.logLevel', function() { }); it('Should output warn log', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, - '--preload mymodule', - ].join(' '), cb); + exec(cd(baseDir).gulp('--preload mymodule'), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -48,11 +39,7 @@ describe('config: flag.logLevel', function() { }); it('Should output info log', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, - '--harmony', - ].join(' '), cb); + exec(cd(baseDir).gulp('--harmony'), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -68,11 +55,7 @@ describe('config: flag.logLevel', function() { describe('log level 1 by config `flags.logLevel`', function() { it('Should output error log', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, - '--gulpfile x', - ].join(' '), cb); + exec(cd(baseDir).gulp('--gulpfile x'), cb); function cb(err, stdout, stderr) { expect(err).not.toBeNull(); @@ -83,11 +66,7 @@ describe('config: flag.logLevel', function() { }); it('Should output warn log', function(done) { - exec([ - 'cd ' + path.join(baseDir, 'L') + cmdSep, - gulpCmd, - '--preload mymodule', - ].join(' '), cb); + exec(cd(baseDir, 'L').gulp('--preload mymodule'), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -98,11 +77,7 @@ describe('config: flag.logLevel', function() { }); it('Should output info log', function(done) { - exec([ - 'cd ' + path.join(baseDir, 'L') + cmdSep, - gulpCmd, - '--harmony', - ].join(' '), cb); + exec(cd(baseDir, 'L').gulp('--harmony'), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -115,11 +90,7 @@ describe('config: flag.logLevel', function() { describe('log level 2 by config `flags.logLevel`', function() { it('Should output error log', function(done) { - exec([ - 'cd ' + path.join(baseDir, 'LL') + cmdSep, - gulpCmd, - '--gulpfile x', - ].join(' '), cb); + exec(cd(baseDir, 'LL').gulp('--gulpfile x'), cb); function cb(err, stdout, stderr) { expect(err).not.toBeNull(); @@ -130,11 +101,7 @@ describe('config: flag.logLevel', function() { }); it('Should output warn log', function(done) { - exec([ - 'cd ' + path.join(baseDir, 'LL') + cmdSep, - gulpCmd, - '--preload mymodule', - ].join(' '), cb); + exec(cd(baseDir, 'LL').gulp('--preload mymodule'), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -147,11 +114,7 @@ describe('config: flag.logLevel', function() { }); it('Should output info log', function(done) { - exec([ - 'cd ' + path.join(baseDir, 'LL') + cmdSep, - gulpCmd, - '--harmony', - ].join(' '), cb); + exec(cd(baseDir, 'LL').gulp('--harmony'), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -164,11 +127,7 @@ describe('config: flag.logLevel', function() { describe('log level 3 by config `flags.logLevel`', function() { it('Should output error log', function(done) { - exec([ - 'cd ' + path.join(baseDir, 'LLL') + cmdSep, - gulpCmd, - '--gulpfile x', - ].join(' '), cb); + exec(cd(baseDir, 'LLL').gulp('--gulpfile x'), cb); function cb(err, stdout, stderr) { expect(err).not.toBeNull(); @@ -179,11 +138,7 @@ describe('config: flag.logLevel', function() { }); it('Should output warn log', function(done) { - exec([ - 'cd ' + path.join(baseDir, 'LLL') + cmdSep, - gulpCmd, - '--preload mymodule', - ].join(' '), cb); + exec(cd(baseDir, 'LLL').gulp('--preload mymodule'), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -196,11 +151,7 @@ describe('config: flag.logLevel', function() { }); it('Should output info log', function(done) { - exec([ - 'cd ' + path.join(baseDir, 'LLL') + cmdSep, - gulpCmd, - '--harmony', - ].join(' '), cb); + exec(cd(baseDir, 'LLL').gulp('--harmony'), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -215,12 +166,7 @@ describe('config: flag.logLevel', function() { describe('Overridden by cli flag: -L/-LL/-LLL', function() { it('Should not output info log by -L', function(done) { - exec([ - 'cd ' + path.join(baseDir, 'LLL') + cmdSep, - gulpCmd, - '-L', - '--preload mymodule', - ].join(' '), cb); + exec(cd(baseDir, 'LLL').gulp('-L', '--preload mymodule'), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -231,12 +177,7 @@ describe('config: flag.logLevel', function() { }); it('Should output info log by -LLL', function(done) { - exec([ - 'cd ' + path.join(baseDir, 'L') + cmdSep, - gulpCmd, - '-LLL', - '--harmony', - ].join(' '), cb); + exec(cd(baseDir, 'L').gulp('-LLL', '--harmony'), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); diff --git a/test/config-flags-node-flags.js b/test/config-flags-node-flags.js index 37ace292..291841d5 100644 --- a/test/config-flags-node-flags.js +++ b/test/config-flags-node-flags.js @@ -5,18 +5,14 @@ var exec = require('child_process').exec; var path = require('path'); var sliceLines = require('./tool/slice-lines'); -var cmdSep = require('./tool/cmd-sep'); +var cd = require('./tool/gulp-cmd').cd; -var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); var baseDir = path.join(__dirname, 'fixtures/config/flags/nodeFlags'); describe('config: nodeFlags', function() { it('Should respawn by a node flag: --lazy', function(done) { - exec([ - 'cd ' + path.join(baseDir, 'string') + cmdSep, - gulpCmd, - ].join(' '), cb); + exec(cd(baseDir, 'string').gulp(), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -28,10 +24,7 @@ describe('config: nodeFlags', function() { }); it('Should respawn by a node flag: --lazy --trace-deprecation', function(done) { - exec([ - 'cd ' + path.join(baseDir, 'array') + cmdSep, - gulpCmd, - ].join(' '), cb); + exec(cd(baseDir, 'array').gulp(), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -43,11 +36,7 @@ describe('config: nodeFlags', function() { }); it('Should respawn with flags in config file and command line', function(done) { - exec([ - 'cd ' + path.join(baseDir, 'string') + cmdSep, - gulpCmd, - '--harmony', - ].join(' '), cb); + exec(cd(baseDir, 'string').gulp('--harmony'), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -59,10 +48,7 @@ describe('config: nodeFlags', function() { }); it('Should not respawn when a node flag is specified to undefined', function(done) { - exec([ - 'cd ' + path.join(baseDir, 'undefined') + cmdSep, - gulpCmd, - ].join(' '), cb); + exec(cd(baseDir, 'undefined').gulp(), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -78,10 +64,7 @@ describe('config: nodeFlags', function() { }); it('Should not respawn when a node flag is specified to null', function(done) { - exec([ - 'cd ' + path.join(baseDir, 'null') + cmdSep, - gulpCmd, - ].join(' '), cb); + exec(cd(baseDir, 'null').gulp(), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); diff --git a/test/config-flags-preload.js b/test/config-flags-preload.js index 836e5468..2321cd22 100644 --- a/test/config-flags-preload.js +++ b/test/config-flags-preload.js @@ -5,18 +5,14 @@ var exec = require('child_process').exec; var path = require('path'); var sliceLines = require('./tool/slice-lines'); -var cmdSep = require('./tool/cmd-sep'); +var cd = require('./tool/gulp-cmd').cd; -var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); 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) { - exec([ - 'cd ' + path.join(baseDir, 'array') + cmdSep, - gulpCmd, - ].join(' '), cb); + exec(cd(baseDir, 'array').gulp(), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -32,10 +28,7 @@ describe('config: flags.preload', function() { }); it('Should configure with a string in a .gulp.* file', function(done) { - exec([ - 'cd ' + path.join(baseDir, 'string') + cmdSep, - gulpCmd, - ].join(' '), cb); + exec(cd(baseDir, 'string').gulp(), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -48,11 +41,7 @@ describe('config: flags.preload', function() { }); it('Combines --preload flag with .gulp.* file flags.preload', function(done) { - exec([ - 'cd ' + path.join(baseDir, 'join-flags') + cmdSep, - gulpCmd, - '--preload ./preload_one', - ].join(' '), cb); + exec(cd(baseDir, 'join-flags').gulp('--preload ./preload_one'), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -68,11 +57,7 @@ describe('config: flags.preload', function() { }); it('resolves relative requires against cwd', function(done) { - exec([ - 'cd ' + path.join(__dirname, 'fixtures/config') + cmdSep, - gulpCmd, - '--cwd flags/preload/with-cwd', - ].join(' '), cb); + exec(cd(__dirname, 'fixtures/config').gulp('--cwd flags/preload/with-cwd'), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -85,11 +70,7 @@ describe('config: flags.preload', function() { }); it('works with absolute paths, ignoring cwd', function(done) { - exec([ - 'cd ' + path.join(__dirname, 'fixtures/config') + cmdSep, - gulpCmd, - '--cwd flags/preload/with-absolute', - ].join(' '), cb); + exec(cd(__dirname, 'fixtures/config').gulp('--cwd flags/preload/with-absolute'), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -102,4 +83,3 @@ describe('config: flags.preload', function() { } }); }); - diff --git a/test/config-flags-series.js b/test/config-flags-series.js index e8bcacf1..a16752b9 100644 --- a/test/config-flags-series.js +++ b/test/config-flags-series.js @@ -5,19 +5,14 @@ var exec = require('child_process').exec; var path = require('path'); var sliceLines = require('./tool/slice-lines'); -var cmdSep = require('./tool/cmd-sep'); +var cd = require('./tool/gulp-cmd').cd; -var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); 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) { - exec([ - 'cd ' + path.join(baseDir, 't') + cmdSep, - gulpCmd, - 'task1 task2', - ].join(' '), cb); + exec(cd(baseDir, 't').gulp('task1', 'task2'), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -34,11 +29,7 @@ describe('config: flags.series', function() { }); it('Should run in parallel if `flags.series` is false in .gulp.*', function(done) { - exec([ - 'cd ' + path.join(baseDir, 'f') + cmdSep, - gulpCmd, - 'task1 task2', - ].join(' '), cb); + exec(cd(baseDir, 'f').gulp('task1', 'task2'), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -55,11 +46,7 @@ describe('config: flags.series', function() { }); it('Should overridden by cli flag: --series', function(done) { - exec([ - 'cd ' + path.join(baseDir, 'f') + cmdSep, - gulpCmd, - '--series task1 task2', - ].join(' '), cb); + exec(cd(baseDir, 'f').gulp('--series', 'task1', 'task2'), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -76,11 +63,7 @@ describe('config: flags.series', function() { }); it('Should overridden by cli flag: --no-series', function(done) { - exec([ - 'cd ' + path.join(baseDir, 't') + cmdSep, - gulpCmd, - '--no-series task1 task2', - ].join(' '), cb); + exec(cd(baseDir, 't').gulp('--no-series', 'task1', 'task2'), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); diff --git a/test/config-flags-silent.js b/test/config-flags-silent.js index ca911345..04bf7c1f 100644 --- a/test/config-flags-silent.js +++ b/test/config-flags-silent.js @@ -5,18 +5,14 @@ var exec = require('child_process').exec; var path = require('path'); var sliceLines = require('./tool/slice-lines'); -var cmdSep = require('./tool/cmd-sep'); +var cd = require('./tool/gulp-cmd').cd; -var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); 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) { - exec([ - 'cd ' + path.join(baseDir, 't') + cmdSep, - gulpCmd, - ].join(' '), cb); + exec(cd(baseDir, 't').gulp(), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -27,10 +23,7 @@ describe('config: flags.silent', function() { }); it('Should not be silent if `flags.silent` is false in .gulp.*', function(done) { - exec([ - 'cd ' + path.join(baseDir, 'f') + cmdSep, - gulpCmd, - ].join(' '), cb); + exec(cd(baseDir, 'f').gulp(), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -45,11 +38,7 @@ describe('config: flags.silent', function() { }); it('Should overridden by cli flag: --silent', function(done) { - exec([ - 'cd ' + path.join(baseDir, 'f') + cmdSep, - gulpCmd, - '--silent', - ].join(' '), cb); + exec(cd(baseDir, 'f').gulp('--silent'), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -60,11 +49,7 @@ describe('config: flags.silent', function() { }); it('Should overridden by cli flag: --no-silent', function(done) { - exec([ - 'cd ' + path.join(baseDir, 't') + cmdSep, - gulpCmd, - '--no-silent', - ].join(' '), cb); + exec(cd(baseDir, 't').gulp('--no-silent'), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); diff --git a/test/config-flags-sort-tasks.js b/test/config-flags-sort-tasks.js index 3467a261..4f1ae0ad 100644 --- a/test/config-flags-sort-tasks.js +++ b/test/config-flags-sort-tasks.js @@ -6,20 +6,15 @@ var path = require('path'); var fs = require('fs'); var sliceLines = require('./tool/slice-lines'); -var cmdSep = require('./tool/cmd-sep'); +var cd = require('./tool/gulp-cmd').cd; -var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); var baseDir = path.join(__dirname, 'fixtures/config/flags/sortTasks'); var expectedDir = path.join(__dirname, 'expected'); describe('config: flags.sortTasks', function() { it('Should sort top tasks in task list when `flags.sortTasks` is true in .gulp.*', function(done) { - exec([ - 'cd ' + path.join(baseDir, 't') + cmdSep, - gulpCmd, - '--tasks', - ].join(' '), cb); + exec(cd(baseDir, 't').gulp('--tasks'), cb); function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-sorted.txt'); @@ -31,11 +26,7 @@ describe('config: flags.sortTasks', function() { }); it('Should sort top tasks in task list when `flags.sortTasks` is false in .gulp.*', function(done) { - exec([ - 'cd ' + path.join(baseDir, 'f') + cmdSep, - gulpCmd, - '--tasks', - ].join(' '), cb); + exec(cd(baseDir, 'f').gulp('--tasks'), cb); function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-unsorted.txt'); @@ -47,11 +38,7 @@ describe('config: flags.sortTasks', function() { }); it('Should overridden by cli flag: --sort-tasks', function(done) { - exec([ - 'cd ' + path.join(baseDir, 'f') + cmdSep, - gulpCmd, - '--tasks --sort-tasks', - ].join(' '), cb); + exec(cd(baseDir, 'f').gulp('--tasks', '--sort-tasks'), cb); function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-sorted.txt'); @@ -63,11 +50,7 @@ describe('config: flags.sortTasks', function() { }); it('Should overridden by cli flag: --no-sort-tasks', function(done) { - exec([ - 'cd ' + path.join(baseDir, 't') + cmdSep, - gulpCmd, - '--tasks --no-sort-tasks', - ].join(' '), cb); + exec(cd(baseDir, 't').gulp('--tasks', '--no-sort-tasks'), cb); function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-unsorted.txt'); diff --git a/test/config-flags-tasks-depth.js b/test/config-flags-tasks-depth.js index 7d90c4a3..a7ee31c7 100644 --- a/test/config-flags-tasks-depth.js +++ b/test/config-flags-tasks-depth.js @@ -6,20 +6,15 @@ var path = require('path'); var fs = require('fs'); var sliceLines = require('./tool/slice-lines'); -var cmdSep = require('./tool/cmd-sep'); +var cd = require('./tool/gulp-cmd').cd; -var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); 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) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, - '--tasks', - ].join(' '), cb); + exec(cd(baseDir).gulp('--tasks'), cb); function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-depth4.txt'); @@ -31,12 +26,7 @@ describe('config: flags.tasksDepth', function() { }); it('Should overridden by cli flag: --tasks-depth', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, - '--tasks', - '--tasks-depth 2', - ].join(' '), cb); + exec(cd(baseDir).gulp('--tasks', '--tasks-depth', '2'), cb); function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-depth2.txt'); diff --git a/test/esm.js b/test/esm.js index 1828523c..db54b3df 100644 --- a/test/esm.js +++ b/test/esm.js @@ -8,9 +8,8 @@ var semver = require('semver'); var baseDir = path.join(__dirname, '..'); var sliceLines = require('./tool/slice-lines'); -var cmdSep = require('./tool/cmd-sep'); +var cd = require('./tool/gulp-cmd').cd; -var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); var expectedDir = path.join(__dirname, 'expected'); describe('ESM', function() { @@ -28,11 +27,7 @@ describe('ESM', function() { trailingLines += 2; } - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, - options, - ].join(' '), cb); + exec(cd(baseDir).gulp(options), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); diff --git a/test/execution-errors.js b/test/execution-errors.js index 6f13df8a..25277bd9 100644 --- a/test/execution-errors.js +++ b/test/execution-errors.js @@ -10,18 +10,12 @@ 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 cmdSep = require('./tool/cmd-sep'); - -var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); +var cd = require('./tool/gulp-cmd').cd; describe('execution error', function() { it('should output an error if a task is not defined', function(done) { - exec([ - 'cd ' + path.join(__dirname, './fixtures/gulpfiles') + cmdSep, - gulpCmd, - 'a', - ].join(' '), cb); + exec(cd(__dirname, './fixtures/gulpfiles').gulp('a'), cb); function cb(err, stdout, stderr) { expect(err).not.toBeNull(); @@ -35,10 +29,7 @@ describe('execution error', function() { }); it('should output an error if gulp version is unsupported', function(done) { - exec([ - 'cd ' + path.join(__dirname, './fixtures/errors/bad-gulp-version') + cmdSep, - gulpCmd, - ].join(' '), cb); + exec(cd(__dirname, './fixtures/errors/bad-gulp-version').gulp(), cb); function cb(err, stdout, stderr) { expect(err).not.toBeNull(); @@ -51,11 +42,12 @@ describe('execution error', function() { it('should output an error if gulp is not found', function(done) { var tmpdir = os.tmpdir(); - exec([ - os.platform() === 'win32' ? tmpdir.slice(0, 2) + cmdSep : '', - 'cd ' + tmpdir + cmdSep, - gulpCmd, - ].join(' '), cb); + if (os.platform() === 'win32') { + var moveDrive = tmpdir.slice(0, 2) + '&'; + exec(moveDrive + cd(tmpdir).gulp(), cb); + } else { + exec(cd(tmpdir).gulp(), cb); + } function cb(err, stdout, stderr) { expect(err).not.toBeNull(); @@ -70,11 +62,9 @@ describe('execution error', function() { var dir = path.join(__dirname, 'fixtures/gulpfiles'); var gulpfileName = 'gulpfile-dedup-errorlog.js'; - exec([ - 'cd ' + dir + cmdSep, - 'node ' + path.join(__dirname, '../bin/gulp.js'), - '--gulpfile', gulpfileName, - ].join(' '), cb); + exec(cd(dir).gulp( + '--gulpfile', gulpfileName + ), cb); function cb(err, stdout, stderr) { expect(err).not.toBeNull(); @@ -96,4 +86,3 @@ describe('execution error', function() { } }); }); - diff --git a/test/exports-as-tasks.js b/test/exports-as-tasks.js index 0f88b600..167f40e1 100644 --- a/test/exports-as-tasks.js +++ b/test/exports-as-tasks.js @@ -6,9 +6,8 @@ var fs = require('fs'); var path = require('path'); var sliceLines = require('./tool/slice-lines'); -var cmdSep = require('./tool/cmd-sep'); +var cd = require('./tool/gulp-cmd').cd; -var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); var baseDir = path.join(__dirname, '..'); var expectedDir = path.join(__dirname, 'expected'); @@ -17,13 +16,11 @@ describe('exports as tasks', function() { this.timeout(0); it('prints the task list', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, + exec(cd(baseDir).gulp( '--tasks', '--sort-tasks', - '--gulpfile ./test/fixtures/gulpfiles/gulpfile-exports.babel.js', - ].join(' '), cb); + '--gulpfile', './test/fixtures/gulpfiles/gulpfile-exports.babel.js' + ), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); diff --git a/test/flags-continue.js b/test/flags-continue.js index 3627d6b9..de84d4b2 100644 --- a/test/flags-continue.js +++ b/test/flags-continue.js @@ -5,21 +5,18 @@ var exec = require('child_process').exec; var path = require('path'); var sliceLines = require('./tool/slice-lines'); -var cmdSep = require('./tool/cmd-sep'); +var cd = require('./tool/gulp-cmd').cd; -var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); var baseDir = path.join(__dirname, '..'); describe('flag: --continue', function() { it('continues execution when flag is set', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, + exec(cd(baseDir).gulp( 'test4', '--continue', - '--cwd ./test/fixtures/gulpfiles', - ].join(' '), cb); + '--cwd ./test/fixtures/gulpfiles' + ), cb); function cb(err, stdout, stderr) { expect(err).not.toBeNull(); @@ -39,12 +36,7 @@ describe('flag: --continue', function() { }); it('stops execution when flag is not set', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, - 'test4', - '--cwd ./test/fixtures/gulpfiles', - ].join(' '), cb); + exec(cd(baseDir).gulp('test4', '--cwd ./test/fixtures/gulpfiles'), cb); function cb(err, stdout, stderr) { expect(err).not.toBeNull(); diff --git a/test/flags-gulpfile.js b/test/flags-gulpfile.js index f4979bb9..274f0063 100644 --- a/test/flags-gulpfile.js +++ b/test/flags-gulpfile.js @@ -5,9 +5,8 @@ var exec = require('child_process').exec; var path = require('path'); var sliceLines = require('./tool/slice-lines'); -var cmdSep = require('./tool/cmd-sep'); +var cd = require('./tool/gulp-cmd').cd; -var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); var baseDir = path.join(__dirname, '..'); describe('flag: --gulpfile', function() { @@ -15,11 +14,7 @@ describe('flag: --gulpfile', function() { it('Manually set path of gulpfile using --gulpfile', function(done) { var gulpfilePath = 'test/fixtures/gulpfiles/gulpfile-2.js'; - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, - '--gulpfile', gulpfilePath, - ].join(' '), cb); + exec(cd(baseDir).gulp('--gulpfile', gulpfilePath), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -46,11 +41,7 @@ describe('flag: --gulpfile', function() { it('Manually set path of gulpfile using -f', function(done) { var gulpfilePath = 'test/fixtures/gulpfiles/gulpfile-2.js'; - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, - '-f', gulpfilePath, - ].join(' '), cb); + exec(cd(baseDir).gulp('-f', gulpfilePath), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); diff --git a/test/flags-help.js b/test/flags-help.js index 7ebd93bf..629ca0cc 100644 --- a/test/flags-help.js +++ b/test/flags-help.js @@ -5,9 +5,8 @@ var exec = require('child_process').exec; var path = require('path'); var fs = require('fs'); -var cmdSep = require('./tool/cmd-sep'); +var cd = require('./tool/gulp-cmd').cd; -var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); var baseDir = path.join(__dirname, '..'); var outputFile = path.join(__dirname, 'expected/flags-help.txt'); var outputText = fs.readFileSync(outputFile, 'utf8'); @@ -15,12 +14,10 @@ var outputText = fs.readFileSync(outputFile, 'utf8'); describe('flag: --help', function() { it('shows help using --help', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, + exec(cd(baseDir).gulp( '--help', - '--cwd ./test/fixtures/gulpfiles', - ].join(' '), cb); + '--cwd ./test/fixtures/gulpfiles' + ), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -31,12 +28,10 @@ describe('flag: --help', function() { }); it('shows help using short --h', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, + exec(cd(baseDir).gulp( '--h', - '--cwd ./test/fixtures/gulpfiles', - ].join(' '), cb); + '--cwd ./test/fixtures/gulpfiles' + ), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -47,12 +42,10 @@ describe('flag: --help', function() { }); it('avoids printing "Requiring external module *"', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, + exec(cd(baseDir).gulp( '--help', - '--gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js', - ].join(' '), cb); + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js' + ), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); diff --git a/test/flags-preload.js b/test/flags-preload.js index 9e7d9e7f..df45138f 100644 --- a/test/flags-preload.js +++ b/test/flags-preload.js @@ -7,20 +7,17 @@ var path = require('path'); var sliceLines = require('./tool/slice-lines'); var eraseTime = require('./tool/erase-time'); var eraseLapse = require('./tool/erase-lapse'); -var cmdSep = require('./tool/cmd-sep'); +var cd = require('./tool/gulp-cmd').cd; -var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); var baseDir = path.join(__dirname, '..'); describe('flag: --preload', function() { it('preloads module before running gulpfile', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, + exec(cd(baseDir).gulp( '--preload ../test-module.js', '--cwd ./test/fixtures/gulpfiles' - ].join(' '), cb); + ), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -55,13 +52,11 @@ describe('flag: --preload', function() { }); it('can preload multiple modules before running gulpfile', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, + exec(cd(baseDir).gulp( '--preload ../test-module.js', '--preload ../test-module-2.js', - '--cwd ./test/fixtures/gulpfiles', - ].join(' '), cb); + '--cwd ./test/fixtures/gulpfiles' + ), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -77,12 +72,10 @@ describe('flag: --preload', function() { }); it('warns if module doesn\'t exist', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, + exec(cd(baseDir).gulp( '--preload ./null-module.js', - '--cwd ./test/fixtures/gulpfiles', - ].join(' '), cb); + '--cwd ./test/fixtures/gulpfiles' + ), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -121,12 +114,10 @@ describe('flag: --preload', function() { }); it('warns if module throw some error', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, + exec(cd(baseDir).gulp( '--preload ../test-error-module.js', - '--cwd ./test/fixtures/gulpfiles', - ].join(' '), cb); + '--cwd ./test/fixtures/gulpfiles' + ), cb); function cb(err, stdout, stderr) { stdout = eraseLapse(eraseTime(stdout)); diff --git a/test/flags-series.js b/test/flags-series.js index bf22f6b4..50c38167 100644 --- a/test/flags-series.js +++ b/test/flags-series.js @@ -5,21 +5,18 @@ var exec = require('child_process').exec; var path = require('path'); var sliceLines = require('./tool/slice-lines'); -var cmdSep = require('./tool/cmd-sep'); +var cd = require('./tool/gulp-cmd').cd; -var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); var baseDir = path.join(__dirname, '..'); describe('flag: --series', function() { it('runs tasks in series when flag is set', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, + exec(cd(baseDir).gulp( 'test5 test6', '--series', '--cwd ./test/fixtures/gulpfiles' - ].join(' '), cb); + ), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -36,12 +33,10 @@ describe('flag: --series', function() { }); it('runs tasks in parallel when flag is not set', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, + exec(cd(baseDir).gulp( 'test5 test6', - '--cwd ./test/fixtures/gulpfiles', - ].join(' '), cb); + '--cwd ./test/fixtures/gulpfiles' + ), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); diff --git a/test/flags-silent.js b/test/flags-silent.js index d12088ac..d4b33cc4 100644 --- a/test/flags-silent.js +++ b/test/flags-silent.js @@ -4,20 +4,17 @@ var expect = require('expect'); var exec = require('child_process').exec; var path = require('path'); -var cmdSep = require('./tool/cmd-sep'); +var cd = require('./tool/gulp-cmd').cd; -var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); var baseDir = path.join(__dirname, '..'); describe('flag: --silent', function() { it('prints nothing when silent flag is set', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, + exec(cd(baseDir).gulp( '--silent', - '--cwd ./test/fixtures/gulpfiles', - ].join(' '), cb); + '--cwd ./test/fixtures/gulpfiles' + ), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); diff --git a/test/flags-tasks-json.js b/test/flags-tasks-json.js index 295f4bfc..ae70e36e 100644 --- a/test/flags-tasks-json.js +++ b/test/flags-tasks-json.js @@ -6,21 +6,18 @@ var fs = require('fs'); var path = require('path'); var rimraf = require('rimraf'); -var cmdSep = require('./tool/cmd-sep'); +var cd = require('./tool/gulp-cmd').cd; -var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); 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) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, + exec(cd(baseDir).gulp( '--tasks-json', '--gulpfile ./test/fixtures/gulpfiles/gulpfile.js' - ].join(' '), cb); + ), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -34,13 +31,11 @@ describe('flag: --tasks-json', function() { var cwdPath = __dirname; var gulpfilePath = path.join(__dirname, 'fixtures/gulpfiles/gulpfile.js'); - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, + exec(cd(baseDir).gulp( '--tasks-json', '--cwd ', cwdPath, - '--gulpfile ', gulpfilePath, - ].join(' '), cb); + '--gulpfile ', gulpfilePath + ), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -57,12 +52,10 @@ describe('flag: --tasks-json', function() { rimraf.sync(output); fs.mkdirSync(output); - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, + exec(cd(baseDir).gulp( '--tasks-json ../../output/tasks.json', - '--gulpfile ./test/fixtures/gulpfiles/gulpfile.js', - ].join(' '), cb); + '--gulpfile ./test/fixtures/gulpfiles/gulpfile.js' + ), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -81,12 +74,10 @@ describe('flag: --tasks-json', function() { // Disable the timeout for old node versions this.timeout(0); - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, + exec(cd(baseDir).gulp( '--tasks-json', - '--gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js', - ].join(' '), cb); + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js' + ), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); diff --git a/test/flags-tasks-simple.js b/test/flags-tasks-simple.js index 73e8e28a..6297b264 100644 --- a/test/flags-tasks-simple.js +++ b/test/flags-tasks-simple.js @@ -5,9 +5,8 @@ var exec = require('child_process').exec; var path = require('path'); var fs = require('fs'); -var cmdSep = require('./tool/cmd-sep'); +var cd = require('./tool/gulp-cmd').cd; -var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); var baseDir = path.join(__dirname, '..'); var outputFile = path.join(__dirname, 'expected/flags-tasks-simple.txt'); var outputText = fs.readFileSync(outputFile, 'utf8'); @@ -15,12 +14,10 @@ var outputText = fs.readFileSync(outputFile, 'utf8'); describe('flag: --tasks-simple', function() { it('prints the task list in simple format', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, + exec(cd(baseDir).gulp( '--tasks-simple', - '--cwd ./test/fixtures/gulpfiles', - ].join(' '), cb); + '--cwd ./test/fixtures/gulpfiles' + ), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -34,12 +31,10 @@ describe('flag: --tasks-simple', function() { // Disable the timeout for old node versions this.timeout(0); - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, + exec(cd(baseDir).gulp( '--tasks-simple', '--gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js' - ].join(' '), cb); + ), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); diff --git a/test/flags-tasks.js b/test/flags-tasks.js index 1e10641a..f2978de3 100644 --- a/test/flags-tasks.js +++ b/test/flags-tasks.js @@ -6,20 +6,19 @@ var fs = require('fs'); var path = require('path'); var sliceLines = require('./tool/slice-lines'); -var cmdSep = require('./tool/cmd-sep'); +var cd = require('./tool/gulp-cmd').cd; -var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); var baseDir = path.join(__dirname, '..'); var expectedDir = path.join(__dirname, 'expected'); describe('flag: --tasks', function() { it('prints the task list', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, - '--tasks --sort-tasks --cwd ./test/fixtures/gulpfiles', - ].join(' '), cb); + exec(cd(baseDir).gulp( + '--tasks', + '--sort-tasks', + '--cwd ./test/fixtures/gulpfiles' + ), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -32,13 +31,12 @@ describe('flag: --tasks', function() { }); it('print the task list with description and flags', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, - '--tasks', '--sort-tasks', + exec(cd(baseDir).gulp( + '--tasks', + '--sort-tasks', '--gulpfile ./test/fixtures/gulpfiles/with-desc-and-flags.js', - '--cwd ./test/fixtures', - ].join(' '), cb); + '--cwd ./test/fixtures' + ), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -51,13 +49,12 @@ describe('flag: --tasks', function() { }); it('print the task list by gulp.task(s).unwrap and gulp.task(s)', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, - '--tasks', '--sort-tasks', + exec(cd(baseDir).gulp( + '--tasks', + '--sort-tasks', '--gulpfile ./test/fixtures/gulpfiles/by-unwrap-and-not-by-unwrap.js', - '--cwd ./test/fixtures', - ].join(' '), cb); + '--cwd ./test/fixtures' + ), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -70,11 +67,10 @@ describe('flag: --tasks', function() { }); it('prints the task list without --sort-tasks flag', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, - '--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', - ].join(' '), cb); + exec(cd(baseDir).gulp( + '--tasks', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js' + ), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -87,12 +83,11 @@ describe('flag: --tasks', function() { }); it('prints the task list with --sort-tasks flag', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, - '--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', - '--sort-tasks', - ].join(' '), cb); + exec(cd(baseDir).gulp( + '--tasks', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', + '--sort-tasks' + ), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -105,12 +100,11 @@ describe('flag: --tasks', function() { }); it('prints the task list with --tasks-depth flag', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, - '--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', - '--tasks-depth 4', - ].join(' '), cb); + exec(cd(baseDir).gulp( + '--tasks', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', + '--tasks-depth 4' + ), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -123,12 +117,11 @@ describe('flag: --tasks', function() { }); it('prints the task list with --depth flag', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, - '--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', - '--depth 4', - ].join(' '), cb); + exec(cd(baseDir).gulp( + '--tasks', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', + '--depth 4' + ), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -141,12 +134,11 @@ describe('flag: --tasks', function() { }); it('prints the task list with --compact-tasks flag', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, - '--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', - '--compact-tasks', - ].join(' '), cb); + exec(cd(baseDir).gulp( + '--tasks', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', + '--compact-tasks' + ), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); diff --git a/test/flags-v8flags.js b/test/flags-v8flags.js index 6a49afa1..684424fa 100644 --- a/test/flags-v8flags.js +++ b/test/flags-v8flags.js @@ -5,19 +5,14 @@ var exec = require('child_process').exec; var path = require('path'); var sliceLines = require('./tool/slice-lines'); -var cmdSep = require('./tool/cmd-sep'); +var cd = require('./tool/gulp-cmd').cd; -var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); var baseDir = path.join(__dirname, 'fixtures/gulpfiles'); describe('flags: v8flags', function() { it('Should respawn by a v8flag: --lazy', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, - '--lazy', - ].join(' '), cb); + exec(cd(baseDir).gulp('--lazy'), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -29,11 +24,7 @@ describe('flags: v8flags', function() { }); it('Should respawn by v8flags: --lazy --harmony', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, - '--lazy --harmony' - ].join(' '), cb); + exec(cd(baseDir).gulp('--lazy --harmony'), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); diff --git a/test/flags-verify.js b/test/flags-verify.js index 061f78c2..e3aa15a4 100644 --- a/test/flags-verify.js +++ b/test/flags-verify.js @@ -5,20 +5,17 @@ var exec = require('child_process').exec; var path = require('path'); var eraseTime = require('./tool/erase-time'); -var cmdSep = require('./tool/cmd-sep'); +var cd = require('./tool/gulp-cmd').cd; var baseDir = path.join(__dirname, '..'); -var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); describe('flag: --verify', function() { it('dependencies with invalid dependency', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, + exec(cd(baseDir).gulp( '--verify invalid-package.json', - '--cwd ./test/fixtures/verify/', - ].join(' '), cb); + '--cwd ./test/fixtures/verify/' + ), cb); function cb(err, stdout, stderr) { expect(err).not.toBeNull(); @@ -34,11 +31,10 @@ describe('flag: --verify', function() { }); it('dependencies with valid dependency', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, - '--verify valid-package.json', '--cwd ./test/fixtures/verify/', - ].join(' '), cb); + exec(cd(baseDir).gulp( + '--verify valid-package.json', + '--cwd ./test/fixtures/verify/' + ), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -53,11 +49,10 @@ describe('flag: --verify', function() { }); it('default args with invalid dependency', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, - '--verify', '--cwd', path.resolve('./test/fixtures/verify/'), - ].join(' '), cb); + exec(cd(baseDir).gulp( + '--verify', + '--cwd', path.resolve('./test/fixtures/verify/') + ), cb); function cb(err, stdout, stderr) { expect(err).not.toBeNull(); diff --git a/test/flags-version.js b/test/flags-version.js index e47612aa..41bec492 100644 --- a/test/flags-version.js +++ b/test/flags-version.js @@ -5,22 +5,19 @@ var exec = require('child_process').exec; var path = require('path'); var os = require('os'); -var cmdSep = require('./tool/cmd-sep'); - +var cd = require('./tool/gulp-cmd').cd; var cliVersion = require('../package.json').version; var gulpVersion = require('gulp/package.json').version; -var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); var baseDir = path.join(__dirname, '..'); describe('flag: --version', function() { it('prints the version of CLI and local gulp', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, - '--version --cwd ./test/fixtures/gulpfiles', - ].join(' '), cb); + exec(cd(baseDir).gulp( + '--version', + '--cwd ./test/fixtures/gulpfiles' + ), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -35,11 +32,10 @@ describe('flag: --version', function() { }); it('avoids printing "Requiring external module *"', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, - '--version --gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js', - ].join(' '), cb); + exec(cd(baseDir).gulp( + '--version', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js' + ), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -54,11 +50,7 @@ describe('flag: --version', function() { }); it('should print only CLI version when gulp is not found', function(done) { - exec([ - 'cd ' + baseDir + cmdSep, - gulpCmd, - '--version', '--cwd', os.tmpdir(), - ].join(' '), cb); + exec(cd(baseDir).gulp('--version', '--cwd', os.tmpdir()), cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); diff --git a/test/logging.js b/test/logging.js index c00049c4..11d6bd5a 100644 --- a/test/logging.js +++ b/test/logging.js @@ -1,12 +1,12 @@ '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).toBeNull(); @@ -20,7 +20,7 @@ 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).toBeNull(); @@ -33,7 +33,7 @@ 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).toBeNull(); @@ -46,7 +46,7 @@ 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).toBeNull(); @@ -58,7 +58,7 @@ 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).toBeNull(); diff --git a/test/sync-task.js b/test/sync-task.js index 5451567d..1bcd59ae 100644 --- a/test/sync-task.js +++ b/test/sync-task.js @@ -2,20 +2,13 @@ var expect = require('expect'); var exec = require('child_process').exec; -var path = require('path'); var sliceLines = require('./tool/slice-lines'); -var cmdSep = require('./tool/cmd-sep'); - -var gulpCmd = 'node ' + path.join(__dirname, '../bin/gulp.js'); +var cd = require('./tool/gulp-cmd').cd; describe('sync-task', function() { it('should return error code 1 if any tasks did not complete', function(done) { - exec([ - 'cd ' + path.join(__dirname, 'fixtures/gulpfiles') + cmdSep, - gulpCmd, - 'test6 test7 test8', - ].join(' '), cb); + exec(cd(__dirname, 'fixtures/gulpfiles').gulp('test6 test7 test8'), cb); function cb(err) { expect(err).not.toBeNull(); @@ -25,11 +18,7 @@ describe('sync-task', function() { }); it('should log tasks which did not complete', function(done) { - exec([ - 'cd ' + path.join(__dirname, 'fixtures/gulpfiles') + cmdSep, - gulpCmd, - 'test6 test7 test8', - ].join(' '), cb); + exec(cd(__dirname, 'fixtures/gulpfiles').gulp('test6 test7 test8'), cb); function cb(err, stdout) { expect(sliceLines(stdout, 5, 7)).toEqual( @@ -41,11 +30,9 @@ describe('sync-task', function() { }); it('should not log false positive in case of parallel failure', function(done) { - exec([ - 'cd ' + path.join(__dirname, '..') + cmdSep, - gulpCmd, + exec(cd(__dirname, '..').gulp( '--gulpfile ./test/fixtures/gulpfiles/gulpfile-parallel-failure.js' - ].join(' '), cb); + ), cb); function cb(err, stdout) { expect(stdout).toEqual(expect.not.stringContaining( @@ -56,11 +43,9 @@ describe('sync-task', function() { }); it('should not log false positive in case of parallel failure in continue mode', function(done) { - exec([ - 'cd ' + path.join(__dirname, '..') + cmdSep, - gulpCmd, - '--continue --gulpfile ./test/fixtures/gulpfiles/gulpfile-parallel-failure.js', - ].join(' '), cb); + exec(cd(__dirname, '..').gulp( + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-parallel-failure.js' + ), cb); function cb(err, stdout) { expect(stdout).toEqual(expect.not.stringContaining( @@ -71,11 +56,11 @@ describe('sync-task', function() { }); it('should log non-completing task alongside a failure in continue mode', function(done) { - exec([ - 'cd ' + path.join(__dirname, '..') + cmdSep, - gulpCmd, - '--continue --gulpfile ./test/fixtures/gulpfiles/gulpfile-parallel-failure.js broken', - ].join(' '), cb); + exec(cd(__dirname, '..').gulp( + '--continue', + '--gulpfile ./test/fixtures/gulpfiles/gulpfile-parallel-failure.js', + 'broken' + ), cb); function cb(err, stdout) { expect(stdout).toEqual(expect.stringContaining( diff --git a/test/tool/cmd-sep.js b/test/tool/cmd-sep.js deleted file mode 100644 index 7b3acfc7..00000000 --- a/test/tool/cmd-sep.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict'; - -var os = require('os'); - -module.exports = os.platform() === 'win32' ? '&' : ';'; diff --git a/test/tool/gulp-cmd.js b/test/tool/gulp-cmd.js new file mode 100644 index 00000000..d7faf0a1 --- /dev/null +++ b/test/tool/gulp-cmd.js @@ -0,0 +1,32 @@ +'use strict'; + +var os = require('os'); +var path = require('path'); + +var cmdSep = os.platform() === 'win32' ? '& ' : '; '; + +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; +} + +function cd(/* ... */) { + var cd = 'cd ' + path.join.apply(null, arguments) + cmdSep; + var g = function(/* ... */) { + return cd + gulp.apply(null, arguments); + }; + g.debug = function(/* ... */) { + var s = g.apply(null, arguments); + console.log(s); + return s; + }; + return { gulp: g }; +} + +module.exports = { cd: cd, gulp: gulp }; From 64e381b1f8d8c2497f01924532c2b43b03f21146 Mon Sep 17 00:00:00 2001 From: sttk Date: Sun, 8 Oct 2023 17:00:14 +0900 Subject: [PATCH 25/35] fix: change expect.stringContaining to use toMatch in test/sync-taks.js --- test/sync-task.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/test/sync-task.js b/test/sync-task.js index 1bcd59ae..a60798ef 100644 --- a/test/sync-task.js +++ b/test/sync-task.js @@ -35,9 +35,7 @@ describe('sync-task', function() { ), cb); function cb(err, stdout) { - expect(stdout).toEqual(expect.not.stringContaining( - 'The following tasks did not complete:' - )); + expect(stdout).not.toMatch('The following tasks did not complete:'); done(); } }); @@ -48,9 +46,7 @@ describe('sync-task', function() { ), cb); function cb(err, stdout) { - expect(stdout).toEqual(expect.not.stringContaining( - 'The following tasks did not complete:' - )); + expect(stdout).not.toMatch('The following tasks did not complete:'); done(); } }); @@ -63,9 +59,7 @@ describe('sync-task', function() { ), cb); function cb(err, stdout) { - expect(stdout).toEqual(expect.stringContaining( - 'The following tasks did not complete: broken, notCompleting1\n' - )); + expect(stdout).toMatch('The following tasks did not complete: broken, notCompleting1\n'); done(); } }); From 7242a8ea4586260d8a6a2ec144e2a72b2f9acfe6 Mon Sep 17 00:00:00 2001 From: sttk Date: Sun, 8 Oct 2023 17:14:44 +0900 Subject: [PATCH 26/35] fix: remove extra not.toMatch in test/flags-preload.js --- test/flags-preload.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/flags-preload.js b/test/flags-preload.js index df45138f..87a9048e 100644 --- a/test/flags-preload.js +++ b/test/flags-preload.js @@ -85,8 +85,6 @@ describe('flag: --preload', function() { 'Failed to preload external module: ./null-module.js' ); expect(sliceLines(stdout, 2, 3)).toMatch('Error: Cannot find module \'./null-module.js\''); - expect(stdout).not.toMatch('inside test module'); - expect(stdout).not.toMatch('Preloaded external module: ../null-module.js'); var chgWorkdirLog = sliceLines(stdout, 3, 4); var workdir = 'test/fixtures/gulpfiles'.replace(/\//g, path.sep); From ccf2770bbb81d1eca73dc1e534574d4fbae7db24 Mon Sep 17 00:00:00 2001 From: sttk Date: Sun, 15 Oct 2023 15:37:44 +0900 Subject: [PATCH 27/35] update: remove archy and remake logTasks --- lib/shared/log/tasks.js | 248 ++++++++++++++++++---------------------- package.json | 1 - 2 files changed, 112 insertions(+), 137 deletions(-) diff --git a/lib/shared/log/tasks.js b/lib/shared/log/tasks.js index 6a3e17e1..4239148d 100644 --- a/lib/shared/log/tasks.js +++ b/lib/shared/log/tasks.js @@ -1,164 +1,140 @@ 'use strict'; -var archy = require('archy'); var log = require('gulplog'); - -var isObject = require('../is-object'); - var chalk = require('chalk'); -var copyTree = require('./copy-tree'); +var isObject = require('../is-object'); function logTasks(tree, opts, getTask) { if (opts.sortTasks) { 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 = Infinity; + } 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 = chalk.white(branch); - - if (info.type === 'top') { - line += chalk.cyan(info.name); - if (info.desc.length > 0) { - line += spacer(index) + chalk.white(info.desc); - } - } else if (info.type === 'option') { - line += chalk.magenta(info.name); - if (info.desc.length > 0) { - line += spacer(index) + chalk.white('…' + info.desc); - } - } else { // If (info.type === 'child') { - line += chalk.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().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) { diff --git a/package.json b/package.json index 4ecd2191..034355b8 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,6 @@ "cover": "nyc mocha --async-only --timeout 5000 test/lib test" }, "dependencies": { - "archy": "^1.0.0", "chalk": "^4.1.2", "copy-props": "^4.0.0", "fancy-log": "^2.0.0", From 1439453f7fff8b5c5dd6aa64e0a2670015c014db Mon Sep 17 00:00:00 2001 From: sttk Date: Sun, 29 Oct 2023 19:55:29 +0900 Subject: [PATCH 28/35] update: remove pretty-hrtime --- lib/shared/log/format-hrtime.js | 48 ++++++ lib/versioned/^3.7.0/log/events.js | 6 +- lib/versioned/^4.0.0/log/events.js | 6 +- package.json | 1 - test/lib/format-hrtime.js | 238 +++++++++++++++++++++++++++++ 5 files changed, 292 insertions(+), 7 deletions(-) create mode 100644 lib/shared/log/format-hrtime.js create mode 100644 test/lib/format-hrtime.js 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/versioned/^3.7.0/log/events.js b/lib/versioned/^3.7.0/log/events.js index d2fda5ce..a20de7ce 100644 --- a/lib/versioned/^3.7.0/log/events.js +++ b/lib/versioned/^3.7.0/log/events.js @@ -1,7 +1,7 @@ 'use strict'; var log = require('gulplog'); -var prettyTime = require('pretty-hrtime'); +var formatTime = require('../../../shared/log/format-hrtime'); var chalk = require('chalk'); var exit = require('../../../shared/exit'); @@ -30,7 +30,7 @@ function logEvents(gulpInst) { }); gulpInst.on('task_stop', function(e) { - var time = prettyTime(e.hrDuration); + var time = formatTime(e.hrDuration); log.info( 'Finished', '\'' + chalk.cyan(e.task) + '\'', 'after', chalk.magenta(time) @@ -39,7 +39,7 @@ function logEvents(gulpInst) { gulpInst.on('task_err', function(e) { var msg = formatError(e); - var time = prettyTime(e.hrDuration); + var time = formatTime(e.hrDuration); log.error( '\'' + chalk.cyan(e.task) + '\'', chalk.red('errored after'), diff --git a/lib/versioned/^4.0.0/log/events.js b/lib/versioned/^4.0.0/log/events.js index 4b398b89..0fb82c5c 100644 --- a/lib/versioned/^4.0.0/log/events.js +++ b/lib/versioned/^4.0.0/log/events.js @@ -1,7 +1,7 @@ 'use strict'; var log = require('gulplog'); -var prettyTime = require('pretty-hrtime'); +var formatTime = require('../../../shared/log/format-hrtime'); var chalk = require('chalk'); var formatError = require('../format-error'); @@ -20,7 +20,7 @@ function logEvents(gulpInst) { }); 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]( @@ -31,7 +31,7 @@ function logEvents(gulpInst) { 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]( '\'' + chalk.cyan(evt.name) + '\'', diff --git a/package.json b/package.json index 034355b8..5a8ec3db 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,6 @@ "liftoff": "^4.0.0", "matchdep": "^2.0.0", "mute-stdout": "^2.0.0", - "pretty-hrtime": "^1.0.3", "replace-homedir": "^2.0.0", "semver-greatest-satisfied-range": "^2.0.0", "v8flags": "^4.0.0", 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(); + }); + }); +}); From 0ac2821524bcf7c8e43c75734daa444d84aadc5f Mon Sep 17 00:00:00 2001 From: sttk Date: Sat, 4 Nov 2023 16:54:21 +0900 Subject: [PATCH 29/35] update: remove matchdep and modify skip conditions of esm.js --- lib/shared/verify-dependencies.js | 13 ++++++++++--- package.json | 2 +- test/esm.js | 26 +++++++++++++++++++++++--- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/lib/shared/verify-dependencies.js b/lib/shared/verify-dependencies.js index a0d4812c..93ea4d53 100644 --- a/lib/shared/verify-dependencies.js +++ b/lib/shared/verify-dependencies.js @@ -1,6 +1,6 @@ 'use strict'; -var matchdep = require('matchdep'); +var micromatch = require('micromatch'); /** * Given a collection of plugin names verifies this collection against @@ -12,8 +12,15 @@ 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 = micromatch(pluginNames, Object.keys(blacklist)) .reduce(function(blacklisted, pluginName) { blacklisted[pluginName] = blacklist[pluginName]; return blacklisted; diff --git a/package.json b/package.json index 5a8ec3db..bb4862ce 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "gulplog": "^2.0.1", "interpret": "^3.1.1", "liftoff": "^4.0.0", - "matchdep": "^2.0.0", + "micromatch": "^4.0.5", "mute-stdout": "^2.0.0", "replace-homedir": "^2.0.0", "semver-greatest-satisfied-range": "^2.0.0", diff --git a/test/esm.js b/test/esm.js index db54b3df..93472f2a 100644 --- a/test/esm.js +++ b/test/esm.js @@ -5,6 +5,7 @@ var exec = require('child_process').exec; var fs = require('fs'); var path = require('path'); var semver = require('semver'); +var os = require('os'); var baseDir = path.join(__dirname, '..'); var sliceLines = require('./tool/slice-lines'); @@ -12,11 +13,26 @@ var cd = require('./tool/gulp-cmd').cd; 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) { - // Segmentation fault is caused only v10.15.3. - if (semver.eq(process.version, '10.15.3')) { + if (shouldSkip()) { this.skip(); } @@ -31,7 +47,11 @@ describe('ESM', function() { function cb(err, stdout, stderr) { expect(err).toBeNull(); - expect(stderr).toMatch(/^(.*ExperimentalWarning: The ESM module loader is experimental\.\n)?$/); + 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'); expect(sliceLines(stdout, trailingLines)).toEqual(expected); From 3319411a34b12480b8a199b5e7e57e1b3026a933 Mon Sep 17 00:00:00 2001 From: sttk Date: Sun, 19 Nov 2023 20:36:01 +0900 Subject: [PATCH 30/35] update: make env the sole object determining the behavior of gulp --- index.js | 22 +++++++++------------ lib/shared/config/cli-flags.js | 9 +++++---- lib/shared/config/env-flags.js | 20 +++++++++++++++---- lib/versioned/^3.7.0/index.js | 12 +++++++----- lib/versioned/^4.0.0-alpha.1/index.js | 11 ++++++----- lib/versioned/^4.0.0-alpha.2/index.js | 11 ++++++----- lib/versioned/^4.0.0/index.js | 11 ++++++----- test/lib/config-cli-flags.js | 11 +++++++---- test/lib/config-env-flags.js | 28 ++++++++++++++++++++++----- 9 files changed, 85 insertions(+), 50 deletions(-) diff --git a/index.js b/index.js index 997ea1c2..9e5f43b6 100644 --- a/index.js +++ b/index.js @@ -20,8 +20,7 @@ var getBlacklist = require('./lib/shared/blacklist'); var toConsole = require('./lib/shared/log/to-console'); var mergeProjectAndUserHomeConfigs = require('./lib/shared/config/merge-configs'); -var mergeConfigToCliFlags = require('./lib/shared/config/cli-flags'); -var mergeConfigToEnvFlags = require('./lib/shared/config/env-flags'); +var overrideEnvFlagsByConfigAndCliOpts = require('./lib/shared/config/env-flags'); // Logging functions var logVerify = require('./lib/shared/log/verify'); @@ -121,41 +120,38 @@ module.exports = run; function onPrepare(env) { var cfg = mergeProjectAndUserHomeConfigs(env); - opts = mergeConfigToCliFlags(opts, cfg); - env = mergeConfigToEnvFlags(env, cfg, opts); - env.config['.gulp'] = cfg; + env = overrideEnvFlagsByConfigAndCliOpts(env, cfg, opts); // Set up event listeners for logging again after configuring. - toConsole(log, opts); + 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); @@ -229,5 +225,5 @@ function onExecute(env) { // Load and execute the CLI version var versionedDir = path.join(__dirname, '/lib/versioned/', range, '/'); - require(versionedDir)(opts, env, env.config['.gulp']); + require(versionedDir)(env); } 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 583f0de2..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', 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') { @@ -41,4 +53,4 @@ function mergeConfigToEnvFlags(env, config, cliOpts) { } } -module.exports = mergeConfigToEnvFlags; +module.exports = overrideEnvFlags; diff --git a/lib/versioned/^3.7.0/index.js b/lib/versioned/^3.7.0/index.js index 7eade93f..a5cc2a9f 100644 --- a/lib/versioned/^3.7.0/index.js +++ b/lib/versioned/^3.7.0/index.js @@ -17,7 +17,9 @@ 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']; @@ -51,8 +53,8 @@ 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 ' + chalk.magenta(tildify(env.configPath)); } @@ -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/^4.0.0-alpha.1/index.js b/lib/versioned/^4.0.0-alpha.1/index.js index 0b68558c..c9c5ffc3 100644 --- a/lib/versioned/^4.0.0-alpha.1/index.js +++ b/lib/versioned/^4.0.0-alpha.1/index.js @@ -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,8 +53,8 @@ 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 ' + chalk.magenta(tildify(env.configPath)); } @@ -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); } diff --git a/lib/versioned/^4.0.0-alpha.2/index.js b/lib/versioned/^4.0.0-alpha.2/index.js index 52badc80..3d1763a6 100644 --- a/lib/versioned/^4.0.0-alpha.2/index.js +++ b/lib/versioned/^4.0.0-alpha.2/index.js @@ -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,8 +55,8 @@ 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 ' + chalk.magenta(tildify(env.configPath)); } @@ -64,8 +65,8 @@ function execute(opts, env, config) { } 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); } diff --git a/lib/versioned/^4.0.0/index.js b/lib/versioned/^4.0.0/index.js index 3553c015..d6883587 100644 --- a/lib/versioned/^4.0.0/index.js +++ b/lib/versioned/^4.0.0/index.js @@ -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,8 +55,8 @@ 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 ' + chalk.magenta(tildify(env.configPath)); } @@ -64,8 +65,8 @@ function execute(opts, env, config) { } 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); } 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 dfc43d48..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,11 +16,18 @@ 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(); }); @@ -49,7 +56,7 @@ 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', preload: ['preload', 'a', 'b'], @@ -59,7 +66,15 @@ describe('lib: config/env-flags', function() { 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(); }); @@ -77,7 +92,7 @@ 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', preload: 'preload', @@ -87,8 +102,11 @@ describe('lib: config/env-flags', function() { modulePath: '/path/of/module/path', modulePackage: { name: 'modulePackage' }, configFiles: { aaa: {} }, + config: { + flags: {}, + }, }); + expect(result).toBe(env); done(); }); - }); From 83c1603498df59618cf0cb603f3255cb272f0480 Mon Sep 17 00:00:00 2001 From: Takayuki Sato Date: Sun, 31 Dec 2023 00:46:18 +0900 Subject: [PATCH 31/35] Update lib/shared/log/tasks.js Co-authored-by: Blaine Bublitz --- lib/shared/log/tasks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/shared/log/tasks.js b/lib/shared/log/tasks.js index 4239148d..1eaf0859 100644 --- a/lib/shared/log/tasks.js +++ b/lib/shared/log/tasks.js @@ -11,7 +11,7 @@ function logTasks(tree, opts, getTask) { var maxDepth = opts.tasksDepth; if (typeof maxDepth !== 'number') { - maxDepth = Infinity; + maxDepth = 50; } else if (maxDepth < 1) { maxDepth = 1; } From 9b78b55667fc6906af97271dcfd7d43440fa6f21 Mon Sep 17 00:00:00 2001 From: sttk Date: Sat, 6 Jan 2024 12:34:35 +0900 Subject: [PATCH 32/35] fix: modify sorting task flag entries --- lib/shared/log/tasks.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/shared/log/tasks.js b/lib/shared/log/tasks.js index 1eaf0859..2d59fe35 100644 --- a/lib/shared/log/tasks.js +++ b/lib/shared/log/tasks.js @@ -109,7 +109,7 @@ function addTaskToLines(task, lines, isLast, isLeaf) { flagBars += '│ '; } - Object.entries(task.flags).sort().forEach(addFlagsToLines); + Object.entries(task.flags).sort(flagSorter).forEach(addFlagsToLines); function addFlagsToLines(ent) { if (typeof ent[0] !== 'string' || !ent[0]) return; @@ -148,5 +148,9 @@ function compareByLabel(a, b) { } } +function flagSorter(a, b) { + return (a[0] <= b[0]) ? -1 : 1; +} + module.exports = logTasks; From ccb26521ebf936641c390c21633234922b5a7b51 Mon Sep 17 00:00:00 2001 From: sttk Date: Sat, 6 Jan 2024 15:31:30 +0900 Subject: [PATCH 33/35] update: remove cd in tool/gulp-cmd.js and use cwd option of exec instead --- test/completion.js | 2 +- test/config-description.js | 16 +++++++---- test/config-flags-compact-tasks.js | 14 ++++++---- test/config-flags-continue.js | 14 ++++++---- test/config-flags-gulpfile.js | 23 ++++++++++------ test/config-flags-log-level.js | 44 ++++++++++++++++++++---------- test/config-flags-node-flags.js | 17 ++++++++---- test/config-flags-preload.js | 17 ++++++++---- test/config-flags-series.js | 14 ++++++---- test/config-flags-silent.js | 14 ++++++---- test/config-flags-sort-tasks.js | 14 ++++++---- test/config-flags-tasks-depth.js | 8 ++++-- test/esm.js | 5 ++-- test/execution-errors.js | 18 ++++++------ test/exports-as-tasks.js | 7 +++-- test/flags-continue.js | 10 ++++--- test/flags-gulpfile.js | 8 ++++-- test/flags-help.js | 17 +++++++----- test/flags-preload.js | 22 +++++++++------ test/flags-series.js | 12 ++++---- test/flags-silent.js | 7 +++-- test/flags-tasks-json.js | 22 +++++++++------ test/flags-tasks-simple.js | 12 ++++---- test/flags-tasks.js | 42 ++++++++++++++++------------ test/flags-v8flags.js | 8 ++++-- test/flags-verify.js | 17 +++++++----- test/flags-version.js | 15 ++++++---- test/sync-task.js | 24 ++++++++++------ test/tool/gulp-cmd.js | 18 +----------- 29 files changed, 274 insertions(+), 187 deletions(-) diff --git a/test/completion.js b/test/completion.js index 705387d8..3c30ad74 100644 --- a/test/completion.js +++ b/test/completion.js @@ -5,7 +5,7 @@ var exec = require('child_process').exec; var path = require('path'); var fs = require('fs'); -var gulp = require('./tool/gulp-cmd').gulp; +var gulp = require('./tool/gulp-cmd'); describe('flag: --completion', function() { diff --git a/test/config-description.js b/test/config-description.js index 8fc80ecc..ac85fd70 100644 --- a/test/config-description.js +++ b/test/config-description.js @@ -7,7 +7,7 @@ var fs = require('fs'); var sliceLines = require('./tool/slice-lines'); var eraseTime = require('./tool/erase-time'); -var cd = require('./tool/gulp-cmd').cd; +var gulp = require('./tool/gulp-cmd'); var baseDir = path.join(__dirname, 'fixtures', 'config'); var expectedDir = path.join(__dirname, 'expected', 'config'); @@ -15,7 +15,8 @@ var expectedDir = path.join(__dirname, 'expected', 'config'); describe('config: description', function() { it('Should configure with a .gulp.* file in cwd', function(done) { - exec(cd(baseDir, 'foo/bar').gulp('--tasks'), cb); + var opts = { cwd: path.join(baseDir, 'foo/bar') }; + exec(gulp('--tasks'), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -27,7 +28,8 @@ describe('config: description', function() { }); it('Should configure with a .gulp.* file in cwd found up', function(done) { - exec(cd(baseDir, 'foo/bar/baz').gulp('--tasks'), cb); + var opts = { cwd: path.join(baseDir, 'foo/bar/baz') }; + exec(gulp('--tasks'), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -39,7 +41,8 @@ describe('config: description', function() { }); it('Should configure with a .gulp.* file in cwd even if it is not a project root', function(done) { - exec(cd(baseDir, 'foo/bar/quux').gulp('--tasks'), cb); + var opts = { cwd: path.join(baseDir, 'foo/bar/quux') }; + exec(gulp('--tasks'), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -51,11 +54,12 @@ describe('config: description', function() { }); it('Should configure with a .gulp.* file in cwd by --cwd', function(done) { - exec(cd(baseDir, 'qux').gulp( + var opts = { cwd: path.join(baseDir, 'qux') }; + exec(gulp( '--tasks', '--gulpfile ../foo/bar/gulpfile.js', '--cwd .' - ), cb); + ), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); diff --git a/test/config-flags-compact-tasks.js b/test/config-flags-compact-tasks.js index bfdbb023..06945128 100644 --- a/test/config-flags-compact-tasks.js +++ b/test/config-flags-compact-tasks.js @@ -6,7 +6,7 @@ var path = require('path'); var fs = require('fs'); var sliceLines = require('./tool/slice-lines'); -var cd = require('./tool/gulp-cmd').cd; +var gulp = require('./tool/gulp-cmd'); var baseDir = path.join(__dirname, 'fixtures/config/flags/compactTasks'); var expectedDir = path.join(__dirname, 'expected'); @@ -14,7 +14,8 @@ var expectedDir = path.join(__dirname, 'expected'); describe('config: flags.compactTasks', function() { it('Should compact task lists when `flags.compactTasks` is true in .gulp.*', function(done) { - exec(cd(baseDir, 't').gulp('--tasks'), cb); + 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'); @@ -28,7 +29,8 @@ describe('config: flags.compactTasks', function() { }); it('Should not compact task lists when `flags.compactTasks` is false in .gulp.*', function(done) { - exec(cd(baseDir, 'f').gulp('--tasks'), cb); + 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'); @@ -42,7 +44,8 @@ describe('config: flags.compactTasks', function() { }); it('Should overridden by cli flag: --compact-tasks', function(done) { - exec(cd(baseDir, 'f').gulp('--tasks', '--compact-tasks'), 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'); @@ -56,7 +59,8 @@ describe('config: flags.compactTasks', function() { }); it('Should overridden by cli flag: --no-compact-tasks', function(done) { - exec(cd(baseDir, 't').gulp('--tasks', '--no-compact-tasks'), 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'); diff --git a/test/config-flags-continue.js b/test/config-flags-continue.js index 4f607cea..5764bfbb 100644 --- a/test/config-flags-continue.js +++ b/test/config-flags-continue.js @@ -5,14 +5,15 @@ var exec = require('child_process').exec; var path = require('path'); var sliceLines = require('./tool/slice-lines'); -var cd = require('./tool/gulp-cmd').cd; +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) { - exec(cd(baseDir, 't').gulp(), cb); + var opts = { cwd: path.join(baseDir, 't') }; + exec(gulp(), opts, cb); function cb(err, stdout, stderr) { expect(err).not.toBeNull(); @@ -34,7 +35,8 @@ describe('config: flags.continue', function() { }); it('Should not continue if `flags.continue` is false in .gulp.*', function(done) { - exec(cd(baseDir, 'f').gulp(), cb); + var opts = { cwd: path.join(baseDir, 'f') }; + exec(gulp(), opts, cb); function cb(err, stdout, stderr) { expect(err).not.toBeNull(); @@ -54,7 +56,8 @@ describe('config: flags.continue', function() { }); it('Should overridden by cli flag: --continue', function(done) { - exec(cd(baseDir, 'f').gulp('--continue'), cb); + var opts = { cwd: path.join(baseDir, 'f') }; + exec(gulp('--continue'), opts, cb); function cb(err, stdout, stderr) { expect(err).not.toBeNull(); @@ -76,7 +79,8 @@ describe('config: flags.continue', function() { }); it('Should overridden by cli flag: --no-continue', function(done) { - exec(cd(baseDir, 't').gulp('--no-continue'), cb); + var opts = { cwd: path.join(baseDir, 't') }; + exec(gulp('--no-continue'), opts, cb); function cb(err, stdout, stderr) { expect(err).not.toBeNull(); diff --git a/test/config-flags-gulpfile.js b/test/config-flags-gulpfile.js index 0dcb09f5..5cf6d819 100644 --- a/test/config-flags-gulpfile.js +++ b/test/config-flags-gulpfile.js @@ -5,14 +5,15 @@ var exec = require('child_process').exec; var path = require('path'); var sliceLines = require('./tool/slice-lines'); -var cd = require('./tool/gulp-cmd').cd; +var gulp = require('./tool/gulp-cmd'); var baseDir = path.join(__dirname, 'fixtures/config/flags/gulpfile'); describe('config: flags.gulpfile', function() { it('Should configure with a .gulp.* file', function(done) { - exec(cd(baseDir).gulp(), cb); + var opts = { cwd: baseDir }; + exec(gulp(), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -26,7 +27,8 @@ describe('config: flags.gulpfile', function() { }); it('Should configure with a .gulp.* file in the directory specified by --cwd', function(done) { - exec(cd(__dirname, 'fixtures/config').gulp('--cwd ./flags/gulpfile'), cb); + var opts = { cwd: path.join(__dirname, 'fixtures/config') }; + exec(gulp('--cwd ./flags/gulpfile'), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -40,7 +42,8 @@ describe('config: flags.gulpfile', function() { }); it('Should load a ./gulp.* file in a directory specified by --cwd', function(done) { - exec(cd(baseDir).gulp('--cwd ./cwd'), cb); + var opts = { cwd: baseDir }; + exec(gulp('--cwd ./cwd'), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -53,7 +56,8 @@ describe('config: flags.gulpfile', function() { }); it('Should ignore a ./.gulp.* file if another gulpfile is specified by --gulpfile', function(done) { - exec(cd(baseDir).gulp('--gulpfile ./cwd/gulpfile.js'), cb); + var opts = { cwd: baseDir }; + exec(gulp('--gulpfile ./cwd/gulpfile.js'), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -66,7 +70,8 @@ describe('config: flags.gulpfile', function() { }); it('Should overridden by cli flag: --gulpfile', function(done) { - exec(cd(baseDir, 'override-by-cliflag').gulp('--gulpfile mygulpfile.js'), cb); + var opts = { cwd: path.join(baseDir, 'override-by-cliflag') }; + exec(gulp('--gulpfile mygulpfile.js'), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -81,7 +86,8 @@ describe('config: flags.gulpfile', function() { it('Should autoload a module for loading a specified gulpfile', function(done) { this.timeout(0); - exec(cd(baseDir, 'autoload').gulp('dist'), cb); + var opts = { cwd: path.join(baseDir, 'autoload') }; + exec(gulp('dist'), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -94,7 +100,8 @@ describe('config: flags.gulpfile', function() { }); it('Should output error logs of autoload if fail to load module for a specified gulpfile', function(done) { - exec(cd(baseDir, 'autoload-fail').gulp('dist'), cb); + var opts = { cwd: path.join(baseDir, 'autoload-fail') }; + exec(gulp('dist'), opts, cb); function cb(err, stdout, stderr) { expect(err).not.toBeNull(); diff --git a/test/config-flags-log-level.js b/test/config-flags-log-level.js index 42d602c6..8d187cf0 100644 --- a/test/config-flags-log-level.js +++ b/test/config-flags-log-level.js @@ -6,7 +6,7 @@ var path = require('path'); var sliceLines = require('./tool/slice-lines'); var eraseTime = require('./tool/erase-time'); -var cd = require('./tool/gulp-cmd').cd; +var gulp = require('./tool/gulp-cmd'); var baseDir = path.join(__dirname, 'fixtures/config/flags/logLevel'); @@ -15,7 +15,8 @@ describe('config: flag.logLevel', function() { describe('log level 3 by default', function() { it('Should output error log', function(done) { - exec(cd(baseDir).gulp('--gulpfile x'), cb); + var opts = { cwd: baseDir }; + exec(gulp('--gulpfile x'), opts, cb); function cb(err, stdout, stderr) { expect(err).not.toBeNull(); @@ -26,7 +27,8 @@ describe('config: flag.logLevel', function() { }); it('Should output warn log', function(done) { - exec(cd(baseDir).gulp('--preload mymodule'), cb); + var opts = { cwd: baseDir }; + exec(gulp('--preload mymodule'), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -39,7 +41,8 @@ describe('config: flag.logLevel', function() { }); it('Should output info log', function(done) { - exec(cd(baseDir).gulp('--harmony'), cb); + var opts = { cwd: baseDir }; + exec(gulp('--harmony'), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -55,7 +58,8 @@ describe('config: flag.logLevel', function() { describe('log level 1 by config `flags.logLevel`', function() { it('Should output error log', function(done) { - exec(cd(baseDir).gulp('--gulpfile x'), cb); + var opts = { cwd: baseDir }; + exec(gulp('--gulpfile x'), opts, cb); function cb(err, stdout, stderr) { expect(err).not.toBeNull(); @@ -66,7 +70,8 @@ describe('config: flag.logLevel', function() { }); it('Should output warn log', function(done) { - exec(cd(baseDir, 'L').gulp('--preload mymodule'), cb); + var opts = { cwd: path.join(baseDir, 'L') }; + exec(gulp('--preload mymodule'), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -77,7 +82,8 @@ describe('config: flag.logLevel', function() { }); it('Should output info log', function(done) { - exec(cd(baseDir, 'L').gulp('--harmony'), cb); + var opts = { cwd: path.join(baseDir, 'L') }; + exec(gulp('--harmony'), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -90,7 +96,8 @@ describe('config: flag.logLevel', function() { describe('log level 2 by config `flags.logLevel`', function() { it('Should output error log', function(done) { - exec(cd(baseDir, 'LL').gulp('--gulpfile x'), cb); + var opts = { cwd: path.join(baseDir, 'LL') }; + exec(gulp('--gulpfile x'), opts, cb); function cb(err, stdout, stderr) { expect(err).not.toBeNull(); @@ -101,7 +108,8 @@ describe('config: flag.logLevel', function() { }); it('Should output warn log', function(done) { - exec(cd(baseDir, 'LL').gulp('--preload mymodule'), cb); + var opts = { cwd: path.join(baseDir, 'LL') }; + exec(gulp('--preload mymodule'), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -114,7 +122,8 @@ describe('config: flag.logLevel', function() { }); it('Should output info log', function(done) { - exec(cd(baseDir, 'LL').gulp('--harmony'), cb); + var opts = { cwd: path.join(baseDir, 'LL') }; + exec(gulp('--harmony'), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -127,7 +136,8 @@ describe('config: flag.logLevel', function() { describe('log level 3 by config `flags.logLevel`', function() { it('Should output error log', function(done) { - exec(cd(baseDir, 'LLL').gulp('--gulpfile x'), cb); + var opts = { cwd: path.join(baseDir, 'LLL') }; + exec(gulp('--gulpfile x'), opts, cb); function cb(err, stdout, stderr) { expect(err).not.toBeNull(); @@ -138,7 +148,8 @@ describe('config: flag.logLevel', function() { }); it('Should output warn log', function(done) { - exec(cd(baseDir, 'LLL').gulp('--preload mymodule'), cb); + var opts = { cwd: path.join(baseDir, 'LLL') }; + exec(gulp('--preload mymodule'), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -151,7 +162,8 @@ describe('config: flag.logLevel', function() { }); it('Should output info log', function(done) { - exec(cd(baseDir, 'LLL').gulp('--harmony'), cb); + var opts = { cwd: path.join(baseDir, 'LLL') }; + exec(gulp('--harmony'), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -166,7 +178,8 @@ describe('config: flag.logLevel', function() { describe('Overridden by cli flag: -L/-LL/-LLL', function() { it('Should not output info log by -L', function(done) { - exec(cd(baseDir, 'LLL').gulp('-L', '--preload mymodule'), cb); + var opts = { cwd: path.join(baseDir, 'LLL') }; + exec(gulp('-L', '--preload mymodule'), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -177,7 +190,8 @@ describe('config: flag.logLevel', function() { }); it('Should output info log by -LLL', function(done) { - exec(cd(baseDir, 'L').gulp('-LLL', '--harmony'), cb); + var opts = { cwd: path.join(baseDir, 'L') }; + exec(gulp('-LLL', '--harmony'), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); diff --git a/test/config-flags-node-flags.js b/test/config-flags-node-flags.js index 291841d5..eb9c00cb 100644 --- a/test/config-flags-node-flags.js +++ b/test/config-flags-node-flags.js @@ -5,14 +5,15 @@ var exec = require('child_process').exec; var path = require('path'); var sliceLines = require('./tool/slice-lines'); -var cd = require('./tool/gulp-cmd').cd; +var gulp = require('./tool/gulp-cmd'); var baseDir = path.join(__dirname, 'fixtures/config/flags/nodeFlags'); describe('config: nodeFlags', function() { it('Should respawn by a node flag: --lazy', function(done) { - exec(cd(baseDir, 'string').gulp(), cb); + var opts = { cwd: path.join(baseDir, 'string') }; + exec(gulp(), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -24,7 +25,8 @@ describe('config: nodeFlags', function() { }); it('Should respawn by a node flag: --lazy --trace-deprecation', function(done) { - exec(cd(baseDir, 'array').gulp(), cb); + var opts = { cwd: path.join(baseDir, 'array') }; + exec(gulp(), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -36,7 +38,8 @@ describe('config: nodeFlags', function() { }); it('Should respawn with flags in config file and command line', function(done) { - exec(cd(baseDir, 'string').gulp('--harmony'), cb); + var opts = { cwd: path.join(baseDir, 'string') }; + exec(gulp('--harmony'), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -48,7 +51,8 @@ describe('config: nodeFlags', function() { }); it('Should not respawn when a node flag is specified to undefined', function(done) { - exec(cd(baseDir, 'undefined').gulp(), cb); + var opts = { cwd: path.join(baseDir, 'undefined') }; + exec(gulp(), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -64,7 +68,8 @@ describe('config: nodeFlags', function() { }); it('Should not respawn when a node flag is specified to null', function(done) { - exec(cd(baseDir, 'null').gulp(), cb); + var opts = { cwd: path.join(baseDir, 'null') }; + exec(gulp(), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); diff --git a/test/config-flags-preload.js b/test/config-flags-preload.js index 2321cd22..47942363 100644 --- a/test/config-flags-preload.js +++ b/test/config-flags-preload.js @@ -5,14 +5,15 @@ var exec = require('child_process').exec; var path = require('path'); var sliceLines = require('./tool/slice-lines'); -var cd = require('./tool/gulp-cmd').cd; +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) { - exec(cd(baseDir, 'array').gulp(), cb); + var opts = { cwd: path.join(baseDir, 'array') }; + exec(gulp(), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -28,7 +29,8 @@ describe('config: flags.preload', function() { }); it('Should configure with a string in a .gulp.* file', function(done) { - exec(cd(baseDir, 'string').gulp(), cb); + var opts = { cwd: path.join(baseDir, 'string') }; + exec(gulp(), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -41,7 +43,8 @@ describe('config: flags.preload', function() { }); it('Combines --preload flag with .gulp.* file flags.preload', function(done) { - exec(cd(baseDir, 'join-flags').gulp('--preload ./preload_one'), cb); + var opts = { cwd: path.join(baseDir, 'join-flags') }; + exec(gulp('--preload ./preload_one'), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -57,7 +60,8 @@ describe('config: flags.preload', function() { }); it('resolves relative requires against cwd', function(done) { - exec(cd(__dirname, 'fixtures/config').gulp('--cwd flags/preload/with-cwd'), cb); + 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(); @@ -70,7 +74,8 @@ describe('config: flags.preload', function() { }); it('works with absolute paths, ignoring cwd', function(done) { - exec(cd(__dirname, 'fixtures/config').gulp('--cwd flags/preload/with-absolute'), cb); + 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(); diff --git a/test/config-flags-series.js b/test/config-flags-series.js index a16752b9..b298322a 100644 --- a/test/config-flags-series.js +++ b/test/config-flags-series.js @@ -5,14 +5,15 @@ var exec = require('child_process').exec; var path = require('path'); var sliceLines = require('./tool/slice-lines'); -var cd = require('./tool/gulp-cmd').cd; +var gulp = require('./tool/gulp-cmd'); 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) { - exec(cd(baseDir, 't').gulp('task1', 'task2'), cb); + var opts = { cwd: path.join(baseDir, 't') }; + exec(gulp('task1', 'task2'), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -29,7 +30,8 @@ describe('config: flags.series', function() { }); it('Should run in parallel if `flags.series` is false in .gulp.*', function(done) { - exec(cd(baseDir, 'f').gulp('task1', 'task2'), cb); + var opts = { cwd: path.join(baseDir, 'f') }; + exec(gulp('task1', 'task2'), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -46,7 +48,8 @@ describe('config: flags.series', function() { }); it('Should overridden by cli flag: --series', function(done) { - exec(cd(baseDir, 'f').gulp('--series', 'task1', 'task2'), cb); + var opts = { cwd: path.join(baseDir, 'f') }; + exec(gulp('--series', 'task1', 'task2'), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -63,7 +66,8 @@ describe('config: flags.series', function() { }); it('Should overridden by cli flag: --no-series', function(done) { - exec(cd(baseDir, 't').gulp('--no-series', 'task1', 'task2'), cb); + var opts = { cwd: path.join(baseDir, 't') }; + exec(gulp('--no-series', 'task1', 'task2'), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); diff --git a/test/config-flags-silent.js b/test/config-flags-silent.js index 04bf7c1f..527bbc8f 100644 --- a/test/config-flags-silent.js +++ b/test/config-flags-silent.js @@ -5,14 +5,15 @@ var exec = require('child_process').exec; var path = require('path'); var sliceLines = require('./tool/slice-lines'); -var cd = require('./tool/gulp-cmd').cd; +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) { - exec(cd(baseDir, 't').gulp(), cb); + var opts = { cwd: path.join(baseDir, 't') }; + exec(gulp(), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -23,7 +24,8 @@ describe('config: flags.silent', function() { }); it('Should not be silent if `flags.silent` is false in .gulp.*', function(done) { - exec(cd(baseDir, 'f').gulp(), cb); + var opts = { cwd: path.join(baseDir, 'f') }; + exec(gulp(), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -38,7 +40,8 @@ describe('config: flags.silent', function() { }); it('Should overridden by cli flag: --silent', function(done) { - exec(cd(baseDir, 'f').gulp('--silent'), cb); + var opts = { cwd: path.join(baseDir, 'f') }; + exec(gulp('--silent'), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -49,7 +52,8 @@ describe('config: flags.silent', function() { }); it('Should overridden by cli flag: --no-silent', function(done) { - exec(cd(baseDir, 't').gulp('--no-silent'), cb); + var opts = { cwd: path.join(baseDir, 't') }; + exec(gulp('--no-silent'), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); diff --git a/test/config-flags-sort-tasks.js b/test/config-flags-sort-tasks.js index 4f1ae0ad..01eada8d 100644 --- a/test/config-flags-sort-tasks.js +++ b/test/config-flags-sort-tasks.js @@ -6,7 +6,7 @@ var path = require('path'); var fs = require('fs'); var sliceLines = require('./tool/slice-lines'); -var cd = require('./tool/gulp-cmd').cd; +var gulp = require('./tool/gulp-cmd'); var baseDir = path.join(__dirname, 'fixtures/config/flags/sortTasks'); var expectedDir = path.join(__dirname, 'expected'); @@ -14,7 +14,8 @@ var expectedDir = path.join(__dirname, 'expected'); describe('config: flags.sortTasks', function() { it('Should sort top tasks in task list when `flags.sortTasks` is true in .gulp.*', function(done) { - exec(cd(baseDir, 't').gulp('--tasks'), cb); + 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'); @@ -26,7 +27,8 @@ describe('config: flags.sortTasks', function() { }); it('Should sort top tasks in task list when `flags.sortTasks` is false in .gulp.*', function(done) { - exec(cd(baseDir, 'f').gulp('--tasks'), cb); + 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'); @@ -38,7 +40,8 @@ describe('config: flags.sortTasks', function() { }); it('Should overridden by cli flag: --sort-tasks', function(done) { - exec(cd(baseDir, 'f').gulp('--tasks', '--sort-tasks'), 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'); @@ -50,7 +53,8 @@ describe('config: flags.sortTasks', function() { }); it('Should overridden by cli flag: --no-sort-tasks', function(done) { - exec(cd(baseDir, 't').gulp('--tasks', '--no-sort-tasks'), 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'); diff --git a/test/config-flags-tasks-depth.js b/test/config-flags-tasks-depth.js index a7ee31c7..944766c2 100644 --- a/test/config-flags-tasks-depth.js +++ b/test/config-flags-tasks-depth.js @@ -6,7 +6,7 @@ var path = require('path'); var fs = require('fs'); var sliceLines = require('./tool/slice-lines'); -var cd = require('./tool/gulp-cmd').cd; +var gulp = require('./tool/gulp-cmd'); var baseDir = path.join(__dirname, 'fixtures/config/flags/tasksDepth'); var expectedDir = path.join(__dirname, 'expected'); @@ -14,7 +14,8 @@ 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) { - exec(cd(baseDir).gulp('--tasks'), cb); + var opts = { cwd: baseDir }; + exec(gulp('--tasks'), opts, cb); function cb(err, stdout, stderr) { var filepath = path.join(expectedDir, 'flags-tasks-depth4.txt'); @@ -26,7 +27,8 @@ describe('config: flags.tasksDepth', function() { }); it('Should overridden by cli flag: --tasks-depth', function(done) { - exec(cd(baseDir).gulp('--tasks', '--tasks-depth', '2'), cb); + 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'); diff --git a/test/esm.js b/test/esm.js index 93472f2a..52affdab 100644 --- a/test/esm.js +++ b/test/esm.js @@ -9,7 +9,7 @@ var os = require('os'); var baseDir = path.join(__dirname, '..'); var sliceLines = require('./tool/slice-lines'); -var cd = require('./tool/gulp-cmd').cd; +var gulp = require('./tool/gulp-cmd'); var expectedDir = path.join(__dirname, 'expected'); @@ -43,7 +43,8 @@ describe('ESM', function() { trailingLines += 2; } - exec(cd(baseDir).gulp(options), cb); + var opts = { cwd: baseDir }; + exec(gulp(options), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); diff --git a/test/execution-errors.js b/test/execution-errors.js index 25277bd9..35027883 100644 --- a/test/execution-errors.js +++ b/test/execution-errors.js @@ -10,12 +10,13 @@ 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 cd = require('./tool/gulp-cmd').cd; +var gulp = require('./tool/gulp-cmd'); describe('execution error', function() { it('should output an error if a task is not defined', function(done) { - exec(cd(__dirname, './fixtures/gulpfiles').gulp('a'), cb); + var opts = { cwd: path.join(__dirname, './fixtures/gulpfiles') }; + exec(gulp('a'), opts, cb); function cb(err, stdout, stderr) { expect(err).not.toBeNull(); @@ -29,7 +30,8 @@ describe('execution error', function() { }); it('should output an error if gulp version is unsupported', function(done) { - exec(cd(__dirname, './fixtures/errors/bad-gulp-version').gulp(), cb); + var opts = { cwd: path.join(__dirname, './fixtures/errors/bad-gulp-version') }; + exec(gulp(), opts, cb); function cb(err, stdout, stderr) { expect(err).not.toBeNull(); @@ -43,10 +45,10 @@ describe('execution error', function() { it('should output an error if gulp is not found', function(done) { var tmpdir = os.tmpdir(); if (os.platform() === 'win32') { - var moveDrive = tmpdir.slice(0, 2) + '&'; - exec(moveDrive + cd(tmpdir).gulp(), cb); + var moveDrive = tmpdir.slice(0, 2); + exec(moveDrive + '& cd ' + tmpdir + ' & ' + gulp(), cb); } else { - exec(cd(tmpdir).gulp(), cb); + exec(gulp(), { cwd: tmpdir }, cb); } function cb(err, stdout, stderr) { @@ -62,9 +64,9 @@ describe('execution error', function() { var dir = path.join(__dirname, 'fixtures/gulpfiles'); var gulpfileName = 'gulpfile-dedup-errorlog.js'; - exec(cd(dir).gulp( + exec(gulp( '--gulpfile', gulpfileName - ), cb); + ), { cwd: dir }, cb); function cb(err, stdout, stderr) { expect(err).not.toBeNull(); diff --git a/test/exports-as-tasks.js b/test/exports-as-tasks.js index 167f40e1..81bee75e 100644 --- a/test/exports-as-tasks.js +++ b/test/exports-as-tasks.js @@ -6,7 +6,7 @@ var fs = require('fs'); var path = require('path'); var sliceLines = require('./tool/slice-lines'); -var cd = require('./tool/gulp-cmd').cd; +var gulp = require('./tool/gulp-cmd'); var baseDir = path.join(__dirname, '..'); var expectedDir = path.join(__dirname, 'expected'); @@ -16,11 +16,12 @@ describe('exports as tasks', function() { this.timeout(0); it('prints the task list', function(done) { - exec(cd(baseDir).gulp( + var opts = { cwd: baseDir }; + exec(gulp( '--tasks', '--sort-tasks', '--gulpfile', './test/fixtures/gulpfiles/gulpfile-exports.babel.js' - ), cb); + ), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); diff --git a/test/flags-continue.js b/test/flags-continue.js index de84d4b2..cbf8a94f 100644 --- a/test/flags-continue.js +++ b/test/flags-continue.js @@ -5,18 +5,19 @@ var exec = require('child_process').exec; var path = require('path'); var sliceLines = require('./tool/slice-lines'); -var cd = require('./tool/gulp-cmd').cd; +var gulp = require('./tool/gulp-cmd'); var baseDir = path.join(__dirname, '..'); describe('flag: --continue', function() { it('continues execution when flag is set', function(done) { - exec(cd(baseDir).gulp( + var opts = { cwd: baseDir }; + exec(gulp( 'test4', '--continue', '--cwd ./test/fixtures/gulpfiles' - ), cb); + ), opts, cb); function cb(err, stdout, stderr) { expect(err).not.toBeNull(); @@ -36,7 +37,8 @@ describe('flag: --continue', function() { }); it('stops execution when flag is not set', function(done) { - exec(cd(baseDir).gulp('test4', '--cwd ./test/fixtures/gulpfiles'), cb); + var opts = { cwd: baseDir }; + exec(gulp('test4', '--cwd ./test/fixtures/gulpfiles'), opts, cb); function cb(err, stdout, stderr) { expect(err).not.toBeNull(); diff --git a/test/flags-gulpfile.js b/test/flags-gulpfile.js index 274f0063..7c9316b7 100644 --- a/test/flags-gulpfile.js +++ b/test/flags-gulpfile.js @@ -5,7 +5,7 @@ var exec = require('child_process').exec; var path = require('path'); var sliceLines = require('./tool/slice-lines'); -var cd = require('./tool/gulp-cmd').cd; +var gulp = require('./tool/gulp-cmd'); var baseDir = path.join(__dirname, '..'); @@ -14,7 +14,8 @@ describe('flag: --gulpfile', function() { it('Manually set path of gulpfile using --gulpfile', function(done) { var gulpfilePath = 'test/fixtures/gulpfiles/gulpfile-2.js'; - exec(cd(baseDir).gulp('--gulpfile', gulpfilePath), cb); + var opts = { cwd: baseDir }; + exec(gulp('--gulpfile', gulpfilePath), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -41,7 +42,8 @@ describe('flag: --gulpfile', function() { it('Manually set path of gulpfile using -f', function(done) { var gulpfilePath = 'test/fixtures/gulpfiles/gulpfile-2.js'; - exec(cd(baseDir).gulp('-f', gulpfilePath), cb); + var opts = { cwd: baseDir }; + exec(gulp('-f', gulpfilePath), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); diff --git a/test/flags-help.js b/test/flags-help.js index 629ca0cc..b1947b41 100644 --- a/test/flags-help.js +++ b/test/flags-help.js @@ -5,7 +5,7 @@ var exec = require('child_process').exec; var path = require('path'); var fs = require('fs'); -var cd = require('./tool/gulp-cmd').cd; +var gulp = require('./tool/gulp-cmd'); var baseDir = path.join(__dirname, '..'); var outputFile = path.join(__dirname, 'expected/flags-help.txt'); @@ -14,10 +14,11 @@ var outputText = fs.readFileSync(outputFile, 'utf8'); describe('flag: --help', function() { it('shows help using --help', function(done) { - exec(cd(baseDir).gulp( + var opts = { cwd: baseDir }; + exec(gulp( '--help', '--cwd ./test/fixtures/gulpfiles' - ), cb); + ), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -28,10 +29,11 @@ describe('flag: --help', function() { }); it('shows help using short --h', function(done) { - exec(cd(baseDir).gulp( + var opts = { cwd: baseDir }; + exec(gulp( '--h', '--cwd ./test/fixtures/gulpfiles' - ), cb); + ), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -42,10 +44,11 @@ describe('flag: --help', function() { }); it('avoids printing "Requiring external module *"', function(done) { - exec(cd(baseDir).gulp( + var opts = { cwd: baseDir }; + exec(gulp( '--help', '--gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js' - ), cb); + ), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); diff --git a/test/flags-preload.js b/test/flags-preload.js index 87a9048e..8a666ddc 100644 --- a/test/flags-preload.js +++ b/test/flags-preload.js @@ -7,17 +7,18 @@ var path = require('path'); var sliceLines = require('./tool/slice-lines'); var eraseTime = require('./tool/erase-time'); var eraseLapse = require('./tool/erase-lapse'); -var cd = require('./tool/gulp-cmd').cd; +var gulp = require('./tool/gulp-cmd'); var baseDir = path.join(__dirname, '..'); describe('flag: --preload', function() { it('preloads module before running gulpfile', function(done) { - exec(cd(baseDir).gulp( + var opts = { cwd: baseDir }; + exec(gulp( '--preload ../test-module.js', '--cwd ./test/fixtures/gulpfiles' - ), cb); + ), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -52,11 +53,12 @@ describe('flag: --preload', function() { }); it('can preload multiple modules before running gulpfile', function(done) { - exec(cd(baseDir).gulp( + var opts = { cwd: baseDir }; + exec(gulp( '--preload ../test-module.js', '--preload ../test-module-2.js', '--cwd ./test/fixtures/gulpfiles' - ), cb); + ), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -72,10 +74,11 @@ describe('flag: --preload', function() { }); it('warns if module doesn\'t exist', function(done) { - exec(cd(baseDir).gulp( + var opts = { cwd: baseDir }; + exec(gulp( '--preload ./null-module.js', '--cwd ./test/fixtures/gulpfiles' - ), cb); + ), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -112,10 +115,11 @@ describe('flag: --preload', function() { }); it('warns if module throw some error', function(done) { - exec(cd(baseDir).gulp( + var opts = { cwd: baseDir }; + exec(gulp( '--preload ../test-error-module.js', '--cwd ./test/fixtures/gulpfiles' - ), cb); + ), opts, cb); function cb(err, stdout, stderr) { stdout = eraseLapse(eraseTime(stdout)); diff --git a/test/flags-series.js b/test/flags-series.js index 50c38167..b4ba6047 100644 --- a/test/flags-series.js +++ b/test/flags-series.js @@ -5,18 +5,19 @@ var exec = require('child_process').exec; var path = require('path'); var sliceLines = require('./tool/slice-lines'); -var cd = require('./tool/gulp-cmd').cd; +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) { - exec(cd(baseDir).gulp( + var opts = { cwd: baseDir }; + exec(gulp( 'test5 test6', '--series', '--cwd ./test/fixtures/gulpfiles' - ), cb); + ), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -33,10 +34,11 @@ describe('flag: --series', function() { }); it('runs tasks in parallel when flag is not set', function(done) { - exec(cd(baseDir).gulp( + var opts = { cwd: baseDir }; + exec(gulp( 'test5 test6', '--cwd ./test/fixtures/gulpfiles' - ), cb); + ), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); diff --git a/test/flags-silent.js b/test/flags-silent.js index d4b33cc4..c7bc12b0 100644 --- a/test/flags-silent.js +++ b/test/flags-silent.js @@ -4,17 +4,18 @@ var expect = require('expect'); var exec = require('child_process').exec; var path = require('path'); -var cd = require('./tool/gulp-cmd').cd; +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) { - exec(cd(baseDir).gulp( + var opts = { cwd: baseDir }; + exec(gulp( '--silent', '--cwd ./test/fixtures/gulpfiles' - ), cb); + ), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); diff --git a/test/flags-tasks-json.js b/test/flags-tasks-json.js index ae70e36e..5614ac33 100644 --- a/test/flags-tasks-json.js +++ b/test/flags-tasks-json.js @@ -6,7 +6,7 @@ var fs = require('fs'); var path = require('path'); var rimraf = require('rimraf'); -var cd = require('./tool/gulp-cmd').cd; +var gulp = require('./tool/gulp-cmd'); var baseDir = path.join(__dirname, '..'); var expected = require(path.join(__dirname, 'expected/flags-tasks-json.json')); @@ -14,10 +14,11 @@ 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) { - exec(cd(baseDir).gulp( + var opts = { cwd: baseDir }; + exec(gulp( '--tasks-json', '--gulpfile ./test/fixtures/gulpfiles/gulpfile.js' - ), cb); + ), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -31,11 +32,12 @@ describe('flag: --tasks-json', function() { var cwdPath = __dirname; var gulpfilePath = path.join(__dirname, 'fixtures/gulpfiles/gulpfile.js'); - exec(cd(baseDir).gulp( + var opts = { cwd: baseDir }; + exec(gulp( '--tasks-json', '--cwd ', cwdPath, '--gulpfile ', gulpfilePath - ), cb); + ), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -52,10 +54,11 @@ describe('flag: --tasks-json', function() { rimraf.sync(output); fs.mkdirSync(output); - exec(cd(baseDir).gulp( + var opts = { cwd: baseDir }; + exec(gulp( '--tasks-json ../../output/tasks.json', '--gulpfile ./test/fixtures/gulpfiles/gulpfile.js' - ), cb); + ), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -74,10 +77,11 @@ describe('flag: --tasks-json', function() { // Disable the timeout for old node versions this.timeout(0); - exec(cd(baseDir).gulp( + var opts = { cwd: baseDir }; + exec(gulp( '--tasks-json', '--gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js' - ), cb); + ), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); diff --git a/test/flags-tasks-simple.js b/test/flags-tasks-simple.js index 6297b264..a2f54c22 100644 --- a/test/flags-tasks-simple.js +++ b/test/flags-tasks-simple.js @@ -5,7 +5,7 @@ var exec = require('child_process').exec; var path = require('path'); var fs = require('fs'); -var cd = require('./tool/gulp-cmd').cd; +var gulp = require('./tool/gulp-cmd'); var baseDir = path.join(__dirname, '..'); var outputFile = path.join(__dirname, 'expected/flags-tasks-simple.txt'); @@ -14,10 +14,11 @@ var outputText = fs.readFileSync(outputFile, 'utf8'); describe('flag: --tasks-simple', function() { it('prints the task list in simple format', function(done) { - exec(cd(baseDir).gulp( + var opts = { cwd: baseDir }; + exec(gulp( '--tasks-simple', '--cwd ./test/fixtures/gulpfiles' - ), cb); + ), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -31,10 +32,11 @@ describe('flag: --tasks-simple', function() { // Disable the timeout for old node versions this.timeout(0); - exec(cd(baseDir).gulp( + var opts = { cwd: baseDir }; + exec(gulp( '--tasks-simple', '--gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js' - ), cb); + ), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); diff --git a/test/flags-tasks.js b/test/flags-tasks.js index f2978de3..4a1c689f 100644 --- a/test/flags-tasks.js +++ b/test/flags-tasks.js @@ -6,7 +6,7 @@ var fs = require('fs'); var path = require('path'); var sliceLines = require('./tool/slice-lines'); -var cd = require('./tool/gulp-cmd').cd; +var gulp = require('./tool/gulp-cmd'); var baseDir = path.join(__dirname, '..'); var expectedDir = path.join(__dirname, 'expected'); @@ -14,11 +14,12 @@ var expectedDir = path.join(__dirname, 'expected'); describe('flag: --tasks', function() { it('prints the task list', function(done) { - exec(cd(baseDir).gulp( + var opts = { cwd: baseDir }; + exec(gulp( '--tasks', '--sort-tasks', '--cwd ./test/fixtures/gulpfiles' - ), cb); + ), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -31,12 +32,13 @@ describe('flag: --tasks', function() { }); it('print the task list with description and flags', function(done) { - exec(cd(baseDir).gulp( + var opts = { cwd: baseDir }; + exec(gulp( '--tasks', '--sort-tasks', '--gulpfile ./test/fixtures/gulpfiles/with-desc-and-flags.js', '--cwd ./test/fixtures' - ), cb); + ), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -49,12 +51,13 @@ describe('flag: --tasks', function() { }); it('print the task list by gulp.task(s).unwrap and gulp.task(s)', function(done) { - exec(cd(baseDir).gulp( + var opts = { cwd: baseDir }; + exec(gulp( '--tasks', '--sort-tasks', '--gulpfile ./test/fixtures/gulpfiles/by-unwrap-and-not-by-unwrap.js', '--cwd ./test/fixtures' - ), cb); + ), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -67,10 +70,11 @@ describe('flag: --tasks', function() { }); it('prints the task list without --sort-tasks flag', function(done) { - exec(cd(baseDir).gulp( + var opts = { cwd: baseDir }; + exec(gulp( '--tasks', '--gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js' - ), cb); + ), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -83,11 +87,12 @@ describe('flag: --tasks', function() { }); it('prints the task list with --sort-tasks flag', function(done) { - exec(cd(baseDir).gulp( + var opts = { cwd: baseDir }; + exec(gulp( '--tasks', '--gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', '--sort-tasks' - ), cb); + ), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -100,11 +105,12 @@ describe('flag: --tasks', function() { }); it('prints the task list with --tasks-depth flag', function(done) { - exec(cd(baseDir).gulp( + var opts = { cwd: baseDir }; + exec(gulp( '--tasks', '--gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', '--tasks-depth 4' - ), cb); + ), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -117,11 +123,12 @@ describe('flag: --tasks', function() { }); it('prints the task list with --depth flag', function(done) { - exec(cd(baseDir).gulp( + var opts = { cwd: baseDir }; + exec(gulp( '--tasks', '--gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', '--depth 4' - ), cb); + ), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -134,11 +141,12 @@ describe('flag: --tasks', function() { }); it('prints the task list with --compact-tasks flag', function(done) { - exec(cd(baseDir).gulp( + var opts = { cwd: baseDir }; + exec(gulp( '--tasks', '--gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js', '--compact-tasks' - ), cb); + ), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); diff --git a/test/flags-v8flags.js b/test/flags-v8flags.js index 684424fa..30dec323 100644 --- a/test/flags-v8flags.js +++ b/test/flags-v8flags.js @@ -5,14 +5,15 @@ var exec = require('child_process').exec; var path = require('path'); var sliceLines = require('./tool/slice-lines'); -var cd = require('./tool/gulp-cmd').cd; +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) { - exec(cd(baseDir).gulp('--lazy'), cb); + var opts = { cwd: baseDir }; + exec(gulp('--lazy'), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -24,7 +25,8 @@ describe('flags: v8flags', function() { }); it('Should respawn by v8flags: --lazy --harmony', function(done) { - exec(cd(baseDir).gulp('--lazy --harmony'), cb); + var opts = { cwd: baseDir }; + exec(gulp('--lazy --harmony'), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); diff --git a/test/flags-verify.js b/test/flags-verify.js index e3aa15a4..b3b6f53c 100644 --- a/test/flags-verify.js +++ b/test/flags-verify.js @@ -5,17 +5,18 @@ var exec = require('child_process').exec; var path = require('path'); var eraseTime = require('./tool/erase-time'); -var cd = require('./tool/gulp-cmd').cd; +var gulp = require('./tool/gulp-cmd'); var baseDir = path.join(__dirname, '..'); describe('flag: --verify', function() { it('dependencies with invalid dependency', function(done) { - exec(cd(baseDir).gulp( + var opts = { cwd: baseDir }; + exec(gulp( '--verify invalid-package.json', '--cwd ./test/fixtures/verify/' - ), cb); + ), opts, cb); function cb(err, stdout, stderr) { expect(err).not.toBeNull(); @@ -31,10 +32,11 @@ describe('flag: --verify', function() { }); it('dependencies with valid dependency', function(done) { - exec(cd(baseDir).gulp( + var opts = { cwd: baseDir }; + exec(gulp( '--verify valid-package.json', '--cwd ./test/fixtures/verify/' - ), cb); + ), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -49,10 +51,11 @@ describe('flag: --verify', function() { }); it('default args with invalid dependency', function(done) { - exec(cd(baseDir).gulp( + var opts = { cwd: baseDir }; + exec(gulp( '--verify', '--cwd', path.resolve('./test/fixtures/verify/') - ), cb); + ), opts, cb); function cb(err, stdout, stderr) { expect(err).not.toBeNull(); diff --git a/test/flags-version.js b/test/flags-version.js index 41bec492..75105570 100644 --- a/test/flags-version.js +++ b/test/flags-version.js @@ -5,7 +5,7 @@ var exec = require('child_process').exec; var path = require('path'); var os = require('os'); -var cd = require('./tool/gulp-cmd').cd; +var gulp = require('./tool/gulp-cmd'); var cliVersion = require('../package.json').version; var gulpVersion = require('gulp/package.json').version; @@ -14,10 +14,11 @@ var baseDir = path.join(__dirname, '..'); describe('flag: --version', function() { it('prints the version of CLI and local gulp', function(done) { - exec(cd(baseDir).gulp( + var opts = { cwd: baseDir }; + exec(gulp( '--version', '--cwd ./test/fixtures/gulpfiles' - ), cb); + ), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -32,10 +33,11 @@ describe('flag: --version', function() { }); it('avoids printing "Requiring external module *"', function(done) { - exec(cd(baseDir).gulp( + var opts = { cwd: baseDir }; + exec(gulp( '--version', '--gulpfile ./test/fixtures/gulpfiles/gulpfile-babel.babel.js' - ), cb); + ), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); @@ -50,7 +52,8 @@ describe('flag: --version', function() { }); it('should print only CLI version when gulp is not found', function(done) { - exec(cd(baseDir).gulp('--version', '--cwd', os.tmpdir()), cb); + var opts = { cwd: baseDir }; + exec(gulp('--version', '--cwd', os.tmpdir()), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); diff --git a/test/sync-task.js b/test/sync-task.js index a60798ef..8f1bf677 100644 --- a/test/sync-task.js +++ b/test/sync-task.js @@ -2,13 +2,15 @@ var expect = require('expect'); var exec = require('child_process').exec; +var path = require('path'); var sliceLines = require('./tool/slice-lines'); -var cd = require('./tool/gulp-cmd').cd; +var gulp = require('./tool/gulp-cmd'); describe('sync-task', function() { it('should return error code 1 if any tasks did not complete', function(done) { - exec(cd(__dirname, 'fixtures/gulpfiles').gulp('test6 test7 test8'), cb); + var opts = { cwd: path.join(__dirname, 'fixtures/gulpfiles') }; + exec(gulp('test6 test7 test8'), opts, cb); function cb(err) { expect(err).not.toBeNull(); @@ -18,7 +20,8 @@ describe('sync-task', function() { }); it('should log tasks which did not complete', function(done) { - exec(cd(__dirname, 'fixtures/gulpfiles').gulp('test6 test7 test8'), cb); + 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( @@ -30,9 +33,10 @@ describe('sync-task', function() { }); it('should not log false positive in case of parallel failure', function(done) { - exec(cd(__dirname, '..').gulp( + var opts = { cwd: path.join(__dirname, '..') }; + exec(gulp( '--gulpfile ./test/fixtures/gulpfiles/gulpfile-parallel-failure.js' - ), cb); + ), opts, cb); function cb(err, stdout) { expect(stdout).not.toMatch('The following tasks did not complete:'); @@ -41,9 +45,10 @@ describe('sync-task', function() { }); it('should not log false positive in case of parallel failure in continue mode', function(done) { - exec(cd(__dirname, '..').gulp( + var opts = { cwd: path.join(__dirname, '..') }; + exec(gulp( '--gulpfile ./test/fixtures/gulpfiles/gulpfile-parallel-failure.js' - ), cb); + ), opts, cb); function cb(err, stdout) { expect(stdout).not.toMatch('The following tasks did not complete:'); @@ -52,11 +57,12 @@ describe('sync-task', function() { }); it('should log non-completing task alongside a failure in continue mode', function(done) { - exec(cd(__dirname, '..').gulp( + var opts = { cwd: path.join(__dirname, '..') }; + exec(gulp( '--continue', '--gulpfile ./test/fixtures/gulpfiles/gulpfile-parallel-failure.js', 'broken' - ), cb); + ), opts, cb); function cb(err, stdout) { expect(stdout).toMatch('The following tasks did not complete: broken, notCompleting1\n'); diff --git a/test/tool/gulp-cmd.js b/test/tool/gulp-cmd.js index d7faf0a1..87540be1 100644 --- a/test/tool/gulp-cmd.js +++ b/test/tool/gulp-cmd.js @@ -1,10 +1,7 @@ 'use strict'; -var os = require('os'); var path = require('path'); -var cmdSep = os.platform() === 'win32' ? '& ' : '; '; - function gulp(/* ... */) { var arr = Array.prototype.slice.apply(arguments); arr.unshift('node ' + path.join(__dirname, '../../bin/gulp.js')); @@ -16,17 +13,4 @@ gulp.debug = function(/* ... */) { return s; } -function cd(/* ... */) { - var cd = 'cd ' + path.join.apply(null, arguments) + cmdSep; - var g = function(/* ... */) { - return cd + gulp.apply(null, arguments); - }; - g.debug = function(/* ... */) { - var s = g.apply(null, arguments); - console.log(s); - return s; - }; - return { gulp: g }; -} - -module.exports = { cd: cd, gulp: gulp }; +module.exports = gulp; From ff6fad2441cf995e5af5b8b15523a693d4d32748 Mon Sep 17 00:00:00 2001 From: sttk Date: Sat, 6 Jan 2024 19:19:37 +0900 Subject: [PATCH 34/35] fix: modify test cases for flags.gulpfile config --- test/config-flags-gulpfile.js | 65 ++++++++++++++----- .../fixtures/config/flags/gulpfile/.gulp.json | 5 -- .../config/flags/gulpfile/cwd/.gulp.json | 5 ++ .../config/flags/gulpfile/cwd/findup/.gitkeep | 0 .../config/flags/gulpfile/cwd/gulpfile.js | 8 --- .../{mygulpfile.js => gulpfile-by-cwd-cfg.js} | 0 .../gulpfile/is/here/gulpfile-by-prj-cfg.js | 9 +++ .../config/flags/gulpfile/is/here/gulpfile.js | 9 +++ .../config/flags/gulpfile/prj/.gulp.json | 5 ++ .../config/flags/gulpfile/prj/findup/.gitkeep | 0 10 files changed, 77 insertions(+), 29 deletions(-) delete mode 100644 test/fixtures/config/flags/gulpfile/.gulp.json create mode 100644 test/fixtures/config/flags/gulpfile/cwd/.gulp.json create mode 100644 test/fixtures/config/flags/gulpfile/cwd/findup/.gitkeep delete mode 100644 test/fixtures/config/flags/gulpfile/cwd/gulpfile.js rename test/fixtures/config/flags/gulpfile/is/here/{mygulpfile.js => gulpfile-by-cwd-cfg.js} (100%) create mode 100644 test/fixtures/config/flags/gulpfile/is/here/gulpfile-by-prj-cfg.js create mode 100644 test/fixtures/config/flags/gulpfile/is/here/gulpfile.js create mode 100644 test/fixtures/config/flags/gulpfile/prj/.gulp.json create mode 100644 test/fixtures/config/flags/gulpfile/prj/findup/.gitkeep diff --git a/test/config-flags-gulpfile.js b/test/config-flags-gulpfile.js index 5cf6d819..329043d4 100644 --- a/test/config-flags-gulpfile.js +++ b/test/config-flags-gulpfile.js @@ -8,62 +8,95 @@ 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) { - var opts = { cwd: baseDir }; + var opts = { cwd: prjDir }; exec(gulp(), opts, cb); function cb(err, stdout, stderr) { expect(err).toBeNull(); expect(stderr).toEqual(''); expect(sliceLines(stdout, 2, 4)).toEqual( - 'This gulpfile : ' + path.join(baseDir, 'is/here/mygulpfile.js') + '\n' + - 'The current directory : ' + baseDir + '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 --cwd', function(done) { - var opts = { cwd: path.join(__dirname, 'fixtures/config') }; - exec(gulp('--cwd ./flags/gulpfile'), opts, cb); + var opts = { cwd: prjDir }; + exec(gulp('--cwd ../cwd'), 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/mygulpfile.js') + '\n' + - 'The current directory : ' + baseDir + 'This gulpfile : ' + path.join(baseDir, 'is/here/gulpfile-by-cwd-cfg.js') + '\n' + + 'The current directory : ' + path.join(baseDir, 'cwd') ); done(err); } }); - it('Should load a ./gulp.* file in a directory specified by --cwd', function(done) { - var opts = { cwd: baseDir }; - exec(gulp('--cwd ./cwd'), opts, 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).toBeNull(); + expect(stderr).toEqual(''); + 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 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).toBeNull(); expect(stderr).toEqual(''); - expect(sliceLines(stdout, 3, 4)).toEqual( - 'This gulpfile : ' + path.join(baseDir, 'is/here/mygulpfile.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: baseDir }; - exec(gulp('--gulpfile ./cwd/gulpfile.js'), opts, cb); + 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, 4)).toEqual( - 'Another gulpfile : ' + path.join(baseDir, 'cwd/gulpfile.js') + 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); } 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/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 From e66899b901ba614d3d2cead1cf83b8f54539fe38 Mon Sep 17 00:00:00 2001 From: sttk Date: Sat, 6 Jan 2024 21:35:57 +0900 Subject: [PATCH 35/35] update: remove micromatch --- lib/shared/verify-dependencies.js | 8 +++++--- package.json | 1 - 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/shared/verify-dependencies.js b/lib/shared/verify-dependencies.js index 93ea4d53..2dbe9b7a 100644 --- a/lib/shared/verify-dependencies.js +++ b/lib/shared/verify-dependencies.js @@ -1,7 +1,5 @@ 'use strict'; -var micromatch = require('micromatch'); - /** * Given a collection of plugin names verifies this collection against * the blacklist. Returns an object with: @@ -20,13 +18,17 @@ function verifyDependencies(pkg, blacklist) { return res.concat(Object.keys(pkg[prop] || {})); }, []); - var blacklisted = micromatch(pluginNames, Object.keys(blacklist)) + 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/package.json b/package.json index bb4862ce..47ff7595 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,6 @@ "gulplog": "^2.0.1", "interpret": "^3.1.1", "liftoff": "^4.0.0", - "micromatch": "^4.0.5", "mute-stdout": "^2.0.0", "replace-homedir": "^2.0.0", "semver-greatest-satisfied-range": "^2.0.0",