aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js/fetch.test.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/bun.js/fetch.test.js')
-rw-r--r--test/bun.js/fetch.test.js42
1 files changed, 42 insertions, 0 deletions
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 () => {