forked from jprichardson/node-fs-extra
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove copy test fixtures dir, refactor copy & copySync timestamp test
- Loading branch information
Showing
6 changed files
with
56 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,74 @@ | ||
'use strict' | ||
|
||
const fs = require('fs') | ||
const fs = require(process.cwd()) | ||
const os = require('os') | ||
const path = require('path') | ||
const copy = require('../copy') | ||
const utimes = require('../../util/utimes') | ||
const assert = require('assert') | ||
const nodeVersion = process.versions.node | ||
const nodeVersionMajor = parseInt(nodeVersion.split('.')[0], 10) | ||
|
||
/* global beforeEach, describe, it */ | ||
/* global beforeEach, afterEach, describe, it */ | ||
|
||
if (process.arch === 'ia32') console.warn('32 bit arch; skipping copy timestamp tests') | ||
if (nodeVersionMajor < 8) console.warn(`old node version (v${nodeVersion}); skipping copy timestamp tests`) | ||
|
||
const describeIf64 = process.arch === 'ia32' ? describe.skip : describe | ||
const describeIfPractical = (process.arch === 'ia32' || nodeVersionMajor < 8) ? describe.skip : describe | ||
|
||
describeIf64('copy', () => { | ||
let TEST_DIR | ||
describeIfPractical('copy() - preserve timestamp', () => { | ||
let TEST_DIR, SRC, DEST, FILES | ||
|
||
beforeEach(done => { | ||
TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'copy') | ||
require(process.cwd()).emptyDir(TEST_DIR, done) | ||
TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'copy-preserve-timestamp') | ||
SRC = path.join(TEST_DIR, 'src') | ||
DEST = path.join(TEST_DIR, 'dest') | ||
FILES = ['a-file', path.join('a-folder', 'another-file'), path.join('a-folder', 'another-folder', 'file3')] | ||
FILES.forEach(f => fs.ensureFileSync(path.join(SRC, f))) | ||
done() | ||
}) | ||
|
||
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')] | ||
afterEach(done => fs.remove(TEST_DIR, done)) | ||
|
||
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}, () => { | ||
describe('> when timestamp option is false', () => { | ||
it('should have different timestamps on copy', done => { | ||
setTimeout(() => { | ||
copy(SRC, DEST, {preserveTimestamps: false}, () => { | ||
FILES.forEach(testFile({preserveTimestamps: false})) | ||
done() | ||
}) | ||
}) | ||
}, 100) | ||
}) | ||
}) | ||
|
||
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}, () => { | ||
FILES.forEach(testFile({preserveTimestamps: true})) | ||
done() | ||
}) | ||
describe('> when timestamp option is true', () => { | ||
it('should have the same timestamps on copy', done => { | ||
copy(SRC, DEST, {preserveTimestamps: true}, () => { | ||
FILES.forEach(testFile({preserveTimestamps: true})) | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
function testFile (options) { | ||
return function (file) { | ||
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') { | ||
assert.strictEqual(toStat.mtime.getTime(), fromStat.mtime.getTime()) | ||
assert.strictEqual(toStat.atime.getTime(), fromStat.atime.getTime()) | ||
} else { | ||
assert.strictEqual(toStat.mtime.getTime(), utimes.timeRemoveMillis(fromStat.mtime.getTime())) | ||
assert.strictEqual(toStat.atime.getTime(), utimes.timeRemoveMillis(fromStat.atime.getTime())) | ||
} | ||
function testFile (options) { | ||
return function (file) { | ||
const a = path.join(SRC, file) | ||
const b = path.join(DEST, 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') { | ||
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 | ||
assert.strictEqual(toStat.mtime.getTime(), utimes.timeRemoveMillis(fromStat.mtime.getTime())) | ||
assert.strictEqual(toStat.atime.getTime(), utimes.timeRemoveMillis(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 | ||
} | ||
} | ||
}) | ||
} | ||
}) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.