diff options
author | 2023-03-07 12:22:34 -0800 | |
---|---|---|
committer | 2023-03-07 12:22:34 -0800 | |
commit | f7e4eb83694aa007a492ef66c28ffbe6a2dae791 (patch) | |
tree | 7af25aa5c42a2e1b2b47ba1df35f8caa9054cbeb /test/bun.js/fetch_headers.test.js | |
parent | 36275a44ce7a33587bd26aad120042ab95470ff3 (diff) | |
download | bun-f7e4eb83694aa007a492ef66c28ffbe6a2dae791.tar.gz bun-f7e4eb83694aa007a492ef66c28ffbe6a2dae791.tar.zst bun-f7e4eb83694aa007a492ef66c28ffbe6a2dae791.zip |
Reorganize tests (#2332)
Diffstat (limited to 'test/bun.js/fetch_headers.test.js')
-rw-r--r-- | test/bun.js/fetch_headers.test.js | 66 |
1 files changed, 0 insertions, 66 deletions
diff --git a/test/bun.js/fetch_headers.test.js b/test/bun.js/fetch_headers.test.js deleted file mode 100644 index cd2786c08..000000000 --- a/test/bun.js/fetch_headers.test.js +++ /dev/null @@ -1,66 +0,0 @@ -import { describe, it, expect, beforeAll, afterAll } from "bun:test"; -const port = 3009; -const url = `http://localhost:${port}`; -let server; - -describe("Headers", async () => { - // Start up a single server and reuse it between tests - beforeAll(() => { - server = Bun.serve({ - fetch(req) { - const hdr = req.headers.get("x-test"); - return new Response(hdr); - }, - port: port, - }); - }); - afterAll(() => { - server.stop(); - }); - - it("Headers should work", async () => { - expect(await fetchContent({ "x-test": "header 1" })).toBe("header 1"); - }); - - it("Header names must be valid", async () => { - expect(() => fetch(url, { headers: { "a\tb:c": "foo" } })).toThrow("Invalid header name: 'a\tb:c'"); - expect(() => fetch(url, { headers: { "❤️": "foo" } })).toThrow("Invalid header name: '❤️'"); - }); - - it("Header values must be valid", async () => { - expect(() => fetch(url, { headers: { "x-test": "\0" } })).toThrow("Header 'x-test' has invalid value: '\0'"); - expect(() => fetch(url, { headers: { "x-test": "❤️" } })).toThrow("Header 'x-test' has invalid value: '❤️'"); - }); - - it("repro 1602", async () => { - const origString = "😂1234".slice(3); - - var encoder = new TextEncoder(); - var decoder = new TextDecoder(); - const roundTripString = decoder.decode(encoder.encode(origString)); - - expect(roundTripString).toBe(origString); - - // This one will pass - expect(await fetchContent({ "x-test": roundTripString })).toBe(roundTripString); - // This would hang - expect(await fetchContent({ "x-test": origString })).toBe(origString); - }); - - describe("toJSON()", () => { - it("should provide lowercase header names", () => { - const headers1 = new Headers({ "X-Test": "yep", "Content-Type": "application/json" }); - expect(headers1.toJSON()).toEqual({ "x-test": "yep", "content-type": "application/json" }); - - const headers2 = new Headers(); - headers2.append("X-Test", "yep"); - headers2.append("Content-Type", "application/json"); - expect(headers2.toJSON()).toEqual({ "x-test": "yep", "content-type": "application/json" }); - }); - }); -}); - -async function fetchContent(headers) { - const res = await fetch(url, { headers: headers }, { verbose: true }); - return await res.text(); -} |