Update fs.appendFile.spec.js
This commit is contained in:
parent
3a4e26fdb5
commit
36d23ff835
|
@ -1,12 +1,14 @@
|
||||||
var util = require('../lib/test-utils.js');
|
'use strict';
|
||||||
var expect = require('chai').expect;
|
|
||||||
|
const util = require('../lib/test-utils.js');
|
||||||
|
const expect = require('chai').expect;
|
||||||
|
|
||||||
describe('fs.appendFile', function() {
|
describe('fs.appendFile', function() {
|
||||||
const contents = 'This is a file.';
|
const contents = 'This is a file.';
|
||||||
|
|
||||||
beforeEach(function(done) {
|
beforeEach(function(done) {
|
||||||
util.setup(function() {
|
util.setup(function() {
|
||||||
var fs = util.fs();
|
let fs = util.fs();
|
||||||
fs.writeFile('/myfile', contents, function(error) {
|
fs.writeFile('/myfile', contents, function(error) {
|
||||||
if(error) throw error;
|
if(error) throw error;
|
||||||
done();
|
done();
|
||||||
|
@ -16,13 +18,13 @@ describe('fs.appendFile', function() {
|
||||||
afterEach(util.cleanup);
|
afterEach(util.cleanup);
|
||||||
|
|
||||||
it('should be a function', function() {
|
it('should be a function', function() {
|
||||||
var fs = util.fs();
|
let fs = util.fs();
|
||||||
expect(fs.appendFile).to.be.a('function');
|
expect(fs.appendFile).to.be.a('function');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should append a utf8 file without specifying utf8 in appendFile', function(done) {
|
it('should append a utf8 file without specifying utf8 in appendFile', function(done) {
|
||||||
var fs = util.fs();
|
let fs = util.fs();
|
||||||
var more = ' Appended.';
|
const more = ' Appended.';
|
||||||
|
|
||||||
fs.appendFile('/myfile', more, function(error) {
|
fs.appendFile('/myfile', more, function(error) {
|
||||||
if(error) throw error;
|
if(error) throw error;
|
||||||
|
@ -36,8 +38,8 @@ describe('fs.appendFile', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should append a utf8 file with "utf8" option to appendFile', function(done) {
|
it('should append a utf8 file with "utf8" option to appendFile', function(done) {
|
||||||
var fs = util.fs();
|
let fs = util.fs();
|
||||||
var more = ' Appended.';
|
const more = ' Appended.';
|
||||||
|
|
||||||
fs.appendFile('/myfile', more, 'utf8', function(error) {
|
fs.appendFile('/myfile', more, 'utf8', function(error) {
|
||||||
if(error) throw error;
|
if(error) throw error;
|
||||||
|
@ -51,8 +53,8 @@ describe('fs.appendFile', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should append a utf8 file with {encoding: "utf8"} option to appendFile', function(done) {
|
it('should append a utf8 file with {encoding: "utf8"} option to appendFile', function(done) {
|
||||||
var fs = util.fs();
|
let fs = util.fs();
|
||||||
var more = ' Appended.';
|
const more = ' Appended.';
|
||||||
|
|
||||||
fs.appendFile('/myfile', more, { encoding: 'utf8' }, function(error) {
|
fs.appendFile('/myfile', more, { encoding: 'utf8' }, function(error) {
|
||||||
if(error) throw error;
|
if(error) throw error;
|
||||||
|
@ -66,12 +68,12 @@ describe('fs.appendFile', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should append a binary file', function(done) {
|
it('should append a binary file', function(done) {
|
||||||
var fs = util.fs();
|
let fs = util.fs();
|
||||||
|
|
||||||
// String and utf8 binary encoded versions of the same thing: 'This is a file.'
|
// String and utf8 binary encoded versions of the same thing: 'This is a file.'
|
||||||
var binary = Buffer.from([84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 102, 105, 108, 101, 46]);
|
const binary = Buffer.from([84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 102, 105, 108, 101, 46]);
|
||||||
var binary2 = Buffer.from([32, 65, 112, 112, 101, 110, 100, 101, 100, 46]);
|
const binary2 = Buffer.from([32, 65, 112, 112, 101, 110, 100, 101, 100, 46]);
|
||||||
var binary3 = Buffer.from([84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 102, 105, 108, 101, 46,
|
const binary3 = Buffer.from([84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 102, 105, 108, 101, 46,
|
||||||
32, 65, 112, 112, 101, 110, 100, 101, 100, 46]);
|
32, 65, 112, 112, 101, 110, 100, 101, 100, 46]);
|
||||||
|
|
||||||
fs.writeFile('/mybinaryfile', binary, function(error) {
|
fs.writeFile('/mybinaryfile', binary, function(error) {
|
||||||
|
@ -90,9 +92,9 @@ describe('fs.appendFile', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should follow symbolic links', function(done) {
|
it('should follow symbolic links', function(done) {
|
||||||
var fs = util.fs();
|
let fs = util.fs();
|
||||||
var contents = 'This is a file.';
|
const contents = 'This is a file.';
|
||||||
var more = ' Appended.';
|
const more = ' Appended.';
|
||||||
|
|
||||||
fs.symlink('/myfile', '/myFileLink', function (error) {
|
fs.symlink('/myfile', '/myFileLink', function (error) {
|
||||||
if (error) throw error;
|
if (error) throw error;
|
||||||
|
@ -110,7 +112,7 @@ describe('fs.appendFile', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work when file does not exist, and create the file', function(done) {
|
it('should work when file does not exist, and create the file', function(done) {
|
||||||
var fs = util.fs();
|
let fs = util.fs();
|
||||||
|
|
||||||
fs.appendFile('/newfile', contents, { encoding: 'utf8' }, function(error) {
|
fs.appendFile('/newfile', contents, { encoding: 'utf8' }, function(error) {
|
||||||
expect(error).not.to.exist;
|
expect(error).not.to.exist;
|
||||||
|
@ -124,8 +126,8 @@ describe('fs.appendFile', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should accept numbers and append them to the file', function(done) {
|
it('should accept numbers and append them to the file', function(done) {
|
||||||
var fs = util.fs();
|
let fs = util.fs();
|
||||||
var more = 10000;
|
const more = 10000;
|
||||||
|
|
||||||
fs.appendFile('/myfile', more, 'utf8', function(error) {
|
fs.appendFile('/myfile', more, 'utf8', function(error) {
|
||||||
if(error) throw error;
|
if(error) throw error;
|
||||||
|
@ -142,7 +144,7 @@ describe('fs.appendFile', function() {
|
||||||
describe('fs.promises.appendFile', function() {
|
describe('fs.promises.appendFile', function() {
|
||||||
beforeEach(function(done) {
|
beforeEach(function(done) {
|
||||||
util.setup(function() {
|
util.setup(function() {
|
||||||
var fs = util.fs();
|
let fs = util.fs();
|
||||||
return fs.promises.writeFile('/myfile', 'This is a file.', { encoding: 'utf8' })
|
return fs.promises.writeFile('/myfile', 'This is a file.', { encoding: 'utf8' })
|
||||||
.then(done)
|
.then(done)
|
||||||
.catch(done);
|
.catch(done);
|
||||||
|
@ -151,14 +153,14 @@ describe('fs.promises.appendFile', function() {
|
||||||
afterEach(util.cleanup);
|
afterEach(util.cleanup);
|
||||||
|
|
||||||
it('should be a function', function() {
|
it('should be a function', function() {
|
||||||
var fs = util.fs();
|
let fs = util.fs();
|
||||||
expect(fs.promises.appendFile).to.be.a('function');
|
expect(fs.promises.appendFile).to.be.a('function');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should append a utf8 file without specifying utf8 in appendFile', function() {
|
it('should append a utf8 file without specifying utf8 in appendFile', function() {
|
||||||
var fs = util.fs();
|
let fs = util.fs();
|
||||||
var contents = 'This is a file.';
|
const contents = 'This is a file.';
|
||||||
var more = ' Appended.';
|
const more = ' Appended.';
|
||||||
|
|
||||||
return fs.promises.appendFile('/myfile', more)
|
return fs.promises.appendFile('/myfile', more)
|
||||||
.then(() => fs.promises.readFile('/myfile', 'utf8'))
|
.then(() => fs.promises.readFile('/myfile', 'utf8'))
|
||||||
|
@ -166,9 +168,9 @@ describe('fs.promises.appendFile', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should append a utf8 file with "utf8" option to appendFile', function() {
|
it('should append a utf8 file with "utf8" option to appendFile', function() {
|
||||||
var fs = util.fs();
|
let fs = util.fs();
|
||||||
var contents = 'This is a file.';
|
const contents = 'This is a file.';
|
||||||
var more = ' Appended.';
|
const more = ' Appended.';
|
||||||
|
|
||||||
return fs.promises.appendFile('/myfile', more, 'utf8')
|
return fs.promises.appendFile('/myfile', more, 'utf8')
|
||||||
.then(() => fs.promises.readFile('/myfile', 'utf8'))
|
.then(() => fs.promises.readFile('/myfile', 'utf8'))
|
||||||
|
@ -176,9 +178,9 @@ describe('fs.promises.appendFile', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should append a utf8 file with {encoding: "utf8"} option to appendFile', function() {
|
it('should append a utf8 file with {encoding: "utf8"} option to appendFile', function() {
|
||||||
var fs = util.fs();
|
let fs = util.fs();
|
||||||
var contents = 'This is a file.';
|
const contents = 'This is a file.';
|
||||||
var more = ' Appended.';
|
const more = ' Appended.';
|
||||||
|
|
||||||
return fs.promises.appendFile('/myfile', more, { encoding: 'utf8' })
|
return fs.promises.appendFile('/myfile', more, { encoding: 'utf8' })
|
||||||
.then(() => fs.promises.readFile('/myfile', { encoding: 'utf8' }))
|
.then(() => fs.promises.readFile('/myfile', { encoding: 'utf8' }))
|
||||||
|
@ -186,12 +188,12 @@ describe('fs.promises.appendFile', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should append a binary file', function() {
|
it('should append a binary file', function() {
|
||||||
var fs = util.fs();
|
let fs = util.fs();
|
||||||
|
|
||||||
// String and utf8 binary encoded versions of the same thing: 'This is a file.'
|
// String and utf8 binary encoded versions of the same thing: 'This is a file.'
|
||||||
var binary = new Buffer([84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 102, 105, 108, 101, 46]);
|
const binary = new Buffer([84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 102, 105, 108, 101, 46]);
|
||||||
var binary2 = new Buffer([32, 65, 112, 112, 101, 110, 100, 101, 100, 46]);
|
const binary2 = new Buffer([32, 65, 112, 112, 101, 110, 100, 101, 100, 46]);
|
||||||
var binary3 = new Buffer([84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 102, 105, 108, 101, 46,
|
const binary3 = new Buffer([84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 102, 105, 108, 101, 46,
|
||||||
32, 65, 112, 112, 101, 110, 100, 101, 100, 46]);
|
32, 65, 112, 112, 101, 110, 100, 101, 100, 46]);
|
||||||
|
|
||||||
return fs.promises.writeFile('/mybinaryfile', binary)
|
return fs.promises.writeFile('/mybinaryfile', binary)
|
||||||
|
@ -201,9 +203,9 @@ describe('fs.promises.appendFile', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should follow symbolic links', function() {
|
it('should follow symbolic links', function() {
|
||||||
var fs = util.fs();
|
let fs = util.fs();
|
||||||
var contents = 'This is a file.';
|
const contents = 'This is a file.';
|
||||||
var more = ' Appended.';
|
const more = ' Appended.';
|
||||||
|
|
||||||
return fs.promises.symlink('/myfile', '/myFileLink')
|
return fs.promises.symlink('/myfile', '/myFileLink')
|
||||||
.then(() => fs.promises.appendFile('/myFileLink', more, 'utf8'))
|
.then(() => fs.promises.appendFile('/myFileLink', more, 'utf8'))
|
||||||
|
@ -212,8 +214,8 @@ describe('fs.promises.appendFile', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work when file does not exist, and create the file', function() {
|
it('should work when file does not exist, and create the file', function() {
|
||||||
var fs = util.fs();
|
let fs = util.fs();
|
||||||
var contents = 'This is a file.';
|
const contents = 'This is a file.';
|
||||||
|
|
||||||
return fs.promises.appendFile('/newfile', contents, { encoding: 'utf8' })
|
return fs.promises.appendFile('/newfile', contents, { encoding: 'utf8' })
|
||||||
.then(() => fs.promises.readFile('/newfile', 'utf8'))
|
.then(() => fs.promises.readFile('/newfile', 'utf8'))
|
||||||
|
|
Loading…
Reference in New Issue