diff options
Diffstat (limited to 'test/js')
-rw-r--r-- | test/js/bun/http/bun-server.test.ts | 4 | ||||
-rw-r--r-- | test/js/bun/util/inspect.test.js | 2 | ||||
-rw-r--r-- | test/js/web/fetch/body-stream.test.ts | 5 | ||||
-rw-r--r-- | test/js/web/fetch/fetch.test.ts | 40 |
4 files changed, 42 insertions, 9 deletions
diff --git a/test/js/bun/http/bun-server.test.ts b/test/js/bun/http/bun-server.test.ts index 37675c25d..9fd97e3cb 100644 --- a/test/js/bun/http/bun-server.test.ts +++ b/test/js/bun/http/bun-server.test.ts @@ -205,7 +205,7 @@ describe("Server", () => { }, }); try { - const url = `http://${server.hostname}:${server.port}`; + const url = `http://${server.hostname}:${server.port}/`; const response = await server.fetch(url); expect(await response.text()).toBe("Hello World!"); expect(response.status).toBe(200); @@ -222,7 +222,7 @@ describe("Server", () => { }, }); try { - const url = `http://${server.hostname}:${server.port}`; + const url = `http://${server.hostname}:${server.port}/`; const response = await server.fetch(new Request(url)); expect(await response.text()).toBe("Hello World!"); expect(response.status).toBe(200); diff --git a/test/js/bun/util/inspect.test.js b/test/js/bun/util/inspect.test.js index e91204c69..4d5165543 100644 --- a/test/js/bun/util/inspect.test.js +++ b/test/js/bun/util/inspect.test.js @@ -107,7 +107,7 @@ it("Request object", () => { ` Request (0 KB) { method: "GET", - url: "https://example.com", + url: "https://example.com/", headers: Headers {} }`.trim(), ); diff --git a/test/js/web/fetch/body-stream.test.ts b/test/js/web/fetch/body-stream.test.ts index 64b3434e1..8e2baf92a 100644 --- a/test/js/web/fetch/body-stream.test.ts +++ b/test/js/web/fetch/body-stream.test.ts @@ -1,7 +1,6 @@ // @ts-nocheck -import { file, gc, serve, ServeOptions } from "bun"; -import { afterAll, afterEach, describe, expect, it, test } from "bun:test"; -import { readFileSync } from "fs"; +import { gc, ServeOptions } from "bun"; +import { afterAll, describe, expect, it, test } from "bun:test"; var port = 0; diff --git a/test/js/web/fetch/fetch.test.ts b/test/js/web/fetch/fetch.test.ts index d7fc87ade..ec73069de 100644 --- a/test/js/web/fetch/fetch.test.ts +++ b/test/js/web/fetch/fetch.test.ts @@ -30,6 +30,14 @@ afterAll(() => { const payload = new Uint8Array(1024 * 1024 * 2); crypto.getRandomValues(payload); +it("new Request(invalid url) throws", () => { + expect(() => new Request("http")).toThrow(); + expect(() => new Request("")).toThrow(); + expect(() => new Request("http://[::1")).toThrow(); + expect(() => new Request("https://[::1")).toThrow(); + expect(() => new Request("!")).toThrow(); +}); + describe("AbortSignal", () => { beforeEach(() => { startServer({ @@ -1165,9 +1173,9 @@ it("should not be able to parse json from empty body", () => { }); it("#874", () => { - expect(new Request(new Request("https://example.com"), {}).url).toBe("https://example.com"); - expect(new Request(new Request("https://example.com")).url).toBe("https://example.com"); - expect(new Request({ url: "https://example.com" }).url).toBe("https://example.com"); + expect(new Request(new Request("https://example.com"), {}).url).toBe("https://example.com/"); + expect(new Request(new Request("https://example.com")).url).toBe("https://example.com/"); + expect(new Request({ url: "https://example.com" }).url).toBe("https://example.com/"); }); it("#2794", () => { @@ -1213,3 +1221,29 @@ it("fetch() file:// works", async () => { await Bun.file(Bun.fileURLToPath(new URL("file with space in the name.txt", import.meta.url))).text(), ); }); + +it("cloned response headers are independent before accessing", () => { + const response = new Response("hello", { + headers: { + "content-type": "text/html; charset=utf-8", + }, + }); + const cloned = response.clone(); + cloned.headers.set("content-type", "text/plain"); + expect(response.headers.get("content-type")).toBe("text/html; charset=utf-8"); +}); + +it("cloned response headers are independent after accessing", () => { + const response = new Response("hello", { + headers: { + "content-type": "text/html; charset=utf-8", + }, + }); + + // create the headers + response.headers; + + const cloned = response.clone(); + cloned.headers.set("content-type", "text/plain"); + expect(response.headers.get("content-type")).toBe("text/html; charset=utf-8"); +}); |