Skip to content

Commit

Permalink
test/copy-sync: added tests for clobber option
Browse files Browse the repository at this point in the history
  • Loading branch information
jprichardson committed Mar 19, 2015
1 parent f80ab7e commit 0bed228
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions test/copy-sync.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,65 @@ describe('+ copySync()', function () {
assert.strictEqual(data, data2)
})
})

describe('> when clobber option is passed', function () {
var src, dest
var srcData = 'some src data'

beforeEach(function () {
src = path.join(DIR, 'src-file')
dest = path.join(DIR, 'des-file')

// source file must always exist in these cases
fs.writeFileSync(src, srcData)
})

describe('> when destination file does NOT exist', function () {
describe('> when clobber is true', function () {
it('should copy the file and not throw an error', function () {
fs.copySync(src, dest, {clobber: true})
var destData = fs.readFileSync(dest, 'utf8')
assert.strictEqual(srcData, destData)
})
})

describe('> when clobber is false', function () {
it('should copy the file and not throw an error', function () {
fs.copySync(src, dest, {clobber: false})
var destData = fs.readFileSync(dest, 'utf8')
assert.strictEqual(srcData, destData)
})
})
})

describe('when destination file does exist', function () {
var destData
beforeEach(function () {
destData = 'some dest data'
fs.writeFileSync(dest, destData)
})

describe('> when clobber is true', function () {
it('should copy the file and not throw an error', function () {
fs.copySync(src, dest, {clobber: true})
destData = fs.readFileSync(dest, 'utf8')
assert.strictEqual(srcData, destData)
})
})

describe('> when clobber is false', function () {
it('should copy the file and THROW an error', function () {
assert.throws(function () {
fs.copySync(src, dest, {clobber: false})
})

// copy never happened
var destDataNew = fs.readFileSync(dest, 'utf8')
assert.strictEqual(destData, destDataNew)
})
})
})
})
})

describe('> when the source is a directory', function () {
Expand Down

0 comments on commit 0bed228

Please sign in to comment.