From 62786cfebb5c9fe36d0930582951f442bdfe9441 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Thu, 25 Jan 2024 01:59:55 +1100 Subject: feat: deprecate `Deno.close()` (#22066) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For removal in Deno v2. --------- Co-authored-by: Bartek IwaƄczuk --- cli/tests/unit_node/_fs/_fs_ftruncate_test.ts | 52 +++++++++++++-------------- 1 file changed, 24 insertions(+), 28 deletions(-) (limited to 'cli/tests/unit_node/_fs/_fs_ftruncate_test.ts') diff --git a/cli/tests/unit_node/_fs/_fs_ftruncate_test.ts b/cli/tests/unit_node/_fs/_fs_ftruncate_test.ts index 4c2c34789..ef59f0577 100644 --- a/cli/tests/unit_node/_fs/_fs_ftruncate_test.ts +++ b/cli/tests/unit_node/_fs/_fs_ftruncate_test.ts @@ -23,23 +23,23 @@ Deno.test({ Deno.test({ name: "ASYNC: truncate entire file contents", async fn() { - const file: string = Deno.makeTempFileSync(); - await Deno.writeTextFile(file, "hello world"); - const { rid } = await Deno.open(file, { + const filePath = Deno.makeTempFileSync(); + await Deno.writeTextFile(filePath, "hello world"); + using file = await Deno.open(filePath, { read: true, write: true, create: true, }); await new Promise((resolve, reject) => { - ftruncate(rid, (err: Error | null) => { + ftruncate(file.rid, (err: Error | null) => { if (err !== null) reject(); else resolve(); }); }) .then( () => { - const fileInfo: Deno.FileInfo = Deno.lstatSync(file); + const fileInfo: Deno.FileInfo = Deno.lstatSync(filePath); assertEquals(fileInfo.size, 0); }, () => { @@ -47,8 +47,7 @@ Deno.test({ }, ) .finally(() => { - Deno.removeSync(file); - Deno.close(rid); + Deno.removeSync(filePath); }); }, }); @@ -56,23 +55,23 @@ Deno.test({ Deno.test({ name: "ASYNC: truncate file to a size of precisely len bytes", async fn() { - const file: string = Deno.makeTempFileSync(); - await Deno.writeTextFile(file, "hello world"); - const { rid } = await Deno.open(file, { + const filePath = Deno.makeTempFileSync(); + await Deno.writeTextFile(filePath, "hello world"); + using file = await Deno.open(filePath, { read: true, write: true, create: true, }); await new Promise((resolve, reject) => { - ftruncate(rid, 3, (err: Error | null) => { + ftruncate(file.rid, 3, (err: Error | null) => { if (err !== null) reject(); else resolve(); }); }) .then( () => { - const fileInfo: Deno.FileInfo = Deno.lstatSync(file); + const fileInfo: Deno.FileInfo = Deno.lstatSync(filePath); assertEquals(fileInfo.size, 3); }, () => { @@ -80,8 +79,7 @@ Deno.test({ }, ) .finally(() => { - Deno.removeSync(file); - Deno.close(rid); + Deno.removeSync(filePath); }); }, }); @@ -89,21 +87,20 @@ Deno.test({ Deno.test({ name: "SYNC: truncate entire file contents", fn() { - const file: string = Deno.makeTempFileSync(); - Deno.writeFileSync(file, new TextEncoder().encode("hello world")); - const { rid } = Deno.openSync(file, { + const filePath = Deno.makeTempFileSync(); + Deno.writeFileSync(filePath, new TextEncoder().encode("hello world")); + using file = Deno.openSync(filePath, { read: true, write: true, create: true, }); try { - ftruncateSync(rid); - const fileInfo: Deno.FileInfo = Deno.lstatSync(file); + ftruncateSync(file.rid); + const fileInfo: Deno.FileInfo = Deno.lstatSync(filePath); assertEquals(fileInfo.size, 0); } finally { - Deno.removeSync(file); - Deno.close(rid); + Deno.removeSync(filePath); } }, }); @@ -111,21 +108,20 @@ Deno.test({ Deno.test({ name: "SYNC: truncate file to a size of precisely len bytes", fn() { - const file: string = Deno.makeTempFileSync(); - Deno.writeFileSync(file, new TextEncoder().encode("hello world")); - const { rid } = Deno.openSync(file, { + const filePath = Deno.makeTempFileSync(); + Deno.writeFileSync(filePath, new TextEncoder().encode("hello world")); + using file = Deno.openSync(filePath, { read: true, write: true, create: true, }); try { - ftruncateSync(rid, 3); - const fileInfo: Deno.FileInfo = Deno.lstatSync(file); + ftruncateSync(file.rid, 3); + const fileInfo: Deno.FileInfo = Deno.lstatSync(filePath); assertEquals(fileInfo.size, 3); } finally { - Deno.removeSync(file); - Deno.close(rid); + Deno.removeSync(filePath); } }, }); -- cgit v1.2.3