From 947ce41e99637dae4cf46126b8bb2d4107fb9913 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Wed, 24 Jan 2024 10:27:29 +1100 Subject: feat: deprecate `Deno.resources()` (#22059) Most uses of `Deno.resources()` within tests, as they previously checked for leaked resources. This is not needed as the test runner does this automatically. Other internal uses of this API have been replaced with the internal `Deno[Deno.internal].core.resources()`. --- cli/tests/unit_node/_fs/_fs_appendFile_test.ts | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) (limited to 'cli/tests/unit_node/_fs/_fs_appendFile_test.ts') diff --git a/cli/tests/unit_node/_fs/_fs_appendFile_test.ts b/cli/tests/unit_node/_fs/_fs_appendFile_test.ts index 33c99414f..e70d3401f 100644 --- a/cli/tests/unit_node/_fs/_fs_appendFile_test.ts +++ b/cli/tests/unit_node/_fs/_fs_appendFile_test.ts @@ -97,7 +97,6 @@ Deno.test({ Deno.test({ name: "Async: Data is written to passed in file path", async fn() { - const openResourcesBeforeAppend: Deno.ResourceMap = Deno.resources(); await new Promise((resolve, reject) => { appendFile("_fs_appendFile_test_file.txt", "hello world", (err) => { if (err) reject(err); @@ -105,7 +104,6 @@ Deno.test({ }); }) .then(async () => { - assertEquals(Deno.resources(), openResourcesBeforeAppend); const data = await Deno.readFile("_fs_appendFile_test_file.txt"); assertEquals(decoder.decode(data), "hello world"); }, (err) => { @@ -120,7 +118,6 @@ Deno.test({ Deno.test({ name: "Async: Data is written to passed in URL", async fn() { - const openResourcesBeforeAppend: Deno.ResourceMap = Deno.resources(); const fileURL = new URL("_fs_appendFile_test_file.txt", import.meta.url); await new Promise((resolve, reject) => { appendFile(fileURL, "hello world", (err) => { @@ -129,7 +126,6 @@ Deno.test({ }); }) .then(async () => { - assertEquals(Deno.resources(), openResourcesBeforeAppend); const data = await Deno.readFile(fromFileUrl(fileURL)); assertEquals(decoder.decode(data), "hello world"); }, (err) => { @@ -145,7 +141,6 @@ Deno.test({ name: "Async: Callback is made with error if attempting to append data to an existing file with 'ax' flag", async fn() { - const openResourcesBeforeAppend: Deno.ResourceMap = Deno.resources(); const tempFile: string = await Deno.makeTempFile(); await new Promise((resolve, reject) => { appendFile(tempFile, "hello world", { flag: "ax" }, (err) => { @@ -153,11 +148,8 @@ Deno.test({ else resolve(); }); }) - .then(() => { - fail("Expected error to be thrown"); - }, () => { - assertEquals(Deno.resources(), openResourcesBeforeAppend); - }) + .then(() => fail("Expected error to be thrown")) + .catch(() => {}) .finally(async () => { await Deno.remove(tempFile); }); @@ -184,9 +176,7 @@ Deno.test({ Deno.test({ name: "Sync: Data is written to passed in file path", fn() { - const openResourcesBeforeAppend: Deno.ResourceMap = Deno.resources(); appendFileSync("_fs_appendFile_test_file_sync.txt", "hello world"); - assertEquals(Deno.resources(), openResourcesBeforeAppend); const data = Deno.readFileSync("_fs_appendFile_test_file_sync.txt"); assertEquals(decoder.decode(data), "hello world"); Deno.removeSync("_fs_appendFile_test_file_sync.txt"); @@ -197,14 +187,12 @@ Deno.test({ name: "Sync: error thrown if attempting to append data to an existing file with 'ax' flag", fn() { - const openResourcesBeforeAppend: Deno.ResourceMap = Deno.resources(); const tempFile: string = Deno.makeTempFileSync(); assertThrows( () => appendFileSync(tempFile, "hello world", { flag: "ax" }), Error, "", ); - assertEquals(Deno.resources(), openResourcesBeforeAppend); Deno.removeSync(tempFile); }, }); @@ -212,10 +200,8 @@ Deno.test({ Deno.test({ name: "Sync: Data is written in Uint8Array to passed in file path", fn() { - const openResourcesBeforeAppend: Deno.ResourceMap = Deno.resources(); const testData = new TextEncoder().encode("hello world"); appendFileSync("_fs_appendFile_test_file_sync.txt", testData); - assertEquals(Deno.resources(), openResourcesBeforeAppend); const data = Deno.readFileSync("_fs_appendFile_test_file_sync.txt"); assertEquals(data, testData); Deno.removeSync("_fs_appendFile_test_file_sync.txt"); @@ -225,7 +211,6 @@ Deno.test({ Deno.test({ name: "Async: Data is written in Uint8Array to passed in file path", async fn() { - const openResourcesBeforeAppend: Deno.ResourceMap = Deno.resources(); const testData = new TextEncoder().encode("hello world"); await new Promise((resolve, reject) => { appendFile("_fs_appendFile_test_file.txt", testData, (err) => { @@ -234,7 +219,6 @@ Deno.test({ }); }) .then(async () => { - assertEquals(Deno.resources(), openResourcesBeforeAppend); const data = await Deno.readFile("_fs_appendFile_test_file.txt"); assertEquals(data, testData); }, (err) => { -- cgit v1.2.3