2018-09-23 23:20:16 +00:00
|
|
|
var util = require('../lib/test-utils.js');
|
|
|
|
var expect = require('chai').expect;
|
2018-09-24 18:35:41 +00:00
|
|
|
const { COPYFILE_EXCL } = require('../../src/constants').fsConstants;
|
2018-09-23 23:20:16 +00:00
|
|
|
|
2018-12-17 21:06:24 +00:00
|
|
|
// Waiting on implementation to land https://github.com/filerjs/filer/issues/436
|
|
|
|
describe.skip('fs.copyFile', function() {
|
|
|
|
const file = {
|
|
|
|
path: '/srcfile',
|
|
|
|
contents: 'This is a src file.'
|
|
|
|
};
|
|
|
|
|
2018-09-23 23:20:16 +00:00
|
|
|
beforeEach(function(done){
|
|
|
|
util.setup(function() {
|
|
|
|
var fs = util.fs();
|
2018-12-17 21:06:24 +00:00
|
|
|
fs.writeFile(file.path, file.contents, done);
|
2018-09-23 23:20:16 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
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();
|
|
|
|
|
2018-12-17 21:06:24 +00:00
|
|
|
fs.copyFile(null, '/dest.txt', function(error) {
|
2018-09-23 23:20:16 +00:00
|
|
|
expect(error).to.exist;
|
|
|
|
expect(error.code).to.equal('ENOENT');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should copy file successfully', function(done) {
|
|
|
|
var fs = util.fs();
|
2018-12-17 21:06:24 +00:00
|
|
|
const destPath = '/destfile';
|
2018-09-23 23:20:16 +00:00
|
|
|
|
2018-12-17 21:06:24 +00:00
|
|
|
fs.copyFile(file.path, destPath, function(error) {
|
2018-09-23 23:20:16 +00:00
|
|
|
if(error) throw error;
|
|
|
|
|
2018-12-17 21:06:24 +00:00
|
|
|
fs.readFile(destPath, function(error, data) {
|
2018-09-23 23:20:16 +00:00
|
|
|
expect(error).not.to.exist;
|
2018-12-17 21:06:24 +00:00
|
|
|
expect(data).to.equal(file.contents);
|
2018-09-23 23:20:16 +00:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-09-24 18:35:41 +00:00
|
|
|
|
|
|
|
it('should return an error if flag=COPYFILE_EXCL and the destination file exists', function (done) {
|
|
|
|
var fs = util.fs();
|
|
|
|
const destPath = '/destfile';
|
|
|
|
|
|
|
|
fs.writeFile(destPath, 'data', function(error) {
|
|
|
|
if(error) throw error;
|
|
|
|
|
|
|
|
fs.copyFile(file.path, destPath, COPYFILE_EXCL, function(error) {
|
|
|
|
expect(error).to.exist;
|
|
|
|
expect(error.code).to.equal('ENOENT');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-12-17 21:06:24 +00:00
|
|
|
});
|