diff --git a/test/read.test.js b/test/read.test.js index 98e3b92..3b49978 100644 --- a/test/read.test.js +++ b/test/read.test.js @@ -139,10 +139,15 @@ test('read from fd', t => { flags: 'r' }) .then(fd => { - return file.read(fd).then(result => { - t.equal(result.toString(), 'Hi!!!\n'); - return file.close(fd); - }); + return file + .read(fd, { + length: 3 + }) + .then(result => { + t.equal(result.toString(), 'Hi!'); + return file.close(fd); + }) + .then(t.end); }) .catch(error => { t.error(error); diff --git a/test/readfile.test.js b/test/readfile.test.js index 43589c6..9fb4844 100644 --- a/test/readfile.test.js +++ b/test/readfile.test.js @@ -43,6 +43,26 @@ test('readFile utf8', t => { }); }); +test('readFile from fd', t => { + file + .open(filepath1, { + flags: 'r' + }) + .then(fd => { + return file + .readFile(fd) + .then(result => { + t.equal(result.toString(), '0123456789\n'); + return file.close(fd); + }) + .then(t.end); + }) + .catch(error => { + t.error(error); + t.end(); + }); +}); + test('readFile non-existing file', t => { const path = resolve(__dirname, './data/nothing-here.txt'); diff --git a/test/truncate.test.js b/test/truncate.test.js index 6416acd..40bcd95 100644 --- a/test/truncate.test.js +++ b/test/truncate.test.js @@ -29,6 +29,30 @@ test('truncate', t => { }); }); +test('truncate with fd', t => { + file + .open(filepath1, { + flags: 'r+' + }) + .then(fd => { + return file + .truncate(fd, { + length: 8 + }) + .then(() => { + const text = readFileSync(filepath1, 'utf8'); + t.equal(text.length, 8, 'text.length is 8'); + t.equal(text, 'abcdefgh'); + return file.close(fd); + }) + .then(t.end); + }) + .catch(error => { + t.error(error); + t.end(); + }); +}); + test('truncate all', t => { file .truncate(filepath1) diff --git a/test/writefile.test.js b/test/writefile.test.js index 0147675..2eb7f34 100644 --- a/test/writefile.test.js +++ b/test/writefile.test.js @@ -65,6 +65,26 @@ test('writeFile to a new directory', t => { }); }); +test('readFile to fd', t => { + file + .open(file4, { + flags: 'r+' + }) + .then(fd => { + return file + .writeFile(fd, '_ an old') + .then(() => { + t.equal(readFileSync(file4, 'utf8'), '_ an old directory'); + return file.close(fd); + }) + .then(t.end); + }) + .catch(error => { + t.error(error); + t.end(); + }); +}); + test('writeFile error', t => { file .writeFile()