Skip to content

Commit 8347ef6

Browse files
LiviaMedeirostargos
authored andcommitted
test: dispose of filehandles in filehandle.read tests
PR-URL: #58543 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 6f4c9dd commit 8347ef6

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

test/parallel/test-fs-read-empty-buffer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ assert.throws(
2929
);
3030

3131
(async () => {
32-
const filehandle = await fsPromises.open(filepath, 'r');
32+
await using filehandle = await fsPromises.open(filepath, 'r');
3333
assert.rejects(
3434
() => filehandle.read(buffer, 0, 1, 0),
3535
{

test/parallel/test-fs-read-offset-null.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,25 @@ fs.open(filepath, 'r', common.mustSucceed((fd) => {
3535
}));
3636
}));
3737

38-
let filehandle = null;
39-
4038
// Tests for promises api
4139
(async () => {
42-
filehandle = await fsPromises.open(filepath, 'r');
40+
await using filehandle = await fsPromises.open(filepath, 'r');
4341
const readObject = await filehandle.read(buf, { offset: null });
4442
assert.strictEqual(readObject.buffer[0], 120);
4543
})()
46-
.finally(() => filehandle?.close())
4744
.then(common.mustCall());
4845

4946
// Undocumented: omitted position works the same as position === null
5047
(async () => {
51-
filehandle = await fsPromises.open(filepath, 'r');
48+
await using filehandle = await fsPromises.open(filepath, 'r');
5249
const readObject = await filehandle.read(buf, null, buf.length);
5350
assert.strictEqual(readObject.buffer[0], 120);
5451
})()
55-
.finally(() => filehandle?.close())
5652
.then(common.mustCall());
5753

5854
(async () => {
59-
filehandle = await fsPromises.open(filepath, 'r');
55+
await using filehandle = await fsPromises.open(filepath, 'r');
6056
const readObject = await filehandle.read(buf, null, buf.length, 0);
6157
assert.strictEqual(readObject.buffer[0], 120);
6258
})()
63-
.finally(() => filehandle?.close())
6459
.then(common.mustCall());

0 commit comments

Comments
 (0)