From d08e112d416ddee7af8d499524e40e7f193ae55a Mon Sep 17 00:00:00 2001 From: Ai Hoshino Date: Sat, 14 Oct 2023 08:51:36 +0800 Subject: fix(error): correct the `path` field in syscall error message. (#6370) * fix(error): correct the `path` field in syscall error message. Close: #6336 * fix pathlike union case --- test/js/bun/io/bun-write.test.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'test/js/bun/io/bun-write.test.js') diff --git a/test/js/bun/io/bun-write.test.js b/test/js/bun/io/bun-write.test.js index a05fa283a..fbcc99b66 100644 --- a/test/js/bun/io/bun-write.test.js +++ b/test/js/bun/io/bun-write.test.js @@ -80,6 +80,31 @@ it("Bun.file not found returns ENOENT", async () => { await gcTick(); }); +it("Bun.write file not found returns ENOENT, issue#6336", async () => { + const dst = Bun.file(path.join(tmpdir(), "does/not/exist.txt")); + try { + await gcTick(); + await Bun.write(dst, ""); + await gcTick(); + } catch (exception) { + expect(exception.code).toBe("ENOENT"); + expect(exception.path).toBe(dst.name); + } + + const src = Bun.file(path.join(tmpdir(), `test-bun-write-${Date.now()}.txt`)); + await Bun.write(src, ""); + try { + await gcTick(); + await Bun.write(dst, src); + await gcTick(); + } catch (exception) { + expect(exception.code).toBe("ENOENT"); + expect(exception.path).toBe(dst.name); + } finally { + fs.unlinkSync(src.name); + } +}); + it("Bun.write('out.txt', 'string')", async () => { for (let erase of [true, false]) { if (erase) { -- cgit v1.2.3