test: add implicit test for fs dispose handling with using

PR-URL: https://github.com/nodejs/node/pull/61140
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
Ilyas Shabi authored and GitHub committed 2026-01-21 18:23:08 +00:00
1 parent 853277a9e2
commit 98d23317f0
1 file changed
+25 -1
@@ -22,5 +22,29 @@ async function explicitCall() {
assert.throws(() => dhSync.readSync(), { code: 'ERR_DIR_CLOSED' });
}
async function implicitCall() {
let fh;
{
await using openHandle = await fs.open(__filename);
fh = openHandle;
fh.on('close', common.mustCall());
}
assert.strictEqual(fh.fd, -1);
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());