test: dispose of filehandles in filehandle.read tests · nodejs/node@8347ef6

2 files changed

lines changed

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

{

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());