mirror of
https://github.com/jprichardson/node-fs-extra.git
synced 2026-01-25 16:42:57 +00:00
lib/copy/__tests__: extracted preserve-time into own file
This commit is contained in:
parent
40c59c23e7
commit
bbd6c996f7
61
lib/copy/__tests__/copy-preserve-time.test.js
Normal file
61
lib/copy/__tests__/copy-preserve-time.test.js
Normal file
@ -0,0 +1,61 @@
|
||||
var assert = require('assert')
|
||||
var fs = require('fs')
|
||||
var os = require('os')
|
||||
var path = require('path')
|
||||
var fse = require('../../')
|
||||
|
||||
/* global beforeEach, describe, it */
|
||||
|
||||
describe('copy', function () {
|
||||
var TEST_DIR
|
||||
|
||||
beforeEach(function (done) {
|
||||
TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'copy')
|
||||
fse.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('> 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)
|
||||
|
||||
fse.copy(from, to, {preserveTimestamps: false}, function () {
|
||||
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)
|
||||
|
||||
fse.copy(from, to, {preserveTimestamps: true}, function () {
|
||||
FILES.forEach(testFile({preserveTimestamps: true}))
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
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)
|
||||
if (options.preserveTimestamps) {
|
||||
assert.strictEqual(toStat.mtime.getTime(), fromStat.mtime.getTime())
|
||||
assert.strictEqual(toStat.atime.getTime(), fromStat.atime.getTime())
|
||||
} else {
|
||||
assert.notEqual(toStat.mtime.getTime(), fromStat.mtime.getTime())
|
||||
// the access time might actually be the same, so check only modification time
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
@ -179,50 +179,5 @@ describe('fs-extra', function () {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
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('> 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)
|
||||
|
||||
fse.copy(from, to, {preserveTimestamps: false}, function () {
|
||||
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)
|
||||
|
||||
fse.copy(from, to, {preserveTimestamps: true}, function () {
|
||||
FILES.forEach(testFile({preserveTimestamps: true}))
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
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)
|
||||
if (options.preserveTimestamps) {
|
||||
assert.strictEqual(toStat.mtime.getTime(), fromStat.mtime.getTime())
|
||||
assert.strictEqual(toStat.atime.getTime(), fromStat.atime.getTime())
|
||||
} else {
|
||||
assert.notEqual(toStat.mtime.getTime(), fromStat.mtime.getTime())
|
||||
// the access time might actually be the same, so check only modification time
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user