From 5854d395259f4084b1d66e9f12b54085f277527e Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Thu, 1 Dec 2022 21:09:43 -0800 Subject: [fetch] Implement `redirect: "manual"` --- test/bun.js/fetch.test.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'test/bun.js/fetch.test.js') diff --git a/test/bun.js/fetch.test.js b/test/bun.js/fetch.test.js index a703c955a..519d6bbdd 100644 --- a/test/bun.js/fetch.test.js +++ b/test/bun.js/fetch.test.js @@ -60,6 +60,48 @@ describe("fetch", () => { expect(exampleFixture).toBe(text); }); } + + it(`"redirect: "manual"`, async () => { + const server = Bun.serve({ + port: 4082, + fetch(req) { + return new Response(null, { + status: 302, + headers: { + Location: "https://example.com", + }, + }); + }, + }); + const response = await fetch(`http://${server.hostname}:${server.port}`, { + redirect: "manual", + }); + expect(response.status).toBe(302); + expect(response.headers.get("location")).toBe("https://example.com"); + expect(response.redirected).toBe(true); + server.stop(); + }); + + it(`"redirect: "follow"`, async () => { + const server = Bun.serve({ + port: 4083, + fetch(req) { + return new Response(null, { + status: 302, + headers: { + Location: "https://example.com", + }, + }); + }, + }); + const response = await fetch(`http://${server.hostname}:${server.port}`, { + redirect: "follow", + }); + expect(response.status).toBe(200); + expect(response.headers.get("location")).toBe(null); + expect(response.redirected).toBe(true); + server.stop(); + }); }); it("simultaneous HTTPS fetch", async () => { -- cgit v1.2.3