From ea80cd1cd8a0ecea511914707189ebe130d3b0ba Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Tue, 1 Mar 2022 00:50:30 -0800 Subject: [bun.js] shim async fs --- integration/bunjs-only-snippets/fs.test.js | 34 +++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'integration/bunjs-only-snippets/fs.test.js') diff --git a/integration/bunjs-only-snippets/fs.test.js b/integration/bunjs-only-snippets/fs.test.js index c4d937ca3..4c048d199 100644 --- a/integration/bunjs-only-snippets/fs.test.js +++ b/integration/bunjs-only-snippets/fs.test.js @@ -1,5 +1,11 @@ import { describe, it, expect } from "vitest"; -import { mkdirSync, existsSync, readFileSync, writeFileSync } from "node:fs"; +import { + mkdirSync, + existsSync, + readFileSync, + writeFileSync, + readFile, +} from "node:fs"; const Buffer = globalThis.Buffer || Uint8Array; @@ -36,6 +42,32 @@ describe("readFileSync", () => { }); }); +describe("readFile", () => { + it("works", async () => { + await new Promise((resolve, reject) => { + readFile(import.meta.dir + "/readFileSync.txt", "utf8", (err, text) => { + expect(text).toBe("File read successfully"); + resolve(true); + }); + }); + }); + + it("returning Buffer works", async () => { + await new Promise((resolve, reject) => { + readFile(import.meta.dir + "/readFileSync.txt", (err, text) => { + const encoded = [ + 70, 105, 108, 101, 32, 114, 101, 97, 100, 32, 115, 117, 99, 99, 101, + 115, 115, 102, 117, 108, 108, 121, + ]; + for (let i = 0; i < encoded.length; i++) { + expect(text[i]).toBe(encoded[i]); + } + resolve(true); + }); + }); + }); +}); + describe("writeFileSync", () => { it("works", () => { const path = `/tmp/${Date.now()}.writeFileSync.txt`; -- cgit v1.2.3