From 5cc0f056d1af6f76c6ad81a6cd68dcaabba60f35 Mon Sep 17 00:00:00 2001 From: Ali Hasani Date: Sun, 3 May 2020 23:44:38 +0430 Subject: [std/node] add the ability to path argument to be URL type (#5055) --- std/node/_fs/_fs_appendFile_test.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'std/node/_fs/_fs_appendFile_test.ts') diff --git a/std/node/_fs/_fs_appendFile_test.ts b/std/node/_fs/_fs_appendFile_test.ts index ca48dc5d3..402ac1c10 100644 --- a/std/node/_fs/_fs_appendFile_test.ts +++ b/std/node/_fs/_fs_appendFile_test.ts @@ -2,6 +2,7 @@ const { test } = Deno; import { assertEquals, assertThrows, fail } from "../../testing/asserts.ts"; import { appendFile, appendFileSync } from "./_fs_appendFile.ts"; +import { fromFileUrl } from "../path.ts"; const decoder = new TextDecoder("utf-8"); @@ -109,6 +110,31 @@ test({ }, }); +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) => { + if (err) reject(err); + else resolve(); + }); + }) + .then(async () => { + assertEquals(Deno.resources(), openResourcesBeforeAppend); + const data = await Deno.readFile(fromFileUrl(fileURL)); + assertEquals(decoder.decode(data), "hello world"); + }) + .catch((err) => { + fail("No error was expected: " + err); + }) + .finally(async () => { + await Deno.remove(fromFileUrl(fileURL)); + }); + }, +}); + test({ name: "Async: Callback is made with error if attempting to append data to an existing file with 'ax' flag", -- cgit v1.2.3