From bbd6c996f7b0ca14bf15219b8445db91426d91fc Mon Sep 17 00:00:00 2001 From: JP Richardson Date: Fri, 26 Jun 2015 09:55:20 -0500 Subject: [PATCH] lib/copy/__tests__: extracted preserve-time into own file --- lib/copy/__tests__/copy-preserve-time.test.js | 61 +++++++++++++++++++ lib/copy/__tests__/copy.test.js | 45 -------------- 2 files changed, 61 insertions(+), 45 deletions(-) create mode 100644 lib/copy/__tests__/copy-preserve-time.test.js diff --git a/lib/copy/__tests__/copy-preserve-time.test.js b/lib/copy/__tests__/copy-preserve-time.test.js new file mode 100644 index 0000000..6e3dba2 --- /dev/null +++ b/lib/copy/__tests__/copy-preserve-time.test.js @@ -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 + } + } + } + }) +}) diff --git a/lib/copy/__tests__/copy.test.js b/lib/copy/__tests__/copy.test.js index 043c2e1..0f3c60d 100644 --- a/lib/copy/__tests__/copy.test.js +++ b/lib/copy/__tests__/copy.test.js @@ -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 - } - } - } - }) }) })