diff options
author | Luca Casonato <hello@lcas.dev> | 2023-11-01 20:26:12 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-01 20:26:12 +0100 |
commit | d42f1543121e7245789a96a485d1ef7645cb5fba (patch) | |
tree | d57a10ac527fe5b6796a3a8866af95f0f1a5d7bd /cli/tests/unit/files_test.ts | |
parent | 1d19b1011bd7df50598f5981408c2d78c35b76d2 (diff) |
feat: disposable Deno resources (#20845)
This commit implements Symbol.dispose and Symbol.asyncDispose for
the relevant resources.
Closes #20839
---------
Signed-off-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Diffstat (limited to 'cli/tests/unit/files_test.ts')
-rw-r--r-- | cli/tests/unit/files_test.ts | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/cli/tests/unit/files_test.ts b/cli/tests/unit/files_test.ts index 873c70c86..3e0390ae6 100644 --- a/cli/tests/unit/files_test.ts +++ b/cli/tests/unit/files_test.ts @@ -824,3 +824,30 @@ Deno.test( assertEquals(res, "hello \uFFFD"); }, ); + +Deno.test( + { permissions: { read: true } }, + async function fsFileExplicitResourceManagement() { + let file2: Deno.FsFile; + + { + using file = await Deno.open("cli/tests/testdata/assets/hello.txt"); + file2 = file; + + const stat = file.statSync(); + assert(stat.isFile); + } + + assertThrows(() => file2.statSync(), Deno.errors.BadResource); + }, +); + +Deno.test( + { permissions: { read: true } }, + async function fsFileExplicitResourceManagementManualClose() { + using file = await Deno.open("cli/tests/testdata/assets/hello.txt"); + file.close(); + assertThrows(() => file.statSync(), Deno.errors.BadResource); // definitely closed + // calling [Symbol.dispose] after manual close is a no-op + }, +); |