From 0bed228be27249b04caa5f07e05f85f669d2b842 Mon Sep 17 00:00:00 2001 From: JP Richardson Date: Thu, 19 Mar 2015 11:32:35 -0500 Subject: [PATCH] test/copy-sync: added tests for clobber option --- test/copy-sync.test.js | 59 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/test/copy-sync.test.js b/test/copy-sync.test.js index ac3663aa..01271e9b 100644 --- a/test/copy-sync.test.js +++ b/test/copy-sync.test.js @@ -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 () {