From 7a1ebec26fc1a3f480fca5e5508d5ceda5a2ebcf Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Fri, 28 Jul 2023 15:44:05 -0700 Subject: Support file: URLs in `fetch` (#3858) * Support file: URLs in `fetch` * Update url.zig --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> --- test/js/web/fetch/fetch.test.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test/js/web/fetch/fetch.test.ts') diff --git a/test/js/web/fetch/fetch.test.ts b/test/js/web/fetch/fetch.test.ts index 768818420..d7fc87ade 100644 --- a/test/js/web/fetch/fetch.test.ts +++ b/test/js/web/fetch/fetch.test.ts @@ -1203,3 +1203,13 @@ it("new Request(https://example.com, otherRequest) uses url from left instead of expect(req2.url).toBe("http://localhost/def"); expect(req2.headers.get("foo")).toBe("bar"); }); + +it("fetch() file:// works", async () => { + expect(await (await fetch(import.meta.url)).text()).toEqual(await Bun.file(import.meta.path).text()); + expect(await (await fetch(new URL("fetch.test.ts", import.meta.url))).text()).toEqual( + await Bun.file(Bun.fileURLToPath(new URL("fetch.test.ts", import.meta.url))).text(), + ); + expect(await (await fetch(new URL("file with space in the name.txt", import.meta.url))).text()).toEqual( + await Bun.file(Bun.fileURLToPath(new URL("file with space in the name.txt", import.meta.url))).text(), + ); +}); -- cgit v1.2.3