diff options
author | 2023-08-10 22:15:07 -0700 | |
---|---|---|
committer | 2023-08-10 22:15:07 -0700 | |
commit | c6d3b375b821afa117153d51f4596d25203f58dc (patch) | |
tree | 85e5395cb9738bbc4922168dcbc0cbcb69b70b7c /test/js | |
parent | 4731a460a2735380ced273caed4cb04b0f5545ba (diff) | |
download | bun-c6d3b375b821afa117153d51f4596d25203f58dc.tar.gz bun-c6d3b375b821afa117153d51f4596d25203f58dc.tar.zst bun-c6d3b375b821afa117153d51f4596d25203f58dc.zip |
async realpath (#4117)
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'test/js')
-rw-r--r-- | test/js/node/fs/fs.test.ts | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/test/js/node/fs/fs.test.ts b/test/js/node/fs/fs.test.ts index 86e64b713..5b25beded 100644 --- a/test/js/node/fs/fs.test.ts +++ b/test/js/node/fs/fs.test.ts @@ -42,7 +42,7 @@ import { join } from "node:path"; import { ReadStream as ReadStream_, WriteStream as WriteStream_ } from "./export-from.js"; import { ReadStream as ReadStreamStar_, WriteStream as WriteStreamStar_ } from "./export-star-from.js"; -import { spawnSync } from "bun"; +import { SystemError, spawnSync } from "bun"; const Buffer = globalThis.Buffer || Uint8Array; @@ -801,6 +801,36 @@ it("readlink", () => { expect(readlinkSync(actual)).toBe(realpathSync(import.meta.path)); }); +it("realpath async", async () => { + const actual = join(tmpdir(), Math.random().toString(32) + "-fs-realpath.txt"); + try { + unlinkSync(actual); + } catch (e) {} + + symlinkSync(import.meta.path, actual); + + expect(await promises.realpath(actual)).toBe(realpathSync(import.meta.path)); + const tasks = new Array(500); + for (let i = 0; i < 500; i++) { + const current = actual + i; + tasks[i] = promises.realpath(current).then( + () => { + throw new Error("should not get here"); + }, + e => { + expect(e?.path).toBe(current); + }, + ); + } + await Promise.all(tasks); + + const { promise, resolve, reject } = Promise.withResolvers(); + fs.realpath(actual, (err, path) => { + err ? reject(err) : resolve(path); + }); + expect(await promise).toBe(realpathSync(import.meta.path)); +}); + describe("stat", () => { it("file metadata is correct", () => { const fileStats = statSync(new URL("./fs-stream.js", import.meta.url).toString().slice("file://".length - 1)); |