diff options
author | 2022-04-02 05:14:13 -0700 | |
---|---|---|
committer | 2022-04-02 05:14:13 -0700 | |
commit | c2ed8d02400a796e9a44c53fc90bfbd9c4b14df3 (patch) | |
tree | 23e1cddc1dc0cf6add205346343654d6f3bbbab5 /integration/bunjs-only-snippets/fs.test.js | |
parent | 51e5d3ea7056138769ec57221ce7720eb8d77c9a (diff) | |
download | bun-c2ed8d02400a796e9a44c53fc90bfbd9c4b14df3.tar.gz bun-c2ed8d02400a796e9a44c53fc90bfbd9c4b14df3.tar.zst bun-c2ed8d02400a796e9a44c53fc90bfbd9c4b14df3.zip |
Add more tests for Node FS
Diffstat (limited to 'integration/bunjs-only-snippets/fs.test.js')
-rw-r--r-- | integration/bunjs-only-snippets/fs.test.js | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/integration/bunjs-only-snippets/fs.test.js b/integration/bunjs-only-snippets/fs.test.js index 4ee4c652a..8b5e0c867 100644 --- a/integration/bunjs-only-snippets/fs.test.js +++ b/integration/bunjs-only-snippets/fs.test.js @@ -5,6 +5,11 @@ import { readFileSync, writeFileSync, readFile, + read, + openSync, + readSync, + closeSync, + writeSync, } from "node:fs"; const Buffer = globalThis.Buffer || Uint8Array; @@ -24,6 +29,57 @@ describe("mkdirSync", () => { }); }); +describe("readSync", () => { + const firstFourBytes = new Uint32Array( + new TextEncoder().encode("File").buffer + )[0]; + it("works with a position set to 0", () => { + const fd = openSync(import.meta.dir + "/readFileSync.txt", "r"); + const four = new Uint8Array(4); + + { + const count = readSync(fd, four, 0, 4, 0); + const u32 = new Uint32Array(four.buffer)[0]; + expect(u32).toBe(firstFourBytes); + expect(count).toBe(4); + } + closeSync(fd); + }); + it("works without position set", () => { + const fd = openSync(import.meta.dir + "/readFileSync.txt", "r"); + const four = new Uint8Array(4); + { + const count = readSync(fd, four); + const u32 = new Uint32Array(four.buffer)[0]; + expect(u32).toBe(firstFourBytes); + expect(count).toBe(4); + } + closeSync(fd); + }); +}); + +describe("writeSync", () => { + it("works with a position set to 0", () => { + const fd = openSync(import.meta.dir + "/writeFileSync.txt", "w+"); + const four = new Uint8Array(4); + + { + const count = writeSync(fd, new TextEncoder().encode("File"), 0, 4, 0); + expect(count).toBe(4); + } + closeSync(fd); + }); + it("works without position set", () => { + const fd = openSync(import.meta.dir + "/writeFileSync.txt", "w+"); + const four = new Uint8Array(4); + { + const count = writeSync(fd, new TextEncoder().encode("File")); + expect(count).toBe(4); + } + closeSync(fd); + }); +}); + describe("readFileSync", () => { it("works", () => { const text = readFileSync(import.meta.dir + "/readFileSync.txt", "utf8"); |