diff options
author | 2022-03-01 00:50:30 -0800 | |
---|---|---|
committer | 2022-03-01 00:50:30 -0800 | |
commit | ea80cd1cd8a0ecea511914707189ebe130d3b0ba (patch) | |
tree | e0a48b75cf057fdb5f77f33c98ddc0e05d9a4eb6 /integration/bunjs-only-snippets/fs.test.js | |
parent | 114c0e8ed2a0eea835139ece3677efce09a8b702 (diff) | |
download | bun-ea80cd1cd8a0ecea511914707189ebe130d3b0ba.tar.gz bun-ea80cd1cd8a0ecea511914707189ebe130d3b0ba.tar.zst bun-ea80cd1cd8a0ecea511914707189ebe130d3b0ba.zip |
[bun.js] shim async fs
Diffstat (limited to 'integration/bunjs-only-snippets/fs.test.js')
-rw-r--r-- | integration/bunjs-only-snippets/fs.test.js | 34 |
1 files changed, 33 insertions, 1 deletions
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`; |