diff --git a/lib/__tests__/fs-integration.test.js b/lib/__tests__/fs-integration.test.js index efd7ba90..4ff52c59 100644 --- a/lib/__tests__/fs-integration.test.js +++ b/lib/__tests__/fs-integration.test.js @@ -1,31 +1,31 @@ -var assert = require('assert') -var path = require('path') -var os = require('os') -var fs = require('fs') -var fse = require('../') +'use strict' + +const os = require('os') +const fs = require('fs') +const fse = require('../') +const path = require('path') +const assert = require('assert') /* global afterEach, beforeEach, describe, it */ -describe('native fs', function () { - var TEST_DIR +describe('native fs', () => { + let TEST_DIR - beforeEach(function (done) { + beforeEach(done => { TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'native-fs') fse.emptyDir(TEST_DIR, done) }) - afterEach(function (done) { - fse.remove(TEST_DIR, done) - }) + afterEach(done => fse.remove(TEST_DIR, done)) - it('should use native fs methods', function () { - var file = path.join(TEST_DIR, 'write.txt') + it('should use native fs methods', () => { + const file = path.join(TEST_DIR, 'write.txt') fse.writeFileSync(file, 'hello') - var data = fse.readFileSync(file, 'utf8') + const data = fse.readFileSync(file, 'utf8') assert.equal(data, 'hello') }) - it('should have native fs constants', function () { + it('should have native fs constants', () => { // Node.js v0.12 / IO.js if ('F_OK' in fs) { assert.equal(fse.F_OK, fs.F_OK) diff --git a/lib/copy-sync/__tests__/broken-symlink.test.js b/lib/copy-sync/__tests__/broken-symlink.test.js index 7ba184b0..c5772ed2 100644 --- a/lib/copy-sync/__tests__/broken-symlink.test.js +++ b/lib/copy-sync/__tests__/broken-symlink.test.js @@ -1,52 +1,48 @@ -var assert = require('assert') -var fs = require('fs') -var path = require('path') -var os = require('os') -var fse = require(process.cwd()) -var copySync = require('../copy-sync') +'use strict' + +const fs = require('fs') +const os = require('os') +const fse = require(process.cwd()) +const path = require('path') +const assert = require('assert') +const copySync = require('../copy-sync') /* global afterEach, beforeEach, describe, it */ -describe('copy-sync / broken symlink', function () { - var TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'copy-sync-broken-symlinks') - var src = path.join(TEST_DIR, 'src') - var out = path.join(TEST_DIR, 'out') +describe('copy-sync / broken symlink', () => { + const TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'copy-sync-broken-symlinks') + const src = path.join(TEST_DIR, 'src') + const out = path.join(TEST_DIR, 'out') - beforeEach(function (done) { - fse.emptyDir(TEST_DIR, function (err) { + beforeEach(done => { + fse.emptyDir(TEST_DIR, err => { assert.ifError(err) createFixtures(src, done) }) }) - afterEach(function (done) { - fse.remove(TEST_DIR, done) - }) - - it('should copy broken symlinks by default', function () { - assert.doesNotThrow(function () { - copySync(src, out) - }) + afterEach(done => fse.remove(TEST_DIR, done)) + it('should copy broken symlinks by default', () => { + assert.doesNotThrow(() => copySync(src, out)) assert.equal(fs.readlinkSync(path.join(out, 'broken-symlink')), path.join(src, 'does-not-exist')) }) - it('should throw an error when dereference=true', function () { - assert.throws(function () { - copySync(src, out, {dereference: true}) - }, function (err) { - return err.code === 'ENOENT' - }) + it('should throw an error when dereference=true', () => { + assert.throws(() => copySync(src, out, {dereference: true}), err => err.code === 'ENOENT') }) }) function createFixtures (srcDir, callback) { - fs.mkdir(srcDir, function (err) { + fs.mkdir(srcDir, err => { + let brokenFile + let brokenFileLink + if (err) return callback(err) try { - var brokenFile = path.join(srcDir, 'does-not-exist') - var brokenFileLink = path.join(srcDir, 'broken-symlink') + brokenFile = path.join(srcDir, 'does-not-exist') + brokenFileLink = path.join(srcDir, 'broken-symlink') fs.writeFileSync(brokenFile, 'does not matter') fs.symlinkSync(brokenFile, brokenFileLink, 'file') } catch (err) { diff --git a/lib/copy-sync/__tests__/copy-sync-dir.test.js b/lib/copy-sync/__tests__/copy-sync-dir.test.js index d457982a..2b3cd0a1 100644 --- a/lib/copy-sync/__tests__/copy-sync-dir.test.js +++ b/lib/copy-sync/__tests__/copy-sync-dir.test.js @@ -1,84 +1,84 @@ -var assert = require('assert') -var crypto = require('crypto') -var os = require('os') -var path = require('path') -var fs = require(process.cwd()) +'use strict' + +const fs = require(process.cwd()) +const os = require('os') +const path = require('path') +const assert = require('assert') +const crypto = require('crypto') /* global beforeEach, describe, it */ -describe('+ copySync()', function () { - var TEST_DIR - var SIZE = 16 * 64 * 1024 + 7 - var src, dest +describe('+ copySync()', () => { + const SIZE = 16 * 64 * 1024 + 7 + let TEST_DIR + let src, dest - beforeEach(function (done) { + beforeEach(done => { TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'copy-sync-dir') src = path.join(TEST_DIR, 'src') dest = path.join(TEST_DIR, 'dest') fs.emptyDir(TEST_DIR, done) }) - describe('> when the source is a directory', function () { - it('should copy the directory synchronously', function () { - var FILES = 2 - var i, j - var src = path.join(TEST_DIR, 'src') - var dest = path.join(TEST_DIR, 'dest') + describe('> when the source is a directory', () => { + it('should copy the directory synchronously', () => { + const FILES = 2 + + src = path.join(TEST_DIR, 'src') + dest = path.join(TEST_DIR, 'dest') fs.mkdirsSync(src) - for (i = 0; i < FILES; ++i) { + for (let i = 0; i < FILES; ++i) { fs.writeFileSync(path.join(src, i.toString()), crypto.randomBytes(SIZE)) } - var subdir = path.join(src, 'subdir') + const subdir = path.join(src, 'subdir') fs.mkdirsSync(subdir) - for (i = 0; i < FILES; ++i) { + for (let i = 0; i < FILES; ++i) { fs.writeFileSync(path.join(subdir, i.toString()), crypto.randomBytes(SIZE)) } fs.copySync(src, dest) assert(fs.existsSync(dest)) - for (i = 0; i < FILES; ++i) { + for (let i = 0; i < FILES; ++i) { assert(fs.existsSync(path.join(dest, i.toString()))) } - var destSub = path.join(dest, 'subdir') - for (j = 0; j < FILES; ++j) { + const destSub = path.join(dest, 'subdir') + for (let j = 0; j < FILES; ++j) { assert(fs.existsSync(path.join(destSub, j.toString()))) } }) - it('should preserve symbolic links', function () { + it('should preserve symbolic links', () => { fs.mkdirsSync(src) fs.symlinkSync('destination', path.join(src, 'symlink')) fs.copySync(src, dest) - var link = fs.readlinkSync(path.join(dest, 'symlink')) + const link = fs.readlinkSync(path.join(dest, 'symlink')) assert.strictEqual(link, 'destination') }) - it('should should apply filter recursively', function () { - var FILES = 2 - var filter = function (s) { - // Don't match anything that ends with a digit higher than 0: - return /(0|\D)$/i.test(s) - } + it('should should apply filter recursively', () => { + const FILES = 2 + // Don't match anything that ends with a digit higher than 0: + const filter = s => /(0|\D)$/i.test(s) fs.mkdirsSync(src) - for (var i = 0; i < FILES; ++i) { + for (let i = 0; i < FILES; ++i) { fs.writeFileSync(path.join(src, i.toString()), crypto.randomBytes(SIZE)) } - var subdir = path.join(src, 'subdir') + const subdir = path.join(src, 'subdir') fs.mkdirsSync(subdir) - for (i = 0; i < FILES; ++i) { + for (let i = 0; i < FILES; ++i) { fs.writeFileSync(path.join(subdir, i.toString()), crypto.randomBytes(SIZE)) } @@ -87,7 +87,7 @@ describe('+ copySync()', function () { assert(fs.existsSync(dest)) assert(FILES > 1) - for (i = 0; i < FILES; ++i) { + for (let i = 0; i < FILES; ++i) { if (i === 0) { assert(fs.existsSync(path.join(dest, i.toString()))) } else { @@ -95,9 +95,9 @@ describe('+ copySync()', function () { } } - var destSub = path.join(dest, 'subdir') + const destSub = path.join(dest, 'subdir') - for (var j = 0; j < FILES; ++j) { + for (let j = 0; j < FILES; ++j) { if (j === 0) { assert(fs.existsSync(path.join(destSub, j.toString()))) } else { @@ -106,15 +106,13 @@ describe('+ copySync()', function () { } }) - it('should apply the filter to directory names', function () { - var IGNORE = 'ignore' - var filter = function (p) { - return !~p.indexOf(IGNORE) - } + it('should apply the filter to directory names', () => { + const IGNORE = 'ignore' + const filter = p => !~p.indexOf(IGNORE) fs.mkdirsSync(src) - var ignoreDir = path.join(src, IGNORE) + const ignoreDir = path.join(src, IGNORE) fs.mkdirsSync(ignoreDir) fs.writeFileSync(path.join(ignoreDir, 'file'), crypto.randomBytes(SIZE)) @@ -125,23 +123,23 @@ describe('+ copySync()', function () { assert(!fs.existsSync(path.join(dest, IGNORE, 'file')), 'file was not ignored') }) - describe('> when the destination dir does not exist', function () { - it('should create the destination directory and copy the file', function () { - var src = path.join(TEST_DIR, 'data/') + describe('> when the destination dir does not exist', () => { + it('should create the destination directory and copy the file', () => { + const src = path.join(TEST_DIR, 'data/') fs.mkdirSync(src) - var d1 = 'file1' - var d2 = 'file2' + const d1 = 'file1' + const d2 = 'file2' fs.writeFileSync(path.join(src, 'f1.txt'), d1) fs.writeFileSync(path.join(src, 'f2.txt'), d2) - var dest = path.join(TEST_DIR, 'this/path/does/not/exist/outputDir') + const dest = path.join(TEST_DIR, 'this/path/does/not/exist/outputDir') fs.copySync(src, dest) - var o1 = fs.readFileSync(path.join(dest, 'f1.txt'), 'utf8') - var o2 = fs.readFileSync(path.join(dest, 'f2.txt'), 'utf8') + const o1 = fs.readFileSync(path.join(dest, 'f1.txt'), 'utf8') + const o2 = fs.readFileSync(path.join(dest, 'f2.txt'), 'utf8') assert.strictEqual(d1, o1) assert.strictEqual(d2, o2) diff --git a/lib/copy-sync/__tests__/copy-sync-file.test.js b/lib/copy-sync/__tests__/copy-sync-file.test.js index 70e2e5ce..2874c120 100644 --- a/lib/copy-sync/__tests__/copy-sync-file.test.js +++ b/lib/copy-sync/__tests__/copy-sync-file.test.js @@ -1,34 +1,34 @@ -var assert = require('assert') -var crypto = require('crypto') -var os = require('os') -var path = require('path') -var fs = require(process.cwd()) +'use strict' + +const fs = require(process.cwd()) +const os = require('os') +const path = require('path') +const assert = require('assert') +const crypto = require('crypto') /* global afterEach, beforeEach, describe, it */ -var SIZE = 16 * 64 * 1024 + 7 +const SIZE = 16 * 64 * 1024 + 7 -describe('+ copySync()', function () { - var TEST_DIR +describe('+ copySync()', () => { + let TEST_DIR - beforeEach(function (done) { + beforeEach(done => { TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'copy-sync') fs.emptyDir(TEST_DIR, done) }) - afterEach(function (done) { - fs.remove(TEST_DIR, done) - }) + afterEach(done => fs.remove(TEST_DIR, done)) - describe('> when the source is a file', function () { - it('should copy the file synchronously', function () { - var fileSrc = path.join(TEST_DIR, 'TEST_fs-extra_src') - var fileDest = path.join(TEST_DIR, 'TEST_fs-extra_copy') + describe('> when the source is a file', () => { + it('should copy the file synchronously', () => { + const fileSrc = path.join(TEST_DIR, 'TEST_fs-extra_src') + const fileDest = path.join(TEST_DIR, 'TEST_fs-extra_copy') fs.writeFileSync(fileSrc, crypto.randomBytes(SIZE)) - var srcMd5 = crypto.createHash('md5').update(fs.readFileSync(fileSrc)).digest('hex') - var destMd5 = '' + const srcMd5 = crypto.createHash('md5').update(fs.readFileSync(fileSrc)).digest('hex') + let destMd5 = '' fs.copySync(fileSrc, fileDest) @@ -36,15 +36,15 @@ describe('+ copySync()', function () { assert.strictEqual(srcMd5, destMd5) }) - it('should follow symlinks', function () { - var fileSrc = path.join(TEST_DIR, 'TEST_fs-extra_src') - var fileDest = path.join(TEST_DIR, 'TEST_fs-extra_copy') - var linkSrc = path.join(TEST_DIR, 'TEST_fs-extra_copy_link') + it('should follow symlinks', () => { + const fileSrc = path.join(TEST_DIR, 'TEST_fs-extra_src') + const fileDest = path.join(TEST_DIR, 'TEST_fs-extra_copy') + const linkSrc = path.join(TEST_DIR, 'TEST_fs-extra_copy_link') fs.writeFileSync(fileSrc, crypto.randomBytes(SIZE)) - var srcMd5 = crypto.createHash('md5').update(fs.readFileSync(fileSrc)).digest('hex') - var destMd5 = '' + const srcMd5 = crypto.createHash('md5').update(fs.readFileSync(fileSrc)).digest('hex') + let destMd5 = '' fs.symlinkSync(fileSrc, linkSrc) fs.copySync(linkSrc, fileDest) @@ -52,33 +52,33 @@ describe('+ copySync()', function () { assert.strictEqual(srcMd5, destMd5) }) - it('should maintain file mode', function () { - var fileSrc = path.join(TEST_DIR, 'TEST_fs-extra_src') - var fileDest = path.join(TEST_DIR, 'TEST_fs-extra_copy') + it('should maintain file mode', () => { + const fileSrc = path.join(TEST_DIR, 'TEST_fs-extra_src') + const fileDest = path.join(TEST_DIR, 'TEST_fs-extra_copy') fs.writeFileSync(fileSrc, crypto.randomBytes(SIZE)) fs.chmodSync(fileSrc, parseInt('750', 8)) fs.copySync(fileSrc, fileDest) - var statSrc = fs.statSync(fileSrc) - var statDest = fs.statSync(fileDest) + const statSrc = fs.statSync(fileSrc) + const statDest = fs.statSync(fileDest) assert.strictEqual(statSrc.mode, statDest.mode) }) - it('should only copy files allowed by filter fn', function () { - var srcFile1 = path.join(TEST_DIR, '1.html') - var srcFile2 = path.join(TEST_DIR, '2.css') - var srcFile3 = path.join(TEST_DIR, '3.jade') + it('should only copy files allowed by filter fn', () => { + const srcFile1 = path.join(TEST_DIR, '1.html') + const srcFile2 = path.join(TEST_DIR, '2.css') + const srcFile3 = path.join(TEST_DIR, '3.jade') fs.writeFileSync(srcFile1, '') fs.writeFileSync(srcFile2, '') fs.writeFileSync(srcFile3, '') - var destFile1 = path.join(TEST_DIR, 'dest1.html') - var destFile2 = path.join(TEST_DIR, 'dest2.css') - var destFile3 = path.join(TEST_DIR, 'dest3.jade') + const destFile1 = path.join(TEST_DIR, 'dest1.html') + const destFile2 = path.join(TEST_DIR, 'dest2.css') + const destFile3 = path.join(TEST_DIR, 'dest3.jade') - var filter = function (s) { return s.split('.').pop() !== 'css' } + const filter = s => s.split('.').pop() !== 'css' fs.copySync(srcFile1, destFile1, filter) fs.copySync(srcFile2, destFile2, filter) @@ -89,43 +89,43 @@ describe('+ copySync()', function () { assert(fs.existsSync(destFile3)) }) - describe('> when the destination dir does not exist', function () { - it('should create the destination directory and copy the file', function () { - var src = path.join(TEST_DIR, 'file.txt') - var dest = path.join(TEST_DIR, 'this/path/does/not/exist/copied.txt') - var data = 'did it copy?\n' + describe('> when the destination dir does not exist', () => { + it('should create the destination directory and copy the file', () => { + const src = path.join(TEST_DIR, 'file.txt') + const dest = path.join(TEST_DIR, 'this/path/does/not/exist/copied.txt') + const data = 'did it copy?\n' fs.writeFileSync(src, data, 'utf8') fs.copySync(src, dest) - var data2 = fs.readFileSync(dest, 'utf8') + const data2 = fs.readFileSync(dest, 'utf8') assert.strictEqual(data, data2) }) }) - describe('> when the source file does not have write permissions', function () { - it('should be able to copy contents of file', function () { - var fileSrc = path.join(TEST_DIR, 'file.txt') - var fileDest = path.join(TEST_DIR, 'file-copy.txt') - var data = 'did it copy?' + describe('> when the source file does not have write permissions', () => { + it('should be able to copy contents of file', () => { + const fileSrc = path.join(TEST_DIR, 'file.txt') + const fileDest = path.join(TEST_DIR, 'file-copy.txt') + const data = 'did it copy?' fs.writeFileSync(fileSrc, data, 'utf8') fs.chmodSync(fileSrc, '0444') fs.copySync(fileSrc, fileDest) - var data2 = fs.readFileSync(fileDest, 'utf8') + const data2 = fs.readFileSync(fileDest, 'utf8') assert.strictEqual(data, data2) }) }) - describe('> when overwrite option is passed', function () { - var src, dest - var srcData = 'some src data' + describe('> when overwrite option is passed', () => { + const srcData = 'some src data' + let src, dest - beforeEach(function () { + beforeEach(() => { src = path.join(TEST_DIR, 'src-file') dest = path.join(TEST_DIR, 'des-file') @@ -133,60 +133,59 @@ describe('+ copySync()', function () { fs.writeFileSync(src, srcData) }) - describe('> when destination file does NOT exist', function () { - describe('> when overwrite is true', function () { - it('should copy the file and not throw an error', function () { + describe('> when destination file does NOT exist', () => { + describe('> when overwrite is true', () => { + it('should copy the file and not throw an error', () => { fs.copySync(src, dest, {overwrite: true}) - var destData = fs.readFileSync(dest, 'utf8') + const destData = fs.readFileSync(dest, 'utf8') assert.strictEqual(srcData, destData) }) }) - describe('> when overwrite is false', function () { - it('should copy the file and not throw an error', function () { + describe('> when overwrite is false', () => { + it('should copy the file and not throw an error', () => { fs.copySync(src, dest, {overwrite: false}) - var destData = fs.readFileSync(dest, 'utf8') + const destData = fs.readFileSync(dest, 'utf8') assert.strictEqual(srcData, destData) }) }) }) - describe('when destination file does exist', function () { - var destData - beforeEach(function () { + describe('when destination file does exist', () => { + let destData + + beforeEach(() => { destData = 'some dest data' fs.writeFileSync(dest, destData) }) - describe('> when overwrite is true', function () { - it('should copy the file and not throw an error', function () { + describe('> when overwrite is true', () => { + it('should copy the file and not throw an error', () => { fs.copySync(src, dest, {overwrite: true}) destData = fs.readFileSync(dest, 'utf8') assert.strictEqual(srcData, destData) }) }) - describe('> when overwrite is false', function () { - it('should not throw an error', function () { + describe('> when overwrite is false', () => { + it('should not throw an error', () => { fs.copySync(src, dest, {overwrite: false}) // copy never happened - var destDataNew = fs.readFileSync(dest, 'utf8') + const destDataNew = fs.readFileSync(dest, 'utf8') assert.strictEqual(destData, destDataNew) }) - it('should throw an error when errorOnExist is true', function () { - assert.throws(function () { - fs.copySync(src, dest, {overwrite: false, errorOnExist: true}) - }) + it('should throw an error when errorOnExist is true', () => { + assert.throws(() => fs.copySync(src, dest, {overwrite: false, errorOnExist: true})) // copy never happened - var destDataNew = fs.readFileSync(dest, 'utf8') + const destDataNew = fs.readFileSync(dest, 'utf8') assert.strictEqual(destData, destDataNew) }) }) - describe('> when overwrite is true and dest is readonly', function () { - it('should copy the file and not throw an error', function () { + describe('> when overwrite is true and dest is readonly', () => { + it('should copy the file and not throw an error', () => { try { fs.chmodSync(dest, parseInt('444', 8)) fs.copySync(src, dest, {overwrite: true}) @@ -200,10 +199,10 @@ describe('+ copySync()', function () { }) }) }) - describe('clobber', function () { - var src, dest, srcData, destData + describe('clobber', () => { + let src, dest, srcData, destData - beforeEach(function () { + beforeEach(() => { src = path.join(TEST_DIR, 'src-file') dest = path.join(TEST_DIR, 'des-file') srcData = 'some src data' @@ -212,11 +211,11 @@ describe('+ copySync()', function () { fs.writeFileSync(dest, destData) }) - it('is an alias for overwrite', function () { + it('is an alias for overwrite', () => { fs.copySync(src, dest, {clobber: false}) // copy never happened - var destDataNew = fs.readFileSync(dest, 'utf8') + const destDataNew = fs.readFileSync(dest, 'utf8') assert.strictEqual(destData, destDataNew) }) }) diff --git a/lib/copy-sync/__tests__/copy-sync-preserve-time.test.js b/lib/copy-sync/__tests__/copy-sync-preserve-time.test.js index 8028b739..8c4bfa9f 100644 --- a/lib/copy-sync/__tests__/copy-sync-preserve-time.test.js +++ b/lib/copy-sync/__tests__/copy-sync-preserve-time.test.js @@ -1,35 +1,37 @@ -var assert = require('assert') -var fs = require('fs') -var os = require('os') -var path = require('path') -var copySync = require('../copy-sync') -var utimes = require('../../util/utimes') +'use strict' + +const fs = require('fs') +const os = require('os') +const path = require('path') +const utimes = require('../../util/utimes') +const assert = require('assert') +const copySync = require('../copy-sync') /* global beforeEach, describe, it */ -describe('copy', function () { - var TEST_DIR +describe('copy', () => { + let TEST_DIR - beforeEach(function (done) { + beforeEach(done => { TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'copy-sync-preserve-time') require(process.cwd()).emptyDir(TEST_DIR, done) }) - describe('> modification option', function () { - var SRC_FIXTURES_DIR = path.join(__dirname, './fixtures') - var FILES = ['a-file', path.join('a-folder', 'another-file'), path.join('a-folder', 'another-folder', 'file3')] + describe('> modification option', () => { + const SRC_FIXTURES_DIR = path.join(__dirname, './fixtures') + const FILES = ['a-file', path.join('a-folder', 'another-file'), path.join('a-folder', 'another-folder', 'file3')] - describe('> when modified option is turned off', function () { - it('should have different timestamps on copy', function () { - var from = path.join(SRC_FIXTURES_DIR) + describe('> when modified option is turned off', () => { + it('should have different timestamps on copy', () => { + const from = path.join(SRC_FIXTURES_DIR) copySync(from, TEST_DIR, {preserveTimestamps: false}) FILES.forEach(testFile({preserveTimestamps: false})) }) }) - describe('> when modified option is turned on', function () { - it('should have the same timestamps on copy', function () { - var from = path.join(SRC_FIXTURES_DIR) + describe('> when modified option is turned on', () => { + it('should have the same timestamps on copy', () => { + const from = path.join(SRC_FIXTURES_DIR) copySync(from, TEST_DIR, {preserveTimestamps: true}) FILES.forEach(testFile({preserveTimestamps: true})) }) @@ -37,10 +39,10 @@ describe('copy', function () { function testFile (options) { return function (file) { - var a = path.join(SRC_FIXTURES_DIR, file) - var b = path.join(TEST_DIR, file) - var fromStat = fs.statSync(a) - var toStat = fs.statSync(b) + const a = path.join(SRC_FIXTURES_DIR, file) + const b = path.join(TEST_DIR, file) + const fromStat = fs.statSync(a) + const toStat = fs.statSync(b) if (options.preserveTimestamps) { // https://github.com/nodejs/io.js/issues/2069 if (process.platform !== 'win32') { diff --git a/lib/copy-sync/__tests__/symlink.test.js b/lib/copy-sync/__tests__/symlink.test.js index 28905837..3764e599 100644 --- a/lib/copy-sync/__tests__/symlink.test.js +++ b/lib/copy-sync/__tests__/symlink.test.js @@ -1,30 +1,32 @@ -var assert = require('assert') -var fs = require('fs') -var path = require('path') -var os = require('os') -var fse = require(process.cwd()) -var copySync = require('../copy-sync') +'use strict' + +const fs = require('fs') +const os = require('os') +const fse = require(process.cwd()) +const path = require('path') +const assert = require('assert') +const copySync = require('../copy-sync') /* global afterEach, beforeEach, describe, it */ -describe('copy-sync / symlink', function () { - var TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'copy-sync-symlinks') - var src = path.join(TEST_DIR, 'src') - var out = path.join(TEST_DIR, 'out') +describe('copy-sync / symlink', () => { + const TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'copy-sync-symlinks') + const src = path.join(TEST_DIR, 'src') + const out = path.join(TEST_DIR, 'out') - beforeEach(function (done) { - fse.emptyDir(TEST_DIR, function (err) { + beforeEach(done => { + fse.emptyDir(TEST_DIR, err => { assert.ifError(err) createFixtures(src, done) }) }) - afterEach(function (done) { + afterEach(done => { fse.remove(TEST_DIR, done) }) - it('copies symlinks by default', function () { - assert.doesNotThrow(function () { + it('copies symlinks by default', () => { + assert.doesNotThrow(() => { copySync(src, out) }) @@ -32,38 +34,38 @@ describe('copy-sync / symlink', function () { assert.equal(fs.readlinkSync(path.join(out, 'dir-symlink')), path.join(src, 'dir')) }) - it('copies file contents when dereference=true', function () { + it('copies file contents when dereference=true', () => { try { copySync(src, out, {dereference: true}) } catch (err) { assert.ifError(err) } - var fileSymlinkPath = path.join(out, 'file-symlink') + const fileSymlinkPath = path.join(out, 'file-symlink') assert.ok(fs.lstatSync(fileSymlinkPath).isFile()) assert.equal(fs.readFileSync(fileSymlinkPath), 'foo contents') - var dirSymlinkPath = path.join(out, 'dir-symlink') + const dirSymlinkPath = path.join(out, 'dir-symlink') assert.ok(fs.lstatSync(dirSymlinkPath).isDirectory()) assert.deepEqual(fs.readdirSync(dirSymlinkPath), ['bar']) }) }) function createFixtures (srcDir, callback) { - fs.mkdir(srcDir, function (err) { + fs.mkdir(srcDir, err => { if (err) return callback(err) // note: third parameter in symlinkSync is type e.g. 'file' or 'dir' // https://nodejs.org/api/fs.html#fs_fs_symlink_srcpath_dstpath_type_callback try { - var fooFile = path.join(srcDir, 'foo') - var fooFileLink = path.join(srcDir, 'file-symlink') + const fooFile = path.join(srcDir, 'foo') + const fooFileLink = path.join(srcDir, 'file-symlink') fs.writeFileSync(fooFile, 'foo contents') fs.symlinkSync(fooFile, fooFileLink, 'file') - var dir = path.join(srcDir, 'dir') - var dirFile = path.join(dir, 'bar') - var dirLink = path.join(srcDir, 'dir-symlink') + const dir = path.join(srcDir, 'dir') + const dirFile = path.join(dir, 'bar') + const dirLink = path.join(srcDir, 'dir-symlink') fs.mkdirSync(dir) fs.writeFileSync(dirFile, 'bar contents') fs.symlinkSync(dir, dirLink, 'dir') diff --git a/lib/copy/__tests__/async/copy-gh-89.test.js b/lib/copy/__tests__/async/copy-gh-89.test.js index 4ff9269b..4cfe191c 100644 --- a/lib/copy/__tests__/async/copy-gh-89.test.js +++ b/lib/copy/__tests__/async/copy-gh-89.test.js @@ -1,46 +1,48 @@ +'use strict' + // relevant: https://github.com/jprichardson/node-fs-extra/issues/89 // come up with better file name -var assert = require('assert') -var fs = require('fs') -var path = require('path') -var os = require('os') -var fse = require(process.cwd()) +const fs = require('fs') +const os = require('os') +const fse = require(process.cwd()) +const path = require('path') +const assert = require('assert') /* global afterEach, beforeEach, describe, it */ -describe('copy / gh #89', function () { - var TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'copy-gh-89') +describe('copy / gh #89', () => { + const TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'copy-gh-89') - beforeEach(function (done) { + beforeEach(done => { fse.emptyDir(TEST_DIR, done) }) - afterEach(function (done) { + afterEach(done => { fse.remove(TEST_DIR, done) }) - it('should...', function (done) { - var A = path.join(TEST_DIR, 'A') - var B = path.join(TEST_DIR, 'B') + it('should...', done => { + const A = path.join(TEST_DIR, 'A') + const B = path.join(TEST_DIR, 'B') fs.mkdirSync(A) fs.mkdirSync(B) - var one = path.join(A, 'one.txt') - var two = path.join(A, 'two.txt') - var three = path.join(B, 'three.txt') - var four = path.join(B, 'four.txt') + const one = path.join(A, 'one.txt') + const two = path.join(A, 'two.txt') + const three = path.join(B, 'three.txt') + const four = path.join(B, 'four.txt') fs.writeFileSync(one, '1') fs.writeFileSync(two, '2') fs.writeFileSync(three, '3') fs.writeFileSync(four, '4') - var C = path.join(TEST_DIR, 'C') - fse.copy(A, C, function (err) { + const C = path.join(TEST_DIR, 'C') + fse.copy(A, C, err => { if (err) return done(err) - fse.copy(B, C, function (err) { + fse.copy(B, C, err => { if (err) return done(err) assert(fs.existsSync(path.join(C, 'one.txt'))) diff --git a/lib/copy/__tests__/copy-dev-null.test.js b/lib/copy/__tests__/copy-dev-null.test.js index dfdfea50..582fe79b 100644 --- a/lib/copy/__tests__/copy-dev-null.test.js +++ b/lib/copy/__tests__/copy-dev-null.test.js @@ -1,31 +1,33 @@ -var assert = require('assert') -var fs = require('fs') -var os = require('os') -var path = require('path') -var fse = require('../../') +'use strict' + +const fs = require('fs') +const os = require('os') +const fse = require('../../') +const path = require('path') +const assert = require('assert') /* global afterEach, beforeEach, describe, it */ -var TEST_DIR = '' +let TEST_DIR = '' -describe('fs-extra', function () { - beforeEach(function (done) { +describe('fs-extra', () => { + beforeEach(done => { TEST_DIR = path.join(os.tmpdir(), 'test', 'fs-extra', 'copy-dev-null') fse.emptyDir(TEST_DIR, done) }) - afterEach(function (done) { - fse.remove(TEST_DIR, done) - }) + afterEach(done => fse.remove(TEST_DIR, done)) - describe('+ copy()', function () { - it('should error', function (done) { + describe('+ copy()', () => { + it('should error', done => { // no /dev/null on windows if (process.platform === 'win32') return done() - var tmpFile = path.join(TEST_DIR, 'foo') - fse.copy('/dev/null', tmpFile, function (err) { + + const tmpFile = path.join(TEST_DIR, 'foo') + + fse.copy('/dev/null', tmpFile, err => { assert.ifError(err) - var stats = fs.lstatSync(tmpFile) + const stats = fs.lstatSync(tmpFile) assert.strictEqual(stats.size, 0) done() }) diff --git a/lib/copy/__tests__/copy-permissions.test.js b/lib/copy/__tests__/copy-permissions.test.js index 16516d61..ccc89cd2 100644 --- a/lib/copy/__tests__/copy-permissions.test.js +++ b/lib/copy/__tests__/copy-permissions.test.js @@ -1,36 +1,38 @@ -var assert = require('assert') -var fs = require('fs') -var os = require('os') -var path = require('path') -var fse = require('../../') +'use strict' + +const fs = require('fs') +const os = require('os') +const fse = require('../../') +const path = require('path') +const assert = require('assert') /* global beforeEach, describe, it */ -var o777 = parseInt('777', 8) -var o666 = parseInt('666', 8) -var o444 = parseInt('444', 8) +const o777 = parseInt('777', 8) +const o666 = parseInt('666', 8) +const o444 = parseInt('444', 8) -describe('copy', function () { - var TEST_DIR +describe('copy', () => { + let TEST_DIR - beforeEach(function (done) { + beforeEach(done => { TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'copy') fse.emptyDir(TEST_DIR, done) }) // pretty UNIX specific, may not pass on windows... only tested on Mac OS X 10.9 - it('should maintain file permissions and ownership', function (done) { + it('should maintain file permissions and ownership', done => { if (process.platform === 'win32') return done() // var userid = require('userid') // http://man7.org/linux/man-pages/man2/stat.2.html - var S_IFREG = parseInt('0100000', 8) // regular file - var S_IFDIR = parseInt('0040000', 8) // directory + const S_IFREG = parseInt('0100000', 8) // regular file + const S_IFDIR = parseInt('0040000', 8) // directory // these are Mac specific I think (at least staff), should find Linux equivalent - var gidWheel - var gidStaff + let gidWheel + let gidStaff try { gidWheel = process.getgid() // userid.gid('wheel') @@ -44,48 +46,48 @@ describe('copy', function () { gidStaff = process.getgid() } - var permDir = path.join(TEST_DIR, 'perms') + const permDir = path.join(TEST_DIR, 'perms') fs.mkdirSync(permDir) - var srcDir = path.join(permDir, 'src') + const srcDir = path.join(permDir, 'src') fs.mkdirSync(srcDir) - var f1 = path.join(srcDir, 'f1.txt') + const f1 = path.join(srcDir, 'f1.txt') fs.writeFileSync(f1, '') fs.chmodSync(f1, o666) fs.chownSync(f1, process.getuid(), gidWheel) - var f1stats = fs.lstatSync(f1) + const f1stats = fs.lstatSync(f1) assert.strictEqual(f1stats.mode - S_IFREG, o666) - var d1 = path.join(srcDir, 'somedir') + const d1 = path.join(srcDir, 'somedir') fs.mkdirSync(d1) fs.chmodSync(d1, o777) fs.chownSync(d1, process.getuid(), gidStaff) - var d1stats = fs.lstatSync(d1) + const d1stats = fs.lstatSync(d1) assert.strictEqual(d1stats.mode - S_IFDIR, o777) - var f2 = path.join(d1, 'f2.bin') + const f2 = path.join(d1, 'f2.bin') fs.writeFileSync(f2, '') fs.chmodSync(f2, o777) fs.chownSync(f2, process.getuid(), gidStaff) - var f2stats = fs.lstatSync(f2) + const f2stats = fs.lstatSync(f2) assert.strictEqual(f2stats.mode - S_IFREG, o777) - var d2 = path.join(srcDir, 'crazydir') + const d2 = path.join(srcDir, 'crazydir') fs.mkdirSync(d2) fs.chmodSync(d2, o444) fs.chownSync(d2, process.getuid(), gidWheel) - var d2stats = fs.lstatSync(d2) + const d2stats = fs.lstatSync(d2) assert.strictEqual(d2stats.mode - S_IFDIR, o444) - var destDir = path.join(permDir, 'dest') - fse.copy(srcDir, destDir, function (err) { + const destDir = path.join(permDir, 'dest') + fse.copy(srcDir, destDir, err => { assert.ifError(err) - var newf1stats = fs.lstatSync(path.join(permDir, 'dest/f1.txt')) - var newd1stats = fs.lstatSync(path.join(permDir, 'dest/somedir')) - var newf2stats = fs.lstatSync(path.join(permDir, 'dest/somedir/f2.bin')) - var newd2stats = fs.lstatSync(path.join(permDir, 'dest/crazydir')) + const newf1stats = fs.lstatSync(path.join(permDir, 'dest/f1.txt')) + const newd1stats = fs.lstatSync(path.join(permDir, 'dest/somedir')) + const newf2stats = fs.lstatSync(path.join(permDir, 'dest/somedir/f2.bin')) + const newd2stats = fs.lstatSync(path.join(permDir, 'dest/crazydir')) assert.strictEqual(newf1stats.mode, f1stats.mode) assert.strictEqual(newd1stats.mode, d1stats.mode) diff --git a/lib/copy/__tests__/copy-preserve-time.test.js b/lib/copy/__tests__/copy-preserve-time.test.js index 9de5e0cd..1c9fcb0d 100644 --- a/lib/copy/__tests__/copy-preserve-time.test.js +++ b/lib/copy/__tests__/copy-preserve-time.test.js @@ -1,42 +1,44 @@ -var assert = require('assert') -var fs = require('fs') -var os = require('os') -var path = require('path') -var copy = require('../copy') -var utimes = require('../../util/utimes') +'use strict' + +const fs = require('fs') +const os = require('os') +const path = require('path') +const copy = require('../copy') +const utimes = require('../../util/utimes') +const assert = require('assert') /* global beforeEach, describe, it */ -describe('copy', function () { - var TEST_DIR +describe('copy', () => { + let TEST_DIR - beforeEach(function (done) { + beforeEach(done => { TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'copy') require(process.cwd()).emptyDir(TEST_DIR, done) }) - describe('> modification option', function () { - var SRC_FIXTURES_DIR = path.join(__dirname, '/fixtures') - var FILES = ['a-file', path.join('a-folder', 'another-file'), path.join('a-folder', 'another-folder', 'file3')] + describe('> modification option', () => { + const SRC_FIXTURES_DIR = path.join(__dirname, '/fixtures') + const FILES = ['a-file', path.join('a-folder', 'another-file'), path.join('a-folder', 'another-folder', 'file3')] - describe('> when modified option is turned off', function () { - it('should have different timestamps on copy', function (done) { - var from = path.join(SRC_FIXTURES_DIR) - var to = path.join(TEST_DIR) + describe('> when modified option is turned off', () => { + it('should have different timestamps on copy', done => { + const from = path.join(SRC_FIXTURES_DIR) + const to = path.join(TEST_DIR) - copy(from, to, {preserveTimestamps: false}, function () { + copy(from, to, {preserveTimestamps: false}, () => { FILES.forEach(testFile({preserveTimestamps: false})) done() }) }) }) - describe('> when modified option is turned on', function () { - it('should have the same timestamps on copy', function (done) { - var from = path.join(SRC_FIXTURES_DIR) - var to = path.join(TEST_DIR) + describe('> when modified option is turned on', () => { + it('should have the same timestamps on copy', done => { + const from = path.join(SRC_FIXTURES_DIR) + const to = path.join(TEST_DIR) - copy(from, to, {preserveTimestamps: true}, function () { + copy(from, to, {preserveTimestamps: true}, () => { FILES.forEach(testFile({preserveTimestamps: true})) done() }) @@ -45,10 +47,10 @@ describe('copy', function () { function testFile (options) { return function (file) { - var a = path.join(SRC_FIXTURES_DIR, file) - var b = path.join(TEST_DIR, file) - var fromStat = fs.statSync(a) - var toStat = fs.statSync(b) + const a = path.join(SRC_FIXTURES_DIR, file) + const b = path.join(TEST_DIR, file) + const fromStat = fs.statSync(a) + const toStat = fs.statSync(b) if (options.preserveTimestamps) { // https://github.com/nodejs/io.js/issues/2069 if (process.platform !== 'win32') { diff --git a/lib/copy/__tests__/copy.test.js b/lib/copy/__tests__/copy.test.js index 5c1efbcd..44695974 100644 --- a/lib/copy/__tests__/copy.test.js +++ b/lib/copy/__tests__/copy.test.js @@ -1,44 +1,46 @@ -var assert = require('assert') -var crypto = require('crypto') -var fs = require('fs') -var os = require('os') -var path = require('path') -var fse = require('../../') +'use strict' + +const fs = require('fs') +const os = require('os') +const fse = require('../../') +const path = require('path') +const assert = require('assert') +const crypto = require('crypto') /* global afterEach, beforeEach, describe, it */ -var SIZE = 16 * 64 * 1024 + 7 -var TEST_DIR = '' +const SIZE = 16 * 64 * 1024 + 7 +let TEST_DIR = '' -describe('fs-extra', function () { - beforeEach(function (done) { +describe('fs-extra', () => { + beforeEach(done => { TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'copy') fse.emptyDir(TEST_DIR, done) }) - afterEach(function (done) { + afterEach(done => { fse.remove(TEST_DIR, done) }) - describe('+ copy()', function () { - it('should return an error if src and dest are the same', function (done) { - var fileSrc = path.join(TEST_DIR, 'TEST_fs-extra_copy') - var fileDest = path.join(TEST_DIR, 'TEST_fs-extra_copy') - fse.copy(fileSrc, fileDest, function (err) { + describe('+ copy()', () => { + it('should return an error if src and dest are the same', done => { + const fileSrc = path.join(TEST_DIR, 'TEST_fs-extra_copy') + const fileDest = path.join(TEST_DIR, 'TEST_fs-extra_copy') + fse.copy(fileSrc, fileDest, err => { assert.equal(err.message, 'Source and destination must not be the same.') done() }) }) - describe('> when the source is a file', function () { - it('should copy the file asynchronously', function (done) { - var fileSrc = path.join(TEST_DIR, 'TEST_fs-extra_src') - var fileDest = path.join(TEST_DIR, 'TEST_fs-extra_copy') + describe('> when the source is a file', () => { + it('should copy the file asynchronously', done => { + const fileSrc = path.join(TEST_DIR, 'TEST_fs-extra_src') + const fileDest = path.join(TEST_DIR, 'TEST_fs-extra_copy') fs.writeFileSync(fileSrc, crypto.randomBytes(SIZE)) - var srcMd5 = crypto.createHash('md5').update(fs.readFileSync(fileSrc)).digest('hex') - var destMd5 = '' + const srcMd5 = crypto.createHash('md5').update(fs.readFileSync(fileSrc)).digest('hex') + let destMd5 = '' - fse.copy(fileSrc, fileDest, function (err) { + fse.copy(fileSrc, fileDest, err => { assert(!err) destMd5 = crypto.createHash('md5').update(fs.readFileSync(fileDest)).digest('hex') assert.strictEqual(srcMd5, destMd5) @@ -46,60 +48,61 @@ describe('fs-extra', function () { }) }) - it('should return an error if the source file does not exist', function (done) { - var fileSrc = 'we-simply-assume-this-file-does-not-exist.bin' - var fileDest = path.join(TEST_DIR, 'TEST_fs-extra_copy') + it('should return an error if the source file does not exist', done => { + const fileSrc = 'we-simply-assume-this-file-does-not-exist.bin' + const fileDest = path.join(TEST_DIR, 'TEST_fs-extra_copy') - fse.copy(fileSrc, fileDest, function (err) { + fse.copy(fileSrc, fileDest, err => { assert(err) done() }) }) - it('should only copy files allowed by filter fn', function (done) { - var srcFile1 = path.join(TEST_DIR, '1.css') + it('should only copy files allowed by filter fn', done => { + const srcFile1 = path.join(TEST_DIR, '1.css') fs.writeFileSync(srcFile1, '') - var destFile1 = path.join(TEST_DIR, 'dest1.css') - var filter = function (s) { return s.split('.').pop() !== 'css' } - fse.copy(srcFile1, destFile1, filter, function () { + const destFile1 = path.join(TEST_DIR, 'dest1.css') + const filter = s => s.split('.').pop() !== 'css' + fse.copy(srcFile1, destFile1, filter, () => { assert(!fs.existsSync(destFile1)) done() }) }) - it('accepts options object in place of filter', function (done) { - var srcFile1 = path.join(TEST_DIR, '1.jade') + it('accepts options object in place of filter', done => { + const srcFile1 = path.join(TEST_DIR, '1.jade') fs.writeFileSync(srcFile1, '') - var destFile1 = path.join(TEST_DIR, 'dest1.jade') - var options = {filter: function (s) { return /.html$|.css$/i.test(s) }} - fse.copy(srcFile1, destFile1, options, function () { + const destFile1 = path.join(TEST_DIR, 'dest1.jade') + const options = { filter: s => /.html$|.css$/i.test(s) } + fse.copy(srcFile1, destFile1, options, () => { assert(!fs.existsSync(destFile1)) done() }) }) - it('should copy to a destination file with two \'$\' characters in name (eg: TEST_fs-extra_$$_copy)', function (done) { - var fileSrc = path.join(TEST_DIR, 'TEST_fs-extra_src') - var fileDest = path.join(TEST_DIR, 'TEST_fs-extra_$$_copy') + it('should copy to a destination file with two \'$\' characters in name (eg: TEST_fs-extra_$$_copy)', done => { + const fileSrc = path.join(TEST_DIR, 'TEST_fs-extra_src') + const fileDest = path.join(TEST_DIR, 'TEST_fs-extra_$$_copy') + fs.writeFileSync(fileSrc, '') - fse.copy(fileSrc, fileDest, function (err) { + fse.copy(fileSrc, fileDest, err => { assert(!err) fs.statSync(fileDest) done() }) }) - describe('> when the destination dir does not exist', function () { - it('should create the destination directory and copy the file', function (done) { - var src = path.join(TEST_DIR, 'file.txt') - var dest = path.join(TEST_DIR, 'this/path/does/not/exist/copied.txt') - var data = 'did it copy?\n' + describe('> when the destination dir does not exist', () => { + it('should create the destination directory and copy the file', done => { + const src = path.join(TEST_DIR, 'file.txt') + const dest = path.join(TEST_DIR, 'this/path/does/not/exist/copied.txt') + const data = 'did it copy?\n' fs.writeFileSync(src, data, 'utf8') - fse.copy(src, dest, function (err) { - var data2 = fs.readFileSync(dest, 'utf8') + fse.copy(src, dest, err => { + const data2 = fs.readFileSync(dest, 'utf8') assert.strictEqual(data, data2) done(err) }) @@ -107,46 +110,46 @@ describe('fs-extra', function () { }) }) - describe('> when the source is a directory', function () { - describe('> when the source directory does not exist', function () { - it('should return an error', function (done) { - var ts = path.join(TEST_DIR, 'this_dir_does_not_exist') - var td = path.join(TEST_DIR, 'this_dir_really_does_not_matter') - fse.copy(ts, td, function (err) { + describe('> when the source is a directory', () => { + describe('> when the source directory does not exist', () => { + it('should return an error', done => { + const ts = path.join(TEST_DIR, 'this_dir_does_not_exist') + const td = path.join(TEST_DIR, 'this_dir_really_does_not_matter') + fse.copy(ts, td, err => { assert(err) done() }) }) }) - it('should copy the directory asynchronously', function (done) { - var FILES = 2 - var src = path.join(TEST_DIR, 'src') - var dest = path.join(TEST_DIR, 'dest') + it('should copy the directory asynchronously', done => { + const FILES = 2 + const src = path.join(TEST_DIR, 'src') + const dest = path.join(TEST_DIR, 'dest') - fse.mkdirs(src, function (err) { + fse.mkdirs(src, err => { assert(!err) - for (var i = 0; i < FILES; ++i) { + for (let i = 0; i < FILES; ++i) { fs.writeFileSync(path.join(src, i.toString()), crypto.randomBytes(SIZE)) } - var subdir = path.join(src, 'subdir') - fse.mkdirs(subdir, function (err) { + const subdir = path.join(src, 'subdir') + fse.mkdirs(subdir, err => { assert(!err) - for (var i = 0; i < FILES; ++i) { + for (let i = 0; i < FILES; ++i) { fs.writeFileSync(path.join(subdir, i.toString()), crypto.randomBytes(SIZE)) } - fse.copy(src, dest, function (err) { + fse.copy(src, dest, err => { assert.ifError(err) assert(fs.existsSync(dest)) - for (var i = 0; i < FILES; ++i) { + for (let i = 0; i < FILES; ++i) { assert(fs.existsSync(path.join(dest, i.toString()))) } - var destSub = path.join(dest, 'subdir') - for (var j = 0; j < FILES; ++j) { + const destSub = path.join(dest, 'subdir') + for (let j = 0; j < FILES; ++j) { assert(fs.existsSync(path.join(destSub, j.toString()))) } @@ -156,21 +159,21 @@ describe('fs-extra', function () { }) }) - describe('> when the destination dir does not exist', function () { - it('should create the destination directory and copy the file', function (done) { - var src = path.join(TEST_DIR, 'data/') + describe('> when the destination dir does not exist', () => { + it('should create the destination directory and copy the file', done => { + const src = path.join(TEST_DIR, 'data/') fse.mkdirsSync(src) - var d1 = 'file1' - var d2 = 'file2' + const d1 = 'file1' + const d2 = 'file2' fs.writeFileSync(path.join(src, 'f1.txt'), d1) fs.writeFileSync(path.join(src, 'f2.txt'), d2) - var dest = path.join(TEST_DIR, 'this/path/does/not/exist/outputDir') + const dest = path.join(TEST_DIR, 'this/path/does/not/exist/outputDir') - fse.copy(src, dest, function (err) { - var o1 = fs.readFileSync(path.join(dest, 'f1.txt'), 'utf8') - var o2 = fs.readFileSync(path.join(dest, 'f2.txt'), 'utf8') + fse.copy(src, dest, err => { + const o1 = fs.readFileSync(path.join(dest, 'f1.txt'), 'utf8') + const o2 = fs.readFileSync(path.join(dest, 'f2.txt'), 'utf8') assert.strictEqual(d1, o1) assert.strictEqual(d2, o2) @@ -180,9 +183,9 @@ describe('fs-extra', function () { }) }) - describe('> when src dir does not exist', function () { - it('should return an error', function (done) { - fse.copy('/does/not/exist', '/something/else', function (err) { + describe('> when src dir does not exist', () => { + it('should return an error', done => { + fse.copy('/does/not/exist', '/something/else', err => { assert(err instanceof Error) done() }) diff --git a/lib/copy/__tests__/ncp/broken-symlink.test.js b/lib/copy/__tests__/ncp/broken-symlink.test.js index 33b0d435..781ac6d9 100644 --- a/lib/copy/__tests__/ncp/broken-symlink.test.js +++ b/lib/copy/__tests__/ncp/broken-symlink.test.js @@ -1,38 +1,38 @@ -var assert = require('assert') -var fs = require('fs') -var path = require('path') -var os = require('os') -var fse = require(process.cwd()) -var ncp = require('../../ncp') +'use strict' + +const fs = require('fs') +const os = require('os') +const fse = require(process.cwd()) +const ncp = require('../../ncp') +const path = require('path') +const assert = require('assert') /* global afterEach, beforeEach, describe, it */ describe('ncp broken symlink', function () { - var TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'ncp-broken-symlinks') - var src = path.join(TEST_DIR, 'src') - var out = path.join(TEST_DIR, 'out') + const TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'ncp-broken-symlinks') + const src = path.join(TEST_DIR, 'src') + const out = path.join(TEST_DIR, 'out') - beforeEach(function (done) { - fse.emptyDir(TEST_DIR, function (err) { + beforeEach(done => { + fse.emptyDir(TEST_DIR, err => { assert.ifError(err) createFixtures(src, done) }) }) - afterEach(function (done) { - fse.remove(TEST_DIR, done) - }) + afterEach(done => fse.remove(TEST_DIR, done)) - it('should copy broken symlinks by default', function (done) { - ncp(src, out, function (err) { + it('should copy broken symlinks by default', done => { + ncp(src, out, err => { if (err) return done(err) assert.equal(fs.readlinkSync(path.join(out, 'broken-symlink')), path.join(src, 'does-not-exist')) done() }) }) - it('should return an error when dereference=true', function (done) { - ncp(src, out, {dereference: true}, function (err) { + it('should return an error when dereference=true', done => { + ncp(src, out, {dereference: true}, err => { assert.equal(err.code, 'ENOENT') done() }) @@ -40,12 +40,15 @@ describe('ncp broken symlink', function () { }) function createFixtures (srcDir, callback) { - fs.mkdir(srcDir, function (err) { + fs.mkdir(srcDir, err => { + let brokenFile + let brokenFileLink + if (err) return callback(err) try { - var brokenFile = path.join(srcDir, 'does-not-exist') - var brokenFileLink = path.join(srcDir, 'broken-symlink') + brokenFile = path.join(srcDir, 'does-not-exist') + brokenFileLink = path.join(srcDir, 'broken-symlink') fs.writeFileSync(brokenFile, 'does not matter') fs.symlinkSync(brokenFile, brokenFileLink, 'file') } catch (err) { diff --git a/lib/copy/__tests__/ncp/ncp-error-perm.test.js b/lib/copy/__tests__/ncp/ncp-error-perm.test.js index 50389598..451bbdf7 100644 --- a/lib/copy/__tests__/ncp/ncp-error-perm.test.js +++ b/lib/copy/__tests__/ncp/ncp-error-perm.test.js @@ -1,11 +1,13 @@ +'use strict' + // file in reference: https://github.com/jprichardson/node-fs-extra/issues/56 -var assert = require('assert') -var fs = require('fs') -var path = require('path') -var os = require('os') -var fse = require(process.cwd()) -var ncp = require('../../ncp') +const fs = require('fs') +const os = require('os') +const fse = require(process.cwd()) +const ncp = require('../../ncp') +const path = require('path') +const assert = require('assert') /* global afterEach, beforeEach, describe, it */ @@ -14,34 +16,32 @@ var ncp = require('../../ncp') // if (os.platform().indexOf('win') === 0) return // eslint-enable globalReturn */ -describe('ncp / error / dest-permission', function () { - var TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'ncp-error-dest-perm') - var src = path.join(TEST_DIR, 'src') - var dest = path.join(TEST_DIR, 'dest') +describe('ncp / error / dest-permission', () => { + const TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'ncp-error-dest-perm') + const src = path.join(TEST_DIR, 'src') + const dest = path.join(TEST_DIR, 'dest') if (os.platform().indexOf('win') === 0) return - beforeEach(function (done) { - fse.emptyDir(TEST_DIR, function (err) { + beforeEach(done => { + fse.emptyDir(TEST_DIR, err => { assert.ifError(err) done() }) }) - afterEach(function (done) { - fse.remove(TEST_DIR, done) - }) + afterEach(done => fse.remove(TEST_DIR, done)) - it('should return an error', function (done) { - var someFile = path.join(src, 'some-file') + it('should return an error', done => { + const someFile = path.join(src, 'some-file') fse.outputFileSync(someFile, 'hello') fse.mkdirsSync(dest) fs.chmodSync(dest, parseInt('444', 8)) - var subdest = path.join(dest, 'another-dir') + const subdest = path.join(dest, 'another-dir') - ncp(src, subdest, function (err) { + ncp(src, subdest, err => { assert(err) assert.equal(err.code, 'EACCES') done() diff --git a/lib/copy/__tests__/ncp/ncp.test.js b/lib/copy/__tests__/ncp/ncp.test.js index acb0f421..23ad3fcc 100644 --- a/lib/copy/__tests__/ncp/ncp.test.js +++ b/lib/copy/__tests__/ncp/ncp.test.js @@ -1,30 +1,28 @@ -var assert = require('assert') -var fs = require('fs') -var path = require('path') -var rimraf = require('rimraf') -var readDirFiles = require('read-dir-files').read // temporary, will remove -var ncp = require('../../ncp') +'use strict' + +const fs = require('fs') +const ncp = require('../../ncp') +const path = require('path') +const rimraf = require('rimraf') +const assert = require('assert') +const readDirFiles = require('read-dir-files').read // temporary, will remove /* eslint-env mocha */ -var fixturesDir = path.join(__dirname, 'fixtures') +const fixturesDir = path.join(__dirname, 'fixtures') -describe('ncp', function () { - describe('regular files and directories', function () { - var fixtures = path.join(fixturesDir, 'regular-fixtures') - var src = path.join(fixtures, 'src') - var out = path.join(fixtures, 'out') +describe('ncp', () => { + describe('regular files and directories', () => { + const fixtures = path.join(fixturesDir, 'regular-fixtures') + const src = path.join(fixtures, 'src') + const out = path.join(fixtures, 'out') - before(function (cb) { - rimraf(out, function () { - ncp(src, out, cb) - }) - }) + before(cb => rimraf(out, () => ncp(src, out, cb))) - describe('when copying a directory of files', function () { - it('files are copied correctly', function (cb) { - readDirFiles(src, 'utf8', function (srcErr, srcFiles) { - readDirFiles(out, 'utf8', function (outErr, outFiles) { + describe('when copying a directory of files', () => { + it('files are copied correctly', cb => { + readDirFiles(src, 'utf8', (srcErr, srcFiles) => { + readDirFiles(out, 'utf8', (outErr, outFiles) => { assert.ifError(srcErr) assert.deepEqual(srcFiles, outFiles) cb() @@ -33,21 +31,18 @@ describe('ncp', function () { }) }) - describe('when copying files using filter', function () { - before(function (cb) { - var filter = function (name) { - return name.substr(name.length - 1) !== 'a' - } - rimraf(out, function () { - ncp(src, out, {filter: filter}, cb) - }) + describe('when copying files using filter', () => { + before(cb => { + const filter = name => name.substr(name.length - 1) !== 'a' + + rimraf(out, () => ncp(src, out, { filter }, cb)) }) - it('files are copied correctly', function (cb) { - readDirFiles(src, 'utf8', function (srcErr, srcFiles) { + it('files are copied correctly', cb => { + readDirFiles(src, 'utf8', (srcErr, srcFiles) => { function filter (files) { - for (var fileName in files) { - var curFile = files[fileName] + for (let fileName in files) { + const curFile = files[fileName] if (curFile instanceof Object) { return filter(curFile) } @@ -58,7 +53,7 @@ describe('ncp', function () { } } filter(srcFiles) - readDirFiles(out, 'utf8', function (outErr, outFiles) { + readDirFiles(out, 'utf8', (outErr, outFiles) => { assert.ifError(outErr) assert.deepEqual(srcFiles, outFiles) cb() @@ -67,7 +62,7 @@ describe('ncp', function () { }) }) - describe('when using overwrite=true', function () { + describe('when using overwrite=true', () => { before(function () { this.originalCreateReadStream = fs.createReadStream }) @@ -76,41 +71,41 @@ describe('ncp', function () { fs.createReadStream = this.originalCreateReadStream }) - it('the copy is complete after callback', function (done) { - ncp(src, out, {overwrite: true}, function (err) { - fs.createReadStream = function () { - done(new Error('createReadStream after callback')) - } + it('the copy is complete after callback', done => { + ncp(src, out, {overwrite: true}, err => { + fs.createReadStream = () => done(new Error('createReadStream after callback')) + assert.ifError(err) process.nextTick(done) }) }) }) - describe('when using overwrite=false', function () { - beforeEach(function (done) { - rimraf(out, done) - }) - it('works', function (cb) { - ncp(src, out, {overwrite: false}, function (err) { + describe('when using overwrite=false', () => { + beforeEach(done => rimraf(out, done)) + + it('works', cb => { + ncp(src, out, {overwrite: false}, err => { assert.ifError(err) cb() }) }) - it('should not error if files exist', function (cb) { - ncp(src, out, function () { - ncp(src, out, {overwrite: false}, function (err) { + + it('should not error if files exist', cb => { + ncp(src, out, () => { + ncp(src, out, {overwrite: false}, err => { assert.ifError(err) cb() }) }) }) - it('should error if errorOnExist and file exists', function (cb) { - ncp(src, out, function () { + + it('should error if errorOnExist and file exists', cb => { + ncp(src, out, () => { ncp(src, out, { overwrite: false, errorOnExist: true - }, function (err) { + }, err => { assert(err) cb() }) @@ -118,17 +113,15 @@ describe('ncp', function () { }) }) - describe('clobber', function () { - beforeEach(function (done) { - rimraf(out, done) - }) + describe('clobber', () => { + beforeEach(done => rimraf(out, done)) - it('is an alias for overwrite', function (cb) { - ncp(src, out, function () { + it('is an alias for overwrite', cb => { + ncp(src, out, () => { ncp(src, out, { clobber: false, errorOnExist: true - }, function (err) { + }, err => { assert(err) cb() }) @@ -136,10 +129,10 @@ describe('ncp', function () { }) }) - describe('when using transform', function () { - it('file descriptors are passed correctly', function (cb) { + describe('when using transform', () => { + it('file descriptors are passed correctly', cb => { ncp(src, out, { - transform: function (read, write, file) { + transform: (read, write, file) => { assert.notEqual(file.name, undefined) assert.strictEqual(typeof file.mode, 'number') read.pipe(write) @@ -150,20 +143,20 @@ describe('ncp', function () { }) // see https://github.com/AvianFlu/ncp/issues/71 - describe('Issue 71: Odd Async Behaviors', function (cb) { - var fixtures = path.join(__dirname, 'fixtures', 'regular-fixtures') - var src = path.join(fixtures, 'src') - var out = path.join(fixtures, 'out') + describe('Issue 71: Odd Async Behaviors', cb => { + const fixtures = path.join(__dirname, 'fixtures', 'regular-fixtures') + const src = path.join(fixtures, 'src') + const out = path.join(fixtures, 'out') - var totalCallbacks = 0 + let totalCallbacks = 0 function copyAssertAndCount (callback) { // rimraf(out, function() { - ncp(src, out, function (err) { + ncp(src, out, err => { assert(!err) totalCallbacks += 1 - readDirFiles(src, 'utf8', function (srcErr, srcFiles) { - readDirFiles(out, 'utf8', function (outErr, outFiles) { + readDirFiles(src, 'utf8', (srcErr, srcFiles) => { + readDirFiles(out, 'utf8', (outErr, outFiles) => { assert.ifError(srcErr) assert.deepEqual(srcFiles, outFiles) callback() @@ -173,15 +166,15 @@ describe('ncp', function () { // }) } - describe('when copying a directory of files without cleaning the destination', function () { - it('callback fires once per run and directories are equal', function (done) { - var expected = 10 - var count = 10 + describe('when copying a directory of files without cleaning the destination', () => { + it('callback fires once per run and directories are equal', done => { + const expected = 10 + let count = 10 function next () { if (count > 0) { - setTimeout(function () { - copyAssertAndCount(function () { + setTimeout(() => { + copyAssertAndCount(() => { count -= 1 next() }) diff --git a/lib/copy/__tests__/ncp/symlink.test.js b/lib/copy/__tests__/ncp/symlink.test.js index 3315a1cf..1b8816b6 100644 --- a/lib/copy/__tests__/ncp/symlink.test.js +++ b/lib/copy/__tests__/ncp/symlink.test.js @@ -1,30 +1,30 @@ -var assert = require('assert') -var fs = require('fs') -var path = require('path') -var os = require('os') -var fse = require(process.cwd()) -var ncp = require('../../ncp') +'use strict' + +const fs = require('fs') +const os = require('os') +const fse = require(process.cwd()) +const ncp = require('../../ncp') +const path = require('path') +const assert = require('assert') /* global afterEach, beforeEach, describe, it */ -describe('ncp / symlink', function () { - var TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'ncp-symlinks') - var src = path.join(TEST_DIR, 'src') - var out = path.join(TEST_DIR, 'out') +describe('ncp / symlink', () => { + const TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'ncp-symlinks') + const src = path.join(TEST_DIR, 'src') + const out = path.join(TEST_DIR, 'out') - beforeEach(function (done) { - fse.emptyDir(TEST_DIR, function (err) { + beforeEach(done => { + fse.emptyDir(TEST_DIR, err => { assert.ifError(err) createFixtures(src, done) }) }) - afterEach(function (done) { - fse.remove(TEST_DIR, done) - }) + afterEach(done => fse.remove(TEST_DIR, done)) - it('copies symlinks by default', function (done) { - ncp(src, out, function (err) { + it('copies symlinks by default', done => { + ncp(src, out, err => { assert.ifError(err) assert.equal(fs.readlinkSync(path.join(out, 'file-symlink')), path.join(src, 'foo')) @@ -34,15 +34,15 @@ describe('ncp / symlink', function () { }) }) - it('copies file contents when dereference=true', function (done) { - ncp(src, out, {dereference: true}, function (err) { + it('copies file contents when dereference=true', done => { + ncp(src, out, {dereference: true}, err => { assert.ifError(err) - var fileSymlinkPath = path.join(out, 'file-symlink') + const fileSymlinkPath = path.join(out, 'file-symlink') assert.ok(fs.lstatSync(fileSymlinkPath).isFile()) assert.equal(fs.readFileSync(fileSymlinkPath), 'foo contents') - var dirSymlinkPath = path.join(out, 'dir-symlink') + const dirSymlinkPath = path.join(out, 'dir-symlink') assert.ok(fs.lstatSync(dirSymlinkPath).isDirectory()) assert.deepEqual(fs.readdirSync(dirSymlinkPath), ['bar']) @@ -52,20 +52,20 @@ describe('ncp / symlink', function () { }) function createFixtures (srcDir, callback) { - fs.mkdir(srcDir, function (err) { + fs.mkdir(srcDir, err => { if (err) return callback(err) // note: third parameter in symlinkSync is type e.g. 'file' or 'dir' // https://nodejs.org/api/fs.html#fs_fs_symlink_srcpath_dstpath_type_callback try { - var fooFile = path.join(srcDir, 'foo') - var fooFileLink = path.join(srcDir, 'file-symlink') + const fooFile = path.join(srcDir, 'foo') + const fooFileLink = path.join(srcDir, 'file-symlink') fs.writeFileSync(fooFile, 'foo contents') fs.symlinkSync(fooFile, fooFileLink, 'file') - var dir = path.join(srcDir, 'dir') - var dirFile = path.join(dir, 'bar') - var dirLink = path.join(srcDir, 'dir-symlink') + const dir = path.join(srcDir, 'dir') + const dirFile = path.join(dir, 'bar') + const dirLink = path.join(srcDir, 'dir-symlink') fs.mkdirSync(dir) fs.writeFileSync(dirFile, 'bar contents') fs.symlinkSync(dir, dirLink, 'dir')