Skip to content
Open
Changes from all commits
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
23 changes: 22 additions & 1 deletion test/parallel/test-fs-promises-file-handle-dispose.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,26 @@ async function explicitCall() {
assert.throws(() => dhSync.readSync(), { code: 'ERR_DIR_CLOSED' });
}

async function implicitCall() {
{
await using fh = await fs.open(__filename);
fh.on('close', common.mustCall());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ensures only that fh is closed at some point, but we need to test that the filehandle is closed as soon as we exit the scope.

}

let dh;
{
await using dirHandle = await fs.opendir(__dirname);
dh = dirHandle;
}
await assert.rejects(dh.read(), { code: 'ERR_DIR_CLOSED' });

let dhSync;
{
using dirHandleSync = opendirSync(__dirname);
dhSync = dirHandleSync;
}
assert.throws(() => dhSync.readSync(), { code: 'ERR_DIR_CLOSED' });
}

explicitCall().then(common.mustCall());
// TODO(aduh95): add test for implicit calls, with `await using` syntax.
implicitCall().then(common.mustCall());
Loading