summaryrefslogtreecommitdiff
path: root/std/node/_fs/promises/_fs_readFile_test.ts
diff options
context:
space:
mode:
authorMarcos Casagrande <marcoscvp90@gmail.com>2020-05-20 08:50:48 +0200
committerGitHub <noreply@github.com>2020-05-20 02:50:48 -0400
commiteb5acb39d5936d3e0fde44a33357cda88a5ff55f (patch)
tree8595b6fea985fcedffc1a92cd2f3de49c1c7ceb4 /std/node/_fs/promises/_fs_readFile_test.ts
parent62c34bc21e8864ec5701ad493c73224367627580 (diff)
feat(std/node): Add fs.promises.readFile (#5656)
Diffstat (limited to 'std/node/_fs/promises/_fs_readFile_test.ts')
-rw-r--r--std/node/_fs/promises/_fs_readFile_test.ts37
1 files changed, 37 insertions, 0 deletions
diff --git a/std/node/_fs/promises/_fs_readFile_test.ts b/std/node/_fs/promises/_fs_readFile_test.ts
new file mode 100644
index 000000000..ac3c8fdda
--- /dev/null
+++ b/std/node/_fs/promises/_fs_readFile_test.ts
@@ -0,0 +1,37 @@
+const { test } = Deno;
+import { readFile } from "./_fs_readFile.ts";
+import * as path from "../../../path/mod.ts";
+import { assertEquals, assert } from "../../../testing/asserts.ts";
+
+const testData = path.resolve(
+ path.join("node", "_fs", "testdata", "hello.txt")
+);
+
+test("readFileSuccess", async function () {
+ const data = await readFile(testData);
+
+ assert(data instanceof Uint8Array);
+ assertEquals(new TextDecoder().decode(data as Uint8Array), "hello world");
+});
+
+test("readFileEncodeUtf8Success", async function () {
+ const data = await readFile(testData, { encoding: "utf8" });
+
+ assertEquals(typeof data, "string");
+ assertEquals(data as string, "hello world");
+});
+
+test("readFileEncodingAsString", async function () {
+ const data = await readFile(testData, "utf8");
+
+ assertEquals(typeof data, "string");
+ assertEquals(data as string, "hello world");
+});
+
+test("readFileError", async function () {
+ try {
+ await readFile("invalid-file", "utf8");
+ } catch (e) {
+ assert(e instanceof Deno.errors.NotFound);
+ }
+});