Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
squash: adjust tests
  • Loading branch information
LiviaMedeiros committed Apr 22, 2022
commit ab0b534874af180ba2cd60dcc646ebe795c88309
23 changes: 16 additions & 7 deletions test/parallel/test-fs-read-offset-null.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ const filepath = fixtures.path('x.txt');
const buf = Buffer.alloc(1);
// Reading only one character, hence buffer of one byte is enough.

// Test is done by making sure the first letter in buffer is
// Tests are done by making sure the first letter in buffer is
// same as first letter in file.
// 120 is the ascii code of letter x.

// Test for callback API.
// Tests for callback API.
fs.open(filepath, 'r', common.mustSucceed((fd) => {
fs.read(fd, { offset: null, buffer: buf },
common.mustSucceed((bytesRead, buffer) => {
Expand All @@ -37,19 +37,28 @@ fs.open(filepath, 'r', common.mustSucceed((fd) => {

let filehandle = null;

// Test for promise api
// Tests for promises api
(async () => {
filehandle = await fsPromises.open(filepath, 'r');
const readObject = await filehandle.read(buf, { offset: null });
assert.strictEqual(readObject.buffer[0], 120);
})()
.then(common.mustCall())
.finally(() => filehandle?.close());
.finally(() => filehandle?.close())
.then(common.mustCall());

// Undocumented: omitted position works the same as position === null
(async () => {
filehandle = await fsPromises.open(filepath, 'r');
const readObject = await filehandle.read(buf, null, buf.length);
assert.strictEqual(readObject.buffer[0], 120);
})()
.finally(() => filehandle?.close())
.then(common.mustCall());

(async () => {
filehandle = await fsPromises.open(filepath, 'r');
const readObject = await filehandle.read(buf, null, buf.length, 0);
assert.strictEqual(readObject.buffer[0], 120);
})()
.then(common.mustCall())
.finally(() => filehandle?.close());
.finally(() => filehandle?.close())
.then(common.mustCall());
2 changes: 1 addition & 1 deletion test/parallel/test-fs-read-optional-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ testValid('Passing in an empty object', {});
testValid('Passing in an object', {
offset: 0,
length: bufferAsOption.byteLength,
position: 0
position: 0,
});