From 9e35ddca4484224606aa4ac1c13e02d73fadc3ac Mon Sep 17 00:00:00 2001 From: Livia Medeiros Date: Thu, 5 Jun 2025 09:52:48 +0800 Subject: [PATCH] test: dispose of filehandles in filehandle.read tests PR-URL: https://github.com/nodejs/node/pull/58543 Reviewed-By: Luigi Pinca Reviewed-By: James M Snell --- test/parallel/test-fs-read-empty-buffer.js | 2 +- test/parallel/test-fs-read-offset-null.js | 11 +++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/test/parallel/test-fs-read-empty-buffer.js b/test/parallel/test-fs-read-empty-buffer.js index 6abfcb5aae6..65ed3ee0052 100644 --- a/test/parallel/test-fs-read-empty-buffer.js +++ b/test/parallel/test-fs-read-empty-buffer.js @@ -29,7 +29,7 @@ assert.throws( ); (async () => { - const filehandle = await fsPromises.open(filepath, 'r'); + await using filehandle = await fsPromises.open(filepath, 'r'); assert.rejects( () => filehandle.read(buffer, 0, 1, 0), { diff --git a/test/parallel/test-fs-read-offset-null.js b/test/parallel/test-fs-read-offset-null.js index 012c94e41e9..4104fe14113 100644 --- a/test/parallel/test-fs-read-offset-null.js +++ b/test/parallel/test-fs-read-offset-null.js @@ -35,30 +35,25 @@ fs.open(filepath, 'r', common.mustSucceed((fd) => { })); })); -let filehandle = null; - // Tests for promises api (async () => { - filehandle = await fsPromises.open(filepath, 'r'); + await using filehandle = await fsPromises.open(filepath, 'r'); const readObject = await filehandle.read(buf, { offset: null }); assert.strictEqual(readObject.buffer[0], 120); })() -.finally(() => filehandle?.close()) .then(common.mustCall()); // Undocumented: omitted position works the same as position === null (async () => { - filehandle = await fsPromises.open(filepath, 'r'); + await using 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'); + await using filehandle = await fsPromises.open(filepath, 'r'); const readObject = await filehandle.read(buf, null, buf.length, 0); assert.strictEqual(readObject.buffer[0], 120); })() -.finally(() => filehandle?.close()) .then(common.mustCall());