test: dispose of filehandles in filehandle.read tests
PR-URL: https://github.com/nodejs/node/pull/58543 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
3f81645f8c
commit
9e35ddca44
@ -29,7 +29,7 @@ assert.throws(
|
|||||||
);
|
);
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const filehandle = await fsPromises.open(filepath, 'r');
|
await using filehandle = await fsPromises.open(filepath, 'r');
|
||||||
assert.rejects(
|
assert.rejects(
|
||||||
() => filehandle.read(buffer, 0, 1, 0),
|
() => filehandle.read(buffer, 0, 1, 0),
|
||||||
{
|
{
|
||||||
|
@ -35,30 +35,25 @@ fs.open(filepath, 'r', common.mustSucceed((fd) => {
|
|||||||
}));
|
}));
|
||||||
}));
|
}));
|
||||||
|
|
||||||
let filehandle = null;
|
|
||||||
|
|
||||||
// Tests for promises api
|
// Tests for promises api
|
||||||
(async () => {
|
(async () => {
|
||||||
filehandle = await fsPromises.open(filepath, 'r');
|
await using filehandle = await fsPromises.open(filepath, 'r');
|
||||||
const readObject = await filehandle.read(buf, { offset: null });
|
const readObject = await filehandle.read(buf, { offset: null });
|
||||||
assert.strictEqual(readObject.buffer[0], 120);
|
assert.strictEqual(readObject.buffer[0], 120);
|
||||||
})()
|
})()
|
||||||
.finally(() => filehandle?.close())
|
|
||||||
.then(common.mustCall());
|
.then(common.mustCall());
|
||||||
|
|
||||||
// Undocumented: omitted position works the same as position === null
|
// Undocumented: omitted position works the same as position === null
|
||||||
(async () => {
|
(async () => {
|
||||||
filehandle = await fsPromises.open(filepath, 'r');
|
await using filehandle = await fsPromises.open(filepath, 'r');
|
||||||
const readObject = await filehandle.read(buf, null, buf.length);
|
const readObject = await filehandle.read(buf, null, buf.length);
|
||||||
assert.strictEqual(readObject.buffer[0], 120);
|
assert.strictEqual(readObject.buffer[0], 120);
|
||||||
})()
|
})()
|
||||||
.finally(() => filehandle?.close())
|
|
||||||
.then(common.mustCall());
|
.then(common.mustCall());
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
filehandle = await fsPromises.open(filepath, 'r');
|
await using filehandle = await fsPromises.open(filepath, 'r');
|
||||||
const readObject = await filehandle.read(buf, null, buf.length, 0);
|
const readObject = await filehandle.read(buf, null, buf.length, 0);
|
||||||
assert.strictEqual(readObject.buffer[0], 120);
|
assert.strictEqual(readObject.buffer[0], 120);
|
||||||
})()
|
})()
|
||||||
.finally(() => filehandle?.close())
|
|
||||||
.then(common.mustCall());
|
.then(common.mustCall());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user