From c9404aa218ebb08f908a7c06d0b0ba776df9aeaf Mon Sep 17 00:00:00 2001 From: Joern Bernhardt Date: Mon, 22 Jun 2015 15:32:23 +0200 Subject: [PATCH] Move tests into lib/copy/__tests__ Signed-off-by: Joern Bernhardt --- lib/copy/__tests__/copy.test.js | 45 +++++++++ .../copy/__tests__}/fixtures/a-file | 0 .../__tests__}/fixtures/a-folder/another-file | 0 .../fixtures/a-folder/another-folder/file3 | 0 lib/copy/__tests__/sync/copy-sync.test.js | 44 +++++++++ test/copy/copy.test.js | 91 ------------------- 6 files changed, 89 insertions(+), 91 deletions(-) rename {test/copy => lib/copy/__tests__}/fixtures/a-file (100%) rename {test/copy => lib/copy/__tests__}/fixtures/a-folder/another-file (100%) rename {test/copy => lib/copy/__tests__}/fixtures/a-folder/another-folder/file3 (100%) delete mode 100644 test/copy/copy.test.js diff --git a/lib/copy/__tests__/copy.test.js b/lib/copy/__tests__/copy.test.js index 93cee39e..664a2939 100644 --- a/lib/copy/__tests__/copy.test.js +++ b/lib/copy/__tests__/copy.test.js @@ -184,6 +184,51 @@ 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.deepEqual(toStat.mtime, fromStat.mtime) + assert.deepEqual(toStat.atime, fromStat.atime) + } else { + assert.notEqual(toStat.mtime, fromStat.mtime) + assert.notEqual(toStat.atime, fromStat.atime) + } + } + } + }) + describe.skip('> REGRESSIONS', function () { // pretty UNIX specific, may not pass on windows... only test on Mac OS X 10.9 it('should maintain file permissions and ownership', function (done) { diff --git a/test/copy/fixtures/a-file b/lib/copy/__tests__/fixtures/a-file similarity index 100% rename from test/copy/fixtures/a-file rename to lib/copy/__tests__/fixtures/a-file diff --git a/test/copy/fixtures/a-folder/another-file b/lib/copy/__tests__/fixtures/a-folder/another-file similarity index 100% rename from test/copy/fixtures/a-folder/another-file rename to lib/copy/__tests__/fixtures/a-folder/another-file diff --git a/test/copy/fixtures/a-folder/another-folder/file3 b/lib/copy/__tests__/fixtures/a-folder/another-folder/file3 similarity index 100% rename from test/copy/fixtures/a-folder/another-folder/file3 rename to lib/copy/__tests__/fixtures/a-folder/another-folder/file3 diff --git a/lib/copy/__tests__/sync/copy-sync.test.js b/lib/copy/__tests__/sync/copy-sync.test.js index f4be31ab..4dbcaca0 100644 --- a/lib/copy/__tests__/sync/copy-sync.test.js +++ b/lib/copy/__tests__/sync/copy-sync.test.js @@ -301,4 +301,48 @@ describe('+ copySync()', 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) + + fs.copySync(from, TEST_DIR, {preserveTimestamps: false}) + + 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) + + fs.copySync(from, TEST_DIR, {preserveTimestamps: true}) + + 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.deepEqual(toStat.mtime, fromStat.mtime) + assert.deepEqual(toStat.atime, fromStat.atime) + } else { + assert.notEqual(toStat.mtime, fromStat.mtime) + assert.notEqual(toStat.atime, fromStat.atime) + } + } + } + }) }) diff --git a/test/copy/copy.test.js b/test/copy/copy.test.js deleted file mode 100644 index 455cd209..00000000 --- a/test/copy/copy.test.js +++ /dev/null @@ -1,91 +0,0 @@ -var assert = require('assert') -var fs = require('fs') -var path = require('path') -var os = require('os') -var fse = require(process.cwd()) - -/* global afterEach, beforeEach, describe, it */ - -describe('fs-extra', function () { - var TEST_DIR - 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')] - - beforeEach(function (done) { - TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'copy') - fse.emptyDir(TEST_DIR, done) - }) - - afterEach(function (done) { - fse.remove(TEST_DIR, done) - }) - - describe('+ copySync', function () { - describe('> when modified option is turned off', function () { - it('should have different timestamps on copy', function (done) { - var from = path.join(SRC_FIXTURES_DIR) - - fse.copySync(from, TEST_DIR, {preserveTimestamps: false}) - - 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) - - fse.copySync(from, TEST_DIR, {preserveTimestamps: true}) - - FILES.forEach(testFile({preserveTimestamps: true})) - - done() - }) - }) - - }) - - describe('+ copy', function () { - 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.deepEqual(toStat.mtime, fromStat.mtime) - assert.deepEqual(toStat.atime, fromStat.atime) - } else { - assert.notEqual(toStat.mtime, fromStat.mtime) - assert.notEqual(toStat.atime, fromStat.atime) - } - } - } -})