UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

94 lines (93 loc) 3.4 kB
import { describe, expect, it } from "vitest"; import { mergeHeaders } from "./one-server-only.native.js"; describe("mergeHeaders", function () { it("merges regular headers", function () { var onto = new Headers({ "content-type": "text/html" }); var from = new Headers({ "x-custom": "value" }); mergeHeaders(onto, from); expect(onto.get("content-type")).toBe("text/html"); expect(onto.get("x-custom")).toBe("value"); }); it("overrides existing headers with set()", function () { var onto = new Headers({ "cache-control": "no-cache" }); var from = new Headers({ "cache-control": "max-age=3600" }); mergeHeaders(onto, from); expect(onto.get("cache-control")).toBe("max-age=3600"); }); it("deletes headers when value is undefined", function () { var onto = new Headers({ "x-remove": "present" }); var from = new Headers(); from.set("x-remove", "undefined"); mergeHeaders(onto, from); expect(onto.has("x-remove")).toBe(false); }); it("preserves multiple set-cookie headers from source", function () { var onto = new Headers(); var from = new Headers(); from.append("set-cookie", "session=abc123; Path=/; HttpOnly"); from.append("set-cookie", "theme=dark; Path=/"); mergeHeaders(onto, from); var cookies = onto.getSetCookie(); expect(cookies).toHaveLength(2); expect(cookies).toContain("session=abc123; Path=/; HttpOnly"); expect(cookies).toContain("theme=dark; Path=/"); }); it("preserves existing set-cookie headers on target when merging", function () { var onto = new Headers(); onto.append("set-cookie", "existing=keep; Path=/"); var from = new Headers(); from.append("set-cookie", "new=added; Path=/"); mergeHeaders(onto, from); var cookies = onto.getSetCookie(); expect(cookies).toHaveLength(2); expect(cookies).toContain("existing=keep; Path=/"); expect(cookies).toContain("new=added; Path=/"); }); it("handles three or more set-cookie headers", function () { var onto = new Headers(); var from = new Headers(); from.append("set-cookie", "a=1; Path=/"); from.append("set-cookie", "b=2; Path=/"); from.append("set-cookie", "c=3; Path=/"); mergeHeaders(onto, from); var cookies = onto.getSetCookie(); expect(cookies).toHaveLength(3); expect(cookies).toContain("a=1; Path=/"); expect(cookies).toContain("b=2; Path=/"); expect(cookies).toContain("c=3; Path=/"); }); it("merges set-cookie alongside regular headers", function () { var onto = new Headers(); var from = new Headers({ "content-type": "text/html" }); from.append("set-cookie", "session=abc; Path=/"); from.append("set-cookie", "csrf=xyz; Path=/"); mergeHeaders(onto, from); expect(onto.get("content-type")).toBe("text/html"); var cookies = onto.getSetCookie(); expect(cookies).toHaveLength(2); expect(cookies).toContain("session=abc; Path=/"); expect(cookies).toContain("csrf=xyz; Path=/"); }); it("handles source with no set-cookie headers", function () { var onto = new Headers(); var from = new Headers({ "x-foo": "bar" }); mergeHeaders(onto, from); expect(onto.getSetCookie()).toHaveLength(0); expect(onto.get("x-foo")).toBe("bar"); }); }); //# sourceMappingURL=one-server-only.test.native.js.map