diff --git a/lib/copy-sync/__tests__/copy-sync-preserve-timestamp.test.js b/lib/copy-sync/__tests__/copy-sync-preserve-timestamp.test.js index da3aacac..6612b3c9 100644 --- a/lib/copy-sync/__tests__/copy-sync-preserve-timestamp.test.js +++ b/lib/copy-sync/__tests__/copy-sync-preserve-timestamp.test.js @@ -3,6 +3,7 @@ const fs = require('../../') const os = require('os') const path = require('path') +const copySync = require('../copy-sync') const utimesSync = require('../../util/utimes').utimesMillisSync const assert = require('assert') const semver = require('semver') @@ -48,7 +49,7 @@ describeIfPractical('copySync() - preserveTimestamps option', () => { beforeEach(() => setupFixture(params.readonly)) it('should have the same timestamps on copy', () => { - fs.copySync(SRC, DEST, { preserveTimestamps: true }) + copySync(SRC, DEST, { preserveTimestamps: true }) FILES.forEach(testFile({ preserveTimestamps: true })) }) }) @@ -63,10 +64,10 @@ describeIfPractical('copySync() - preserveTimestamps option', () => { const toStat = fs.statSync(b) if (options.preserveTimestamps) { // Windows sub-second precision fixed: https://github.com/nodejs/io.js/issues/2069 - assert.strictEqual(toStat.mtime.getTime(), fromStat.mtime.getTime()) - assert.strictEqual(toStat.atime.getTime(), fromStat.atime.getTime()) + assert.strictEqual(toStat.mtime.getTime(), fromStat.mtime.getTime(), 'different mtime values') + assert.strictEqual(toStat.atime.getTime(), fromStat.atime.getTime(), 'different atime values') } else { - assert.notStrictEqual(toStat.mtime.getTime(), fromStat.mtime.getTime()) + assert.notStrictEqual(toStat.mtime.getTime(), fromStat.mtime.getTime(), 'same mtime values') // the access time might actually be the same, so check only modification time } } diff --git a/lib/copy-sync/__tests__/copyfilesync-fallback.test.js b/lib/copy-sync/__tests__/copyfilesync-fallback.test.js index f6bdb269..7a619a3f 100644 --- a/lib/copy-sync/__tests__/copyfilesync-fallback.test.js +++ b/lib/copy-sync/__tests__/copyfilesync-fallback.test.js @@ -1,26 +1,25 @@ -const fs = require('fs') +const fs = require('../../') const path = require('path') -/* global after, describe */ +/* global describe */ if (typeof fs.copyFileSync === 'function') { - // Re-run all copySync tests without fs.copyFileSync + // Also load copy-sync tests without fs.copyFileSync describe('> when using copyFileSyncFallback', () => { const originalCopyFile = fs.copyFileSync - after(done => { - fs.copyFileSync = originalCopyFile - done() - }) - delete fs.copyFileSync const fallbackTest = path.basename(__filename) - fs.readdirSync(__dirname) - .filter(filename => filename.endsWith('.test.js') && filename !== fallbackTest) - .map(filename => { - const testModule = `./${filename}` - delete require.cache[require.resolve(testModule)] - require(testModule) - }) + try { + fs.readdirSync(__dirname) + .filter(filename => filename.endsWith('.test.js') && filename !== fallbackTest) + .map(filename => { + const testModule = `./${filename}` + delete require.cache[require.resolve(testModule)] + require(testModule) + }) + } finally { + fs.copyFileSync = originalCopyFile + } }) } diff --git a/lib/copy/__tests__/copy-preserve-timestamp.test.js b/lib/copy/__tests__/copy-preserve-timestamp.test.js index 6fd0b173..5447e706 100644 --- a/lib/copy/__tests__/copy-preserve-timestamp.test.js +++ b/lib/copy/__tests__/copy-preserve-timestamp.test.js @@ -67,10 +67,10 @@ describeIfPractical('copy() - preserve timestamp', () => { const toStat = fs.statSync(b) if (options.preserveTimestamps) { // Windows sub-second precision fixed: https://github.com/nodejs/io.js/issues/2069 - assert.strictEqual(toStat.mtime.getTime(), fromStat.mtime.getTime()) - assert.strictEqual(toStat.atime.getTime(), fromStat.atime.getTime()) + assert.strictEqual(toStat.mtime.getTime(), fromStat.mtime.getTime(), 'different mtime values') + assert.strictEqual(toStat.atime.getTime(), fromStat.atime.getTime(), 'different atime values') } else { - assert.notStrictEqual(toStat.mtime.getTime(), fromStat.mtime.getTime()) + assert.notStrictEqual(toStat.mtime.getTime(), fromStat.mtime.getTime(), 'same mtime values') // the access time might actually be the same, so check only modification time } } diff --git a/lib/copy/__tests__/copyfile-fallback.test.js b/lib/copy/__tests__/copyfile-fallback.test.js index 45979494..d32d57ba 100644 --- a/lib/copy/__tests__/copyfile-fallback.test.js +++ b/lib/copy/__tests__/copyfile-fallback.test.js @@ -1,26 +1,25 @@ -const fs = require('fs') +const fs = require('../../') const path = require('path') -/* global after, describe */ +/* global describe */ if (typeof fs.copyFile === 'function') { - // Re-run all copy tests without fs.copyFile + // Also load copy tests without fs.copyFile describe('> when using copyFileFallback', () => { const originalCopyFile = fs.copyFile - after(done => { - fs.copyFile = originalCopyFile - done() - }) - delete fs.copyFile const fallbackTest = path.basename(__filename) - fs.readdirSync(__dirname) - .filter(filename => filename.endsWith('.test.js') && filename !== fallbackTest) - .map(filename => { - const testModule = `./${filename}` - delete require.cache[require.resolve(testModule)] - require(testModule) - }) + try { + fs.readdirSync(__dirname) + .filter(filename => filename.endsWith('.test.js') && filename !== fallbackTest) + .map(filename => { + const testModule = `./${filename}` + delete require.cache[require.resolve(testModule)] + require(testModule) + }) + } finally { + fs.copyFile = originalCopyFile + } }) }