From ef80713c3317bd0cf335cd736cf2a91534363650 Mon Sep 17 00:00:00 2001 From: mordax Date: Sun, 23 Sep 2018 19:20:16 -0400 Subject: [PATCH] Added tests for future fs.copyFile implementation and adjusted index.js to run it. --- tests/index.js | 1 + tests/spec/fs.copyFile.spec.js | 53 ++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 tests/spec/fs.copyFile.spec.js diff --git a/tests/index.js b/tests/index.js index a459aa1..4d26f73 100644 --- a/tests/index.js +++ b/tests/index.js @@ -46,6 +46,7 @@ require('./spec/errors.spec'); require('./spec/fs.shell.spec'); require('./spec/fs.chmod.spec'); require('./spec/fs.chown.spec'); +require('./spec/fs.copyFile.spec'); // Filer.FileSystem.providers.* require('./spec/providers/providers.spec'); diff --git a/tests/spec/fs.copyFile.spec.js b/tests/spec/fs.copyFile.spec.js new file mode 100644 index 0000000..c050225 --- /dev/null +++ b/tests/spec/fs.copyFile.spec.js @@ -0,0 +1,53 @@ +var Filer = require('../../src'); +var util = require('../lib/test-utils.js'); +var expect = require('chai').expect; + +describe('fs.copyFile', function(){ + beforeEach(function(done){ + util.setup(function() { + var fs = util.fs(); + fs.writeFile('/srcfile', 'This is a src file.', function(error){ + if(error) throw error; + fs.writeFile('/destfile', 'This is a dest file.', function(error){ + if(error) throw error; + done(); + }); + }); + }); + }); + afterEach(util.cleanup); + + it('should be a function', function() { + var fs = util.fs(); + expect(fs.copyFile).to.be.a('function'); + }); + + it('should return an error if the src path does not exist', function(done){ + var fs = util.fs(); + var src = null; + var dest = 'dest.txt'; + + fs.copyFile(src, dest, function(error){ + expect(error).to.exist; + expect(error.code).to.equal('ENOENT'); + done(); + }); + + }); + + it('should copy file successfully', function(done) { + var fs = util.fs(); + var src = "This is a src file."; + + fs.copyFile('/srcfile', '/destfile', function(error) { + if(error) throw error; + + fs.readFile('/destfile', function(error, data){ + expect(error).not.to.exist; + expect(data).to.equal(src); + done(); + }); + }); + }); + +}); \ No newline at end of file