Skip to content

Commit

Permalink
Fix copy[Sync] fallback tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Bargiel committed Jul 31, 2019
1 parent 4828641 commit 2b7c0e5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 37 deletions.
9 changes: 5 additions & 4 deletions lib/copy-sync/__tests__/copy-sync-preserve-timestamp.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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 }))
})
})
Expand All @@ -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
}
}
Expand Down
29 changes: 14 additions & 15 deletions lib/copy-sync/__tests__/copyfilesync-fallback.test.js
Original file line number Diff line number Diff line change
@@ -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
}
})
}
6 changes: 3 additions & 3 deletions lib/copy/__tests__/copy-preserve-timestamp.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
29 changes: 14 additions & 15 deletions lib/copy/__tests__/copyfile-fallback.test.js
Original file line number Diff line number Diff line change
@@ -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
}
})
}

0 comments on commit 2b7c0e5

Please sign in to comment.