diff options
| author | 2023-07-27 16:55:49 -0700 | |
|---|---|---|
| committer | 2023-07-27 16:55:49 -0700 | |
| commit | 007f357495d02ccccc4a75f6f04a7e127d022a72 (patch) | |
| tree | 3103a41b1fa8fb350cbeabb34e31536705e744e4 /test | |
| parent | 16a7224ce5de519afa4765594d45350c95a87adc (diff) | |
| download | bun-007f357495d02ccccc4a75f6f04a7e127d022a72.tar.gz bun-007f357495d02ccccc4a75f6f04a7e127d022a72.tar.zst bun-007f357495d02ccccc4a75f6f04a7e127d022a72.zip | |
Make readFile() async (#3850)
* less leaky
* async readfile
* Update types.zig
---------
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'test')
| -rw-r--r-- | test/js/node/fs/fs.test.ts | 28 | ||||
| -rw-r--r-- | test/js/web/fetch/fetch-leak-test-fixture.js | 3 |
2 files changed, 30 insertions, 1 deletions
diff --git a/test/js/node/fs/fs.test.ts b/test/js/node/fs/fs.test.ts index 76d06560e..ec2cd1398 100644 --- a/test/js/node/fs/fs.test.ts +++ b/test/js/node/fs/fs.test.ts @@ -196,6 +196,34 @@ it("promises.readdir on a large folder", async () => { rmSync(huge, { force: true, recursive: true }); }); +it("promises.readFile", async () => { + expect(await fs.promises.readFile(import.meta.path, "utf-8")).toEqual(readFileSync(import.meta.path, "utf-8")); + expect(await fs.promises.readFile(import.meta.path, { encoding: "latin1" })).toEqual( + readFileSync(import.meta.path, { encoding: "latin1" }), + ); + + // We do this 20 times to check for any GC issues. + for (let i = 0; i < 20; i++) { + try { + await fs.promises.readFile("/i-dont-exist", "utf-8"); + expect(false).toBeTrue(); + } catch (e: any) { + expect(e).toBeInstanceOf(Error); + expect(e.message).toBe("No such file or directory"); + expect(e.code).toBe("ENOENT"); + expect(e.errno).toBe(-2); + expect(e.path).toBe("/i-dont-exist"); + } + } +}); + +it("promises.readFile with buffer as file path", async () => { + for (let i = 0; i < 10; i++) + expect(await fs.promises.readFile(Buffer.from(import.meta.path), "utf-8")).toEqual( + readFileSync(import.meta.path, "utf-8"), + ); +}); + it("promises.readdir on a large folder withFileTypes", async () => { const huge = join(tmpdir(), "huge-folder-" + Math.random().toString(32)); rmSync(huge, { force: true, recursive: true }); diff --git a/test/js/web/fetch/fetch-leak-test-fixture.js b/test/js/web/fetch/fetch-leak-test-fixture.js index 1767cdb04..a785d6d40 100644 --- a/test/js/web/fetch/fetch-leak-test-fixture.js +++ b/test/js/web/fetch/fetch-leak-test-fixture.js @@ -14,7 +14,8 @@ await (async function runAll() { for (let j = 0; j < 32; j++) { fetches.push(fetch(SERVER)); } - await Promise.all(fetches.slice(i, i + 32)); + await Promise.all(fetches); + fetches.length = 0; i += 32; } |
