Skip to content

Commit

Permalink
Move tests into lib/copy/__tests__
Browse files Browse the repository at this point in the history
Signed-off-by: Joern Bernhardt <[email protected]>
  • Loading branch information
McHunkyTrunk committed Jun 22, 2015
1 parent 5696fca commit c9404aa
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 91 deletions.
45 changes: 45 additions & 0 deletions lib/copy/__tests__/copy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
File renamed without changes.
File renamed without changes.
44 changes: 44 additions & 0 deletions lib/copy/__tests__/sync/copy-sync.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
})
})
91 changes: 0 additions & 91 deletions test/copy/copy.test.js

This file was deleted.

0 comments on commit c9404aa

Please sign in to comment.