diff --git a/bin/main.js b/bin/main.js index ecc43d9..fc3ff3d 100644 --- a/bin/main.js +++ b/bin/main.js @@ -5,9 +5,6 @@ */ 'use strict' -// TODO: remove. -/* eslint-disable no-process-exit, no-process-env */ - // ------------------------------------------------------------------------------ // Requirements // ------------------------------------------------------------------------------ @@ -182,5 +179,3 @@ module.exports = function main (source, outDir, args) { }) } } - -/* eslint-enable no-process-exit, no-process-env */ diff --git a/lib/copy-sync.js b/lib/copy-sync.js index 8705ac2..9cf091f 100644 --- a/lib/copy-sync.js +++ b/lib/copy-sync.js @@ -46,7 +46,7 @@ module.exports = function copySync (source, outputDir, options) { ) } - options = normalizeOptions(source, outputDir, options) // eslint-disable-line no-param-reassign + options = normalizeOptions(source, outputDir, options) // Clean let cleaned = [] diff --git a/lib/copy.js b/lib/copy.js index 1f6d1b2..ece1a86 100644 --- a/lib/copy.js +++ b/lib/copy.js @@ -37,12 +37,10 @@ const removeFile = require('./utils/remove-file') * @returns {Promise} The promise which will go fulfilled after done. */ module.exports = async function copy (source, outputDir, options, callback) { - /* eslint-disable no-param-reassign */ if (typeof options === 'function') { callback = options options = undefined } - /* eslint-enable no-param-reassign */ assert(typeof source === 'string', "'source' should be a string.") assert(source.trim().length >= 1, "'source' should not be empty.") @@ -58,7 +56,6 @@ module.exports = async function copy (source, outputDir, options, callback) { ) } - // eslint-disable-next-line no-param-reassign options = normalizeOptions(source, outputDir, options) // Clean diff --git a/lib/watch.js b/lib/watch.js index d0b50b7..5a3b979 100644 --- a/lib/watch.js +++ b/lib/watch.js @@ -44,7 +44,6 @@ module.exports = function watch (source, outputDir, options) { assert(typeof options === 'object', "'options' should be an object.") } - // eslint-disable-next-line no-param-reassign options = normalizeOptions(source, outputDir, options) const watcher = new Watcher(options) diff --git a/test/copy.js b/test/copy.js index e547419..96575aa 100644 --- a/test/copy.js +++ b/test/copy.js @@ -26,18 +26,20 @@ const upperify2 = require('./util/upperify2') // Test // ------------------------------------------------------------------------------ -describe('The copy method', () => { - describe('should copy specified files with globs:', () => { - beforeEach(() => - setupTestDir({ +describe('The copy method', function () { + describe('should copy specified files with globs:', function () { + beforeEach(function () { + return setupTestDir({ 'test-ws/untouchable.txt': 'untouchable', 'test-ws/a/hello.txt': 'Hello', 'test-ws/a/b/this-is.txt': 'A pen', 'test-ws/a/b/that-is.txt': 'A note', 'test-ws/a/b/no-copy.dat': 'no-copy' }) + } ) - afterEach(() => teardownTestDir('test-ws')) + + afterEach(function () { return teardownTestDir('test-ws') }) /** * Verify. @@ -58,29 +60,28 @@ describe('The copy method', () => { }) } - it('lib async version.', done => { + it('lib async version.', function (done) { cpx.copy('test-ws/a/**/*.txt', 'test-ws/b', () => verifyFiles().then(() => done(), done) ) }) - it('lib async version (promise).', () => - cpx.copy('test-ws/a/**/*.txt', 'test-ws/b').then(verifyFiles)) + it('lib async version (promise).', function () { return cpx.copy('test-ws/a/**/*.txt', 'test-ws/b').then(verifyFiles) }) - it('lib sync version.', () => { + it('lib sync version.', function () { cpx.copySync('test-ws/a/**/*.txt', 'test-ws/b') return verifyFiles() }) - it('command version.', () => { + it('command version.', function () { execCommandSync('"test-ws/a/**/*.txt" test-ws/b') return verifyFiles() }) }) - describe('should copy specified files with globs and ignore strings:', () => { - beforeEach(() => - setupTestDir({ + describe('should copy specified files with globs and ignore strings:', function () { + beforeEach(function () { + return setupTestDir({ 'test-ws/untouchable.txt': 'untouchable', 'test-ws/a/hello.txt': 'Hello', 'test-ws/a/b/this-is.txt': 'A pen', @@ -89,8 +90,10 @@ describe('The copy method', () => { 'test-ws/a/node_modules/no-copy.txt': 'no-copy', 'test-ws/a/vscode/no-copy.txt': 'no-copy' }) + } ) - afterEach(() => teardownTestDir('test-ws')) + + afterEach(function () { return teardownTestDir('test-ws') }) /** * Verify. @@ -116,27 +119,28 @@ describe('The copy method', () => { const ignore = ['node_modules', 'vscode'] - it('lib async version.', done => { + it('lib async version.', function (done) { cpx.copy('test-ws/a/**/*.txt', 'test-ws/b', { ignore }, () => verifyFiles().then(() => done(), done) ) }) - it('lib async version (promise).', () => - cpx + it('lib async version (promise).', function () { + return cpx .copy('test-ws/a/**/*.txt', 'test-ws/b', { ignore }) - .then(verifyFiles)) + .then(verifyFiles) + }) - it('lib sync version.', () => { + it('lib sync version.', function () { cpx.copySync('test-ws/a/**/*.txt', 'test-ws/b', { ignore }) return verifyFiles() }) - it('command version.', () => { + it('command version.', function () { execCommandSync( `"test-ws/a/**/*.txt" test-ws/b --ignore ${ignore.join(',')}` ) @@ -144,9 +148,9 @@ describe('The copy method', () => { }) }) - describe('should clean and copy specified files with globs when give clean option:', () => { - beforeEach(() => - setupTestDir({ + describe('should clean and copy specified files with globs when give clean option:', function () { + beforeEach(function () { + return setupTestDir({ 'test-ws/untouchable.txt': 'untouchable', 'test-ws/a/hello.txt': 'Hello', 'test-ws/a/b/this-is.txt': 'A pen', @@ -155,8 +159,10 @@ describe('The copy method', () => { 'test-ws/b/b/remove.txt': 'remove', 'test-ws/b/b/no-remove.dat': 'no-remove' }) + } ) - afterEach(() => teardownTestDir('test-ws')) + + afterEach(function () { return teardownTestDir('test-ws') }) /** * Verify. @@ -179,25 +185,25 @@ describe('The copy method', () => { }) } - it('lib async version.', done => { + it('lib async version.', function (done) { cpx.copy('test-ws/a/**/*.txt', 'test-ws/b', { clean: true }, () => verifyFiles().then(() => done(), done) ) }) - it('lib sync version.', () => { + it('lib sync version.', function () { cpx.copySync('test-ws/a/**/*.txt', 'test-ws/b', { clean: true }) return verifyFiles() }) - it('command version.', () => { + it('command version.', function () { execCommandSync('"test-ws/a/**/*.txt" test-ws/b --clean') return verifyFiles() }) }) - describe('should copy files inside of symlink directory when `--dereference` option was specified:', () => { - beforeEach(async () => { + describe('should copy files inside of symlink directory when `--dereference` option was specified:', function () { + beforeEach(async function () { await setupTestDir({ 'test-ws/src/a/hello.txt': 'Symlinked', 'test-ws/a/hello.txt': 'Hello' @@ -208,7 +214,8 @@ describe('The copy method', () => { 'junction' ) }) - afterEach(() => teardownTestDir('test-ws')) + + afterEach(function () { return teardownTestDir('test-ws') }) /** * Verify. @@ -223,7 +230,7 @@ describe('The copy method', () => { }) } - it('lib async version.', done => { + it('lib async version.', function (done) { cpx.copy( 'test-ws/a/**/*.txt', 'test-ws/b', @@ -232,21 +239,21 @@ describe('The copy method', () => { ) }) - it('lib sync version.', () => { + it('lib sync version.', function () { cpx.copySync('test-ws/a/**/*.txt', 'test-ws/b', { dereference: true }) return verifyFiles() }) - it('command version.', () => { + it('command version.', function () { execCommandSync('"test-ws/a/**/*.txt" test-ws/b --dereference') return verifyFiles() }) }) - describe('should not copy files inside of symlink directory when `--dereference` option was not specified:', () => { - beforeEach(async () => { + describe('should not copy files inside of symlink directory when `--dereference` option was not specified:', function () { + beforeEach(async function () { await setupTestDir({ 'test-ws/src/a/hello.txt': 'Symlinked', 'test-ws/a/hello.txt': 'Hello' @@ -257,7 +264,8 @@ describe('The copy method', () => { 'junction' ) }) - afterEach(() => teardownTestDir('test-ws')) + + afterEach(function () { return teardownTestDir('test-ws') }) /** * Verify. @@ -272,32 +280,34 @@ describe('The copy method', () => { }) } - it('lib async version.', done => { + it('lib async version.', function (done) { cpx.copy('test-ws/a/**/*.txt', 'test-ws/b', {}, () => verifyFiles().then(() => done(), done) ) }) - it('lib sync version.', () => { + it('lib sync version.', function () { cpx.copySync('test-ws/a/**/*.txt', 'test-ws/b', {}) return verifyFiles() }) - it('command version.', () => { + it('command version.', function () { execCommandSync('"test-ws/a/**/*.txt" test-ws/b') return verifyFiles() }) }) - describe('should copy specified empty directories with globs when `--include-empty-dirs` option was given:', () => { - beforeEach(() => - setupTestDir({ + describe('should copy specified empty directories with globs when `--include-empty-dirs` option was given:', function () { + beforeEach(function () { + return setupTestDir({ 'test-ws/a/hello.txt': 'Hello', 'test-ws/a/b/pen.txt': 'A pen', 'test-ws/a/c': null }) + } ) - afterEach(() => teardownTestDir('test-ws')) + + afterEach(function () { return teardownTestDir('test-ws') }) /** * Verify. @@ -318,7 +328,7 @@ describe('The copy method', () => { return run() } - it('lib async version.', done => { + it('lib async version.', function (done) { cpx.copy( 'test-ws/a/**', 'test-ws/b', @@ -327,28 +337,30 @@ describe('The copy method', () => { ) }) - it('lib sync version.', () => { + it('lib sync version.', function () { cpx.copySync('test-ws/a/**', 'test-ws/b', { includeEmptyDirs: true }) return verifyFiles() }) - it('command version.', () => { + it('command version.', function () { execCommandSync('"test-ws/a/**" test-ws/b --include-empty-dirs') return verifyFiles() }) }) - describe('should not copy specified empty directories with globs when `--include-empty-dirs` option was not given:', () => { - beforeEach(() => - setupTestDir({ + describe('should not copy specified empty directories with globs when `--include-empty-dirs` option was not given:', function () { + beforeEach(function () { + return setupTestDir({ 'test-ws/a/hello.txt': 'Hello', 'test-ws/a/b/pen.txt': 'A pen', 'test-ws/a/c': null }) + } ) - afterEach(() => teardownTestDir('test-ws')) + + afterEach(function () { return teardownTestDir('test-ws') }) /** * Verify. @@ -369,34 +381,36 @@ describe('The copy method', () => { return run() } - it('lib async version.', done => { + it('lib async version.', function (done) { cpx.copy('test-ws/a/**', 'test-ws/b', () => verifyFiles().then(() => done(), done) ) }) - it('lib sync version.', () => { + it('lib sync version.', function () { cpx.copySync('test-ws/a/**', 'test-ws/b') return verifyFiles() }) - it('command version.', () => { + it('command version.', function () { execCommandSync('"test-ws/a/**" test-ws/b') return verifyFiles() }) }) - describe('should copy specified files with globs when `--preserve` option was given:', () => { - beforeEach(() => - setupTestDir({ + describe('should copy specified files with globs when `--preserve` option was given:', function () { + beforeEach(function () { + return setupTestDir({ 'test-ws/untouchable.txt': 'untouchable', 'test-ws/a/hello.txt': 'Hello', 'test-ws/a/b/this-is.txt': 'A pen', 'test-ws/a/b/that-is.txt': 'A note', 'test-ws/a/b/no-copy.dat': 'no-copy' }) + } ) - afterEach(() => teardownTestDir('test-ws')) + + afterEach(function () { return teardownTestDir('test-ws') }) /** * Verify. @@ -417,7 +431,7 @@ describe('The copy method', () => { }) } - it('lib async version.', done => { + it('lib async version.', function (done) { cpx.copy( 'test-ws/a/**/*.txt', 'test-ws/b', @@ -426,19 +440,19 @@ describe('The copy method', () => { ) }) - it('lib sync version.', () => { + it('lib sync version.', function () { cpx.copySync('test-ws/a/**/*.txt', 'test-ws/b', { preserve: true }) return verifyFiles() }) - it('command version.', () => { + it('command version.', function () { execCommandSync('"test-ws/a/**/*.txt" test-ws/b --preserve') return verifyFiles() }) }) - describe('should copy attributes when `--preserve` option was given:', () => { - afterEach(() => teardownTestDir('test-ws')) + describe('should copy attributes when `--preserve` option was given:', function () { + afterEach(function () { return teardownTestDir('test-ws') }) /** * Verify. @@ -459,25 +473,25 @@ describe('The copy method', () => { return run() } - it('lib async version.', done => { + it('lib async version.', function (done) { cpx.copy('LICENSE', 'test-ws', { preserve: true }, () => verifyFiles().then(() => done(), done) ) }) - it('lib sync version.', () => { + it('lib sync version.', function () { cpx.copySync('LICENSE', 'test-ws', { preserve: true }) return verifyFiles() }) - it('command version.', () => { + it('command version.', function () { execCommandSync('LICENSE test-ws --preserve') return verifyFiles() }) }) - describe('should not copy specified files if the source file is older than the destination file, when `--update` option was given:', () => { - beforeEach(async () => { + describe('should not copy specified files if the source file is older than the destination file, when `--update` option was given:', function () { + beforeEach(async function () { await setupTestDir({ 'test-ws/a.txt': 'newer source', 'test-ws/b.txt': 'older source', @@ -492,7 +506,8 @@ describe('The copy method', () => { await fs.utimes('test-ws/a/a.txt', older, older) await fs.utimes('test-ws/a/b.txt', newer, newer) }) - afterEach(() => teardownTestDir('test-ws')) + + afterEach(function () { return teardownTestDir('test-ws') }) /** * Verify. @@ -507,25 +522,25 @@ describe('The copy method', () => { }) } - it('lib async version.', done => { + it('lib async version.', function (done) { cpx.copy('test-ws/*.txt', 'test-ws/a', { update: true }, () => verifyFiles().then(() => done(), done) ) }) - it('lib sync version.', () => { + it('lib sync version.', function () { cpx.copySync('test-ws/*.txt', 'test-ws/a', { update: true }) return verifyFiles() }) - it('command version.', () => { + it('command version.', function () { execCommandSync('"test-ws/*.txt" test-ws/a --update') return verifyFiles() }) }) - describe('should copy specified files when `--update` option was not given:', () => { - beforeEach(async () => { + describe('should copy specified files when `--update` option was not given:', function () { + beforeEach(async function () { await setupTestDir({ 'test-ws/a.txt': 'newer source', 'test-ws/b.txt': 'older source', @@ -540,7 +555,8 @@ describe('The copy method', () => { await fs.utimes('test-ws/a/a.txt', older, older) await fs.utimes('test-ws/a/b.txt', newer, newer) }) - afterEach(() => teardownTestDir('test-ws')) + + afterEach(function () { return teardownTestDir('test-ws') }) /** * Verify. @@ -555,26 +571,27 @@ describe('The copy method', () => { }) } - it('lib async version.', done => { + it('lib async version.', function (done) { cpx.copy('test-ws/*.txt', 'test-ws/a', () => verifyFiles().then(() => done(), done) ) }) - it('lib sync version.', () => { + it('lib sync version.', function () { cpx.copySync('test-ws/*.txt', 'test-ws/a') return verifyFiles() }) - it('command version.', () => { + it('command version.', function () { execCommandSync('"test-ws/*.txt" test-ws/a') return verifyFiles() }) }) - describe('should copy with transforming when `--command` option was specified.', () => { - beforeEach(() => setupTestDir({ 'test-ws/a/hello.txt': 'Hello' })) - afterEach(() => teardownTestDir('test-ws')) + describe('should copy with transforming when `--command` option was specified.', function () { + beforeEach(function () { return setupTestDir({ 'test-ws/a/hello.txt': 'Hello' }) }) + + afterEach(function () { return teardownTestDir('test-ws') }) /** * Verify. @@ -584,7 +601,7 @@ describe('The copy method', () => { return verifyTestDir({ 'test-ws/b/hello.txt': 'HELLO' }) } - it('command version.', () => { + it('command version.', function () { execCommandSync( '"test-ws/a/**/*.txt" test-ws/b --command "node ./test/util/upperify.js"' ) @@ -592,9 +609,10 @@ describe('The copy method', () => { }) }) - describe("should copy with transforming when `--command` option was specified (it does not have 'destroy' method).", () => { - beforeEach(() => setupTestDir({ 'test-ws/a/hello.txt': 'Hello' })) - afterEach(() => teardownTestDir('test-ws')) + describe("should copy with transforming when `--command` option was specified (it does not have 'destroy' method).", function () { + beforeEach(function () { return setupTestDir({ 'test-ws/a/hello.txt': 'Hello' }) }) + + afterEach(function () { return teardownTestDir('test-ws') }) /** * Verify. @@ -604,7 +622,7 @@ describe('The copy method', () => { return verifyTestDir({ 'test-ws/b/hello.txt': 'HELLO' }) } - it('command version.', () => { + it('command version.', function () { execCommandSync( '"test-ws/a/**/*.txt" test-ws/b --command "node ./test/util/upperify2.js"' ) @@ -612,9 +630,10 @@ describe('The copy method', () => { }) }) - describe('should copy with transforming when `--transform` option was specified.', () => { - beforeEach(() => setupTestDir({ 'test-ws/a/hello.txt': 'Hello' })) - afterEach(() => teardownTestDir('test-ws')) + describe('should copy with transforming when `--transform` option was specified.', function () { + beforeEach(function () { return setupTestDir({ 'test-ws/a/hello.txt': 'Hello' }) }) + + afterEach(function () { return teardownTestDir('test-ws') }) /** * Verify. @@ -624,7 +643,7 @@ describe('The copy method', () => { return verifyTestDir({ 'test-ws/b/hello.txt': 'HELLO' }) } - it('lib async version.', done => { + it('lib async version.', function (done) { cpx.copy( 'test-ws/a/**/*.txt', 'test-ws/b', @@ -633,7 +652,7 @@ describe('The copy method', () => { ) }) - it('should throw an error on lib sync version (cannot use streaming api).', () => { + it('should throw an error on lib sync version (cannot use streaming api).', function () { assert.throws(() => { cpx.copySync('test-ws/a/**/*.txt', 'test-ws/b', { transform: upperify @@ -641,7 +660,7 @@ describe('The copy method', () => { }, Error) }) - it('command version.', () => { + it('command version.', function () { execCommandSync( '"test-ws/a/**/*.txt" test-ws/b --transform ./test/util/upperify' ) @@ -649,9 +668,10 @@ describe('The copy method', () => { }) }) - describe("should copy with transforming when `--transform` option was specified (it does not have 'destroy' method).", () => { - beforeEach(() => setupTestDir({ 'test-ws/a/hello.txt': 'Hello' })) - afterEach(() => teardownTestDir('test-ws')) + describe("should copy with transforming when `--transform` option was specified (it does not have 'destroy' method).", function () { + beforeEach(function () { return setupTestDir({ 'test-ws/a/hello.txt': 'Hello' }) }) + + afterEach(function () { return teardownTestDir('test-ws') }) /** * Verify. @@ -661,7 +681,7 @@ describe('The copy method', () => { return verifyTestDir({ 'test-ws/b/hello.txt': 'HELLO' }) } - it('lib async version.', done => { + it('lib async version.', function (done) { cpx.copy( 'test-ws/a/**/*.txt', 'test-ws/b', @@ -670,7 +690,7 @@ describe('The copy method', () => { ) }) - it('should throw an error on lib sync version (cannot use streaming api).', () => { + it('should throw an error on lib sync version (cannot use streaming api).', function () { assert.throws(() => { cpx.copySync('test-ws/a/**/*.txt', 'test-ws/b', { transform: upperify2 @@ -678,7 +698,7 @@ describe('The copy method', () => { }, Error) }) - it('command version.', () => { + it('command version.', function () { execCommandSync( '"test-ws/a/**/*.txt" test-ws/b --transform ./test/util/upperify2' ) @@ -686,9 +706,10 @@ describe('The copy method', () => { }) }) - describe('should keep order when a mix of -c and -t was specified.', () => { - beforeEach(() => setupTestDir({ 'test-ws/a/hello.txt': 'Hello' })) - afterEach(() => teardownTestDir('test-ws')) + describe('should keep order when a mix of -c and -t was specified.', function () { + beforeEach(function () { return setupTestDir({ 'test-ws/a/hello.txt': 'Hello' }) }) + + afterEach(function () { return teardownTestDir('test-ws') }) /** * Verify. @@ -698,7 +719,7 @@ describe('The copy method', () => { return verifyTestDir({ 'test-ws/b/hello.txt': 'Helloabcd' }) } - it('command version.', () => { + it('command version.', function () { execCommandSync( '"test-ws/a/**/*.txt" test-ws/b -c "node ./test/util/appendify.js a" -t [./test/util/appendify b] -c "node ./test/util/appendify.js c" -t [./test/util/appendify d]' ) @@ -706,9 +727,10 @@ describe('The copy method', () => { }) }) - describe("should copy as expected even if a specific path didn't include `/`.", () => { - beforeEach(() => setupTestDir({ 'hello.txt': 'Hello' })) - afterEach(async () => { + describe("should copy as expected even if a specific path didn't include `/`.", function () { + beforeEach(function () { return setupTestDir({ 'hello.txt': 'Hello' }) }) + + afterEach(async function () { await teardownTestDir('hello.txt') await teardownTestDir('test-ws') }) @@ -721,28 +743,28 @@ describe('The copy method', () => { return verifyTestDir({ 'test-ws/hello.txt': 'Hello' }) } - it('lib async version.', done => { + it('lib async version.', function (done) { cpx.copy('hello.txt', 'test-ws', () => verifyFiles().then(() => done(), done) ) }) - it('lib sync version.', () => { + it('lib sync version.', function () { cpx.copySync('hello.txt', 'test-ws') return verifyFiles() }) - it('command version.', () => { + it('command version.', function () { execCommandSync('hello.txt test-ws') return verifyFiles() }) }) - describe('should copy specified files with globs even if there are parentheses:', () => { - beforeEach(() => - setupTestDir({ 'test-ws/a(paren)/hello.txt': 'Hello' }) + describe('should copy specified files with globs even if there are parentheses:', function () { + beforeEach(function () { return setupTestDir({ 'test-ws/a(paren)/hello.txt': 'Hello' }) } ) - afterEach(() => teardownTestDir('test-ws')) + + afterEach(function () { return teardownTestDir('test-ws') }) /** * Verify. @@ -755,18 +777,18 @@ describe('The copy method', () => { }) } - it('lib async version.', done => { + it('lib async version.', function (done) { cpx.copy('test-ws/a(paren)/**/*.txt', 'test-ws/b', () => verifyFiles().then(() => done(), done) ) }) - it('lib sync version.', () => { + it('lib sync version.', function () { cpx.copySync('test-ws/a(paren)/**/*.txt', 'test-ws/b') return verifyFiles() }) - it('command version.', () => { + it('command version.', function () { execCommandSync('"test-ws/a(paren)/**/*.txt" test-ws/b') return verifyFiles() }) diff --git a/test/misc.js b/test/misc.js index e7efa9c..9dc44b3 100644 --- a/test/misc.js +++ b/test/misc.js @@ -18,8 +18,8 @@ const execCommandSync = require('./util/util').execCommandSync // Test // ------------------------------------------------------------------------------ -describe('[misc]', () => { - it('should throw error if invalid option was given.', () => { +describe('[misc]', function () { + it('should throw error if invalid option was given.', function () { const result = execCommandSync( '"test-ws/a/**/*.txt" test-ws/b --invalid' ) @@ -28,7 +28,7 @@ describe('[misc]', () => { assert(result.stderr === 'Unknown option(s): --invalid\n') }) - it('should throw error if invalid options were given.', () => { + it('should throw error if invalid options were given.', function () { const result = execCommandSync( '"test-ws/a/**/*.txt" test-ws/b --invalid --foo --bar' ) @@ -37,42 +37,42 @@ describe('[misc]', () => { assert(result.stderr === 'Unknown option(s): --invalid, --foo, --bar\n') }) - it('should throw error and show help if and were lacking.', () => { + it('should throw error and show help if and were lacking.', function () { const result = execCommandSync('') assert(result.code === 1) assert(/Usage:/u.test(result.stdout)) }) - it('should throw error and show help if was lacking.', () => { + it('should throw error and show help if was lacking.', function () { const result = execCommandSync('test-ws/**/*.js') assert(result.code === 1) assert(/Usage:/u.test(result.stdout)) }) - it('should show help if --help option was given.', () => { + it('should show help if --help option was given.', function () { const result = execCommandSync('--help') assert(result.code === 0) assert(/Usage:/u.test(result.stdout)) }) - it('should show help if -h option was given.', () => { + it('should show help if -h option was given.', function () { const result = execCommandSync('--help') assert(result.code === 0) assert(/Usage:/u.test(result.stdout)) }) - it('should show version if --version option was given.', () => { + it('should show version if --version option was given.', function () { const result = execCommandSync('--version') assert(result.code === 0) assert(/^v[0-9]+\.[0-9]+\.[0-9]+\n$/u.test(result.stdout)) }) - it('should show version if -V option was given.', () => { + it('should show version if -V option was given.', function () { const result = execCommandSync('-V') assert(result.code === 0) diff --git a/test/util/bin.js b/test/util/bin.js index d441cea..9eb25d3 100644 --- a/test/util/bin.js +++ b/test/util/bin.js @@ -10,7 +10,6 @@ if (process.argv.some(arg => arg === '-w' || arg === '--watch')) { process.stdin.setEncoding('utf8') process.stdin.on('data', chunk => { if (chunk === 'KILL') { - // eslint-disable-next-line no-process-exit process.exit(0) } }) diff --git a/test/watch.js b/test/watch.js index b002874..dda325c 100644 --- a/test/watch.js +++ b/test/watch.js @@ -31,11 +31,11 @@ const pEventPromise = import('p-event') // Test // ------------------------------------------------------------------------------ -describe('The watch method', () => { +describe('The watch method', function () { let watcher = null let command = null - afterEach(async () => { + afterEach(async function () { if (watcher) { watcher.close() watcher = null @@ -45,7 +45,7 @@ describe('The watch method', () => { const pEvent = (await pEventPromise).pEvent await pEvent(command, 'exit') await teardownTestDir('test-ws') - command = null // eslint-disable-line require-atomic-updates + command = null } else { await teardownTestDir('test-ws') } @@ -60,7 +60,6 @@ describe('The watch method', () => { if (watcher) { await pEvent(watcher, 'watch-ready') } else if (command) { - // eslint-disable-next-line no-constant-condition while (true) { const chunk = await pEvent(command.stdout, 'data') if (chunk.indexOf('Be watching') >= 0) { @@ -80,7 +79,6 @@ describe('The watch method', () => { if (watcher) { await pEvent(watcher, 'copy') } else if (command) { - // eslint-disable-next-line no-constant-condition while (true) { const chunk = await pEvent(command.stdout, 'data') if (chunk.indexOf('Copied:') >= 0) { @@ -100,7 +98,6 @@ describe('The watch method', () => { if (watcher) { await pEvent(watcher, 'remove') } else if (command) { - // eslint-disable-next-line no-constant-condition while (true) { const chunk = await pEvent(command.stdout, 'data') if (chunk.indexOf('Removed:') >= 0) { @@ -113,15 +110,16 @@ describe('The watch method', () => { //= ========================================================================= - describe('should copy specified files with globs at first:', () => { - beforeEach(() => - setupTestDir({ + describe('should copy specified files with globs at first:', function () { + beforeEach(function () { + return setupTestDir({ 'test-ws/untouchable.txt': 'untouchable', 'test-ws/a/hello.txt': 'Hello', 'test-ws/a/b/this-is.txt': 'A pen', 'test-ws/a/b/that-is.txt': 'A note', 'test-ws/a/b/no-copy.dat': 'no-copy' }) + } ) /** @@ -143,13 +141,13 @@ describe('The watch method', () => { }) } - it('lib version.', async () => { + it('lib version.', async function () { watcher = cpx.watch('test-ws/a/**/*.txt', 'test-ws/b') await waitForReady() await verifyFiles() }) - it('command version.', async () => { + it('command version.', async function () { command = execCommand( '"test-ws/a/**/*.txt" test-ws/b --watch --verbose' ) @@ -158,8 +156,8 @@ describe('The watch method', () => { }) }) - describe('should copy files in symlink directory at first when `--dereference` option was given:', () => { - beforeEach(async () => { + describe('should copy files in symlink directory at first when `--dereference` option was given:', function () { + beforeEach(async function () { await setupTestDir({ 'test-ws/src/a/hello.txt': 'Symlinked', 'test-ws/a/hello.txt': 'Hello' @@ -184,7 +182,7 @@ describe('The watch method', () => { }) } - it('lib version.', async () => { + it('lib version.', async function () { watcher = cpx.watch('test-ws/a/**/*.txt', 'test-ws/b', { dereference: true }) @@ -192,7 +190,7 @@ describe('The watch method', () => { await verifyFiles() }) - it('command version.', async () => { + it('command version.', async function () { command = execCommand( '"test-ws/a/**/*.txt" test-ws/b --watch --dereference --verbose' ) @@ -201,8 +199,8 @@ describe('The watch method', () => { }) }) - describe('should not copy files in symlink directory when `--dereference` option was not given:', () => { - beforeEach(async () => { + describe('should not copy files in symlink directory when `--dereference` option was not given:', function () { + beforeEach(async function () { await setupTestDir({ 'test-ws/src/a/hello.txt': 'Symlinked', 'test-ws/a/hello.txt': 'Hello' @@ -227,7 +225,7 @@ describe('The watch method', () => { }) } - it('lib version.', async () => { + it('lib version.', async function () { watcher = cpx.watch('test-ws/a/**/*.txt', 'test-ws/b', { dereference: false }) @@ -235,7 +233,7 @@ describe('The watch method', () => { await verifyFiles() }) - it('command version.', async () => { + it('command version.', async function () { command = execCommand( '"test-ws/a/**/*.txt" test-ws/b --watch --verbose' ) @@ -244,15 +242,16 @@ describe('The watch method', () => { }) }) - describe('should copy specified files with globs at first even if the glob starts with `./`:', () => { - beforeEach(() => - setupTestDir({ + describe('should copy specified files with globs at first even if the glob starts with `./`:', function () { + beforeEach(function () { + return setupTestDir({ 'test-ws/untouchable.txt': 'untouchable', 'test-ws/a/hello.txt': 'Hello', 'test-ws/a/b/this-is.txt': 'A pen', 'test-ws/a/b/that-is.txt': 'A note', 'test-ws/a/b/no-copy.dat': 'no-copy' }) + } ) /** @@ -274,13 +273,13 @@ describe('The watch method', () => { }) } - it('lib version.', async () => { + it('lib version.', async function () { watcher = cpx.watch('./test-ws/a/**/*.txt', 'test-ws/b') await waitForReady() await verifyFiles() }) - it('command version.', async () => { + it('command version.', async function () { command = execCommand( '"./test-ws/a/**/*.txt" test-ws/b --watch --verbose' ) @@ -289,9 +288,9 @@ describe('The watch method', () => { }) }) - describe('should clean and copy specified file blobs at first when give clean option:', () => { - beforeEach(() => - setupTestDir({ + describe('should clean and copy specified file blobs at first when give clean option:', function () { + beforeEach(function () { + return setupTestDir({ 'test-ws/untouchable.txt': 'untouchable', 'test-ws/a/hello.txt': 'Hello', 'test-ws/a/b/this-is.txt': 'A pen', @@ -300,6 +299,7 @@ describe('The watch method', () => { 'test-ws/b/b/remove.txt': 'remove', 'test-ws/b/b/no-remove.dat': 'no-remove' }) + } ) /** @@ -323,7 +323,7 @@ describe('The watch method', () => { }) } - it('lib version.', async () => { + it('lib version.', async function () { watcher = cpx.watch('test-ws/a/**/*.txt', 'test-ws/b', { clean: true }) @@ -331,7 +331,7 @@ describe('The watch method', () => { await verifyFiles() }) - it('command version.', async () => { + it('command version.', async function () { command = execCommand( '"test-ws/a/**/*.txt" test-ws/b --clean --watch --verbose' ) @@ -340,15 +340,16 @@ describe('The watch method', () => { }) }) - describe('should not copy specified files with globs at first when `--no-initial` option was given:', () => { - beforeEach(() => - setupTestDir({ + describe('should not copy specified files with globs at first when `--no-initial` option was given:', function () { + beforeEach(function () { + return setupTestDir({ 'test-ws/untouchable.txt': 'untouchable', 'test-ws/a/hello.txt': 'Hello', 'test-ws/a/b/this-is.txt': 'A pen', 'test-ws/a/b/that-is.txt': 'A note', 'test-ws/a/b/no-copy.dat': 'no-copy' }) + } ) /** @@ -370,7 +371,7 @@ describe('The watch method', () => { }) } - it('lib version.', async () => { + it('lib version.', async function () { watcher = cpx.watch('test-ws/a/**/*.txt', 'test-ws/b', { initialCopy: false }) @@ -378,7 +379,7 @@ describe('The watch method', () => { await verifyFiles() }) - it('command version.', async () => { + it('command version.', async function () { command = execCommand( '"test-ws/a/**/*.txt" test-ws/b --no-initial --watch --verbose' ) @@ -481,11 +482,10 @@ describe('The watch method', () => { } ] for (const pattern of patterns) { - // eslint-disable-next-line no-loop-func ;(pattern.only ? describe.only : describe)(pattern.description, () => { - beforeEach(() => setupTestDir(pattern.initialFiles)) + beforeEach(function () { return setupTestDir(pattern.initialFiles) }) - it('lib version.', async () => { + it('lib version.', async function () { watcher = cpx.watch('test-ws/a/**/*.txt', 'test-ws/b') await waitForReady() await pattern.action() @@ -493,7 +493,7 @@ describe('The watch method', () => { await verifyTestDir(pattern.verify) }) - it('command version.', async () => { + it('command version.', async function () { command = execCommand( '"test-ws/a/**/*.txt" test-ws/b --watch --verbose' ) @@ -526,11 +526,10 @@ describe('The watch method', () => { } ] for (const pattern of patternsWithIgnore) { - // eslint-disable-next-line no-loop-func ;(pattern.only ? describe.only : describe)(pattern.description, () => { - beforeEach(() => setupTestDir(pattern.initialFiles)) + beforeEach(function () { return setupTestDir(pattern.initialFiles) }) - it('lib version.', async () => { + it('lib version.', async function () { watcher = cpx.watch('test-ws/a/**/*.txt', 'test-ws/b', { ignore: pattern.ignore }) @@ -540,7 +539,7 @@ describe('The watch method', () => { await verifyTestDir(pattern.verify) }) - it('command version.', async () => { + it('command version.', async function () { command = execCommand( `"test-ws/a/**/*.txt" test-ws/b --watch --verbose --ignore ${pattern.ignore.join( ',' @@ -554,7 +553,7 @@ describe('The watch method', () => { }) } - describe('should copy and watch file from a parent dir:', () => { + describe('should copy and watch file from a parent dir:', function () { const pattern = { initialFiles: { 'test-ws/a/hello.txt': 'Hello', @@ -570,9 +569,9 @@ describe('The watch method', () => { wait: waitForCopy } - beforeEach(() => setupTestDir(pattern.initialFiles)) + beforeEach(function () { return setupTestDir(pattern.initialFiles) }) - it('lib version', async () => { + it('lib version', async function () { const startingCwd = process.cwd() process.chdir(path.join(startingCwd, 'test-ws/a')) watcher = cpx.watch('../example.txt', '.') @@ -584,12 +583,13 @@ describe('The watch method', () => { }) }) - describe('should do reactions of multiple events:', () => { - beforeEach(() => - setupTestDir({ + describe('should do reactions of multiple events:', function () { + beforeEach(function () { + return setupTestDir({ 'test-ws/a/hello.txt': 'Hello', 'test-ws/a/hello.dat': 'Hello' }) + } ) /** @@ -605,7 +605,7 @@ describe('The watch method', () => { }) } - it('lib version.', async () => { + it('lib version.', async function () { watcher = cpx.watch('test-ws/a/**/*.txt', 'test-ws/b') await waitForReady() await removeFile('test-ws/a/hello.dat') @@ -616,7 +616,7 @@ describe('The watch method', () => { await verifyFiles() }) - it('command version.', async () => { + it('command version.', async function () { command = execCommand( '"test-ws/a/**/*.txt" test-ws/b --watch --verbose' ) @@ -630,12 +630,13 @@ describe('The watch method', () => { }) }) - describe("should copy it when an empty directory is added when '--include-empty-dirs' option was given:", () => { - beforeEach(() => - setupTestDir({ + describe("should copy it when an empty directory is added when '--include-empty-dirs' option was given:", function () { + beforeEach(function () { + return setupTestDir({ 'test-ws/a/hello.txt': 'Hello', 'test-ws/a/b/hello.txt': 'Hello' }) + } ) /** @@ -650,7 +651,7 @@ describe('The watch method', () => { }) } - it('lib version.', async () => { + it('lib version.', async function () { watcher = cpx.watch('test-ws/a/**', 'test-ws/b', { includeEmptyDirs: true }) @@ -660,7 +661,7 @@ describe('The watch method', () => { await verifyFiles() }) - it('command version.', async () => { + it('command version.', async function () { command = execCommand( '"test-ws/a/**" test-ws/b --include-empty-dirs --watch --verbose' ) @@ -671,13 +672,14 @@ describe('The watch method', () => { }) }) - describe("should remove it on destination when an empty directory is removed when '--include-empty-dirs' option was given:", () => { - beforeEach(() => - setupTestDir({ + describe("should remove it on destination when an empty directory is removed when '--include-empty-dirs' option was given:", function () { + beforeEach(function () { + return setupTestDir({ 'test-ws/a/hello.txt': 'Hello', 'test-ws/a/b/hello.txt': 'Hello', 'test-ws/a/c': null }) + } ) /** @@ -692,7 +694,7 @@ describe('The watch method', () => { }) } - it('lib version.', async () => { + it('lib version.', async function () { watcher = cpx.watch('test-ws/a/**', 'test-ws/b', { includeEmptyDirs: true }) @@ -702,7 +704,7 @@ describe('The watch method', () => { await verifyFiles() }) - it('command version.', async () => { + it('command version.', async function () { command = execCommand( '"test-ws/a/**" test-ws/b --include-empty-dirs --watch --verbose' ) @@ -713,12 +715,13 @@ describe('The watch method', () => { }) }) - describe("should copy it when a file is added even if '--no-initial' option was given:", () => { - beforeEach(() => - setupTestDir({ + describe("should copy it when a file is added even if '--no-initial' option was given:", function () { + beforeEach(function () { + return setupTestDir({ 'test-ws/a/hello.txt': 'Hello', 'test-ws/a/b/hello.txt': 'Hello' }) + } ) /** @@ -733,7 +736,7 @@ describe('The watch method', () => { }) } - it('lib version.', async () => { + it('lib version.', async function () { watcher = cpx.watch('test-ws/a/**', 'test-ws/b', { initialCopy: false }) @@ -743,7 +746,7 @@ describe('The watch method', () => { await verifyFiles() }) - it('command version.', async () => { + it('command version.', async function () { command = execCommand( '"test-ws/a/**" test-ws/b --no-initial --watch --verbose' ) @@ -754,12 +757,13 @@ describe('The watch method', () => { }) }) - describe('should copy it when a file is modified even if there are parentheses in path:', () => { - beforeEach(() => - setupTestDir({ - // + describe('should copy it when a file is modified even if there are parentheses in path:', function () { + beforeEach(function () { + return setupTestDir({ + // 'test-ws/a(paren)/hello.txt': 'Hello' }) + } ) /** @@ -773,7 +777,7 @@ describe('The watch method', () => { }) } - it('lib version.', async () => { + it('lib version.', async function () { watcher = cpx.watch('test-ws/a(paren)/**', 'test-ws/b', { initialCopy: false }) @@ -783,7 +787,7 @@ describe('The watch method', () => { await verifyFiles() }) - it('command version.', async () => { + it('command version.', async function () { command = execCommand( '"test-ws/a(paren)/**" test-ws/b --no-initial --watch --verbose' )