Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"srvx": "^0.9.1"
},
"devDependencies": {
"@happy-dom/global-registrator": "^20.0.8",
"@mitata/counters": "^0.0.8",
"@types/connect": "^3.4.38",
"@types/express": "^5.0.4",
Expand All @@ -72,6 +73,7 @@
"fetchdts": "^0.1.7",
"get-port-please": "^3.2.0",
"h3-nightly": "3.0.0-20251023-133803-7632fc3",
"happy-dom": "^20.0.8",
"hono": "^4.10.3",
"memoirist": "^0.4.0",
"mitata": "^1.0.34",
Expand Down
59 changes: 54 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 4 additions & 9 deletions src/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,14 @@ function mergeHeaders(
return target;
}

const ERROR_FROZEN = () => {
const frozenHeaders = () => {
throw new Error("Headers are frozen");
};

class FrozenHeaders extends Headers {
override set(): void {
ERROR_FROZEN();
}
override append(): void {
ERROR_FROZEN();
}
override delete(): void {
ERROR_FROZEN();
constructor(init?: HeadersInit) {
super(init);
this.set = this.append = this.delete = frozenHeaders;
}
}

Expand Down
45 changes: 45 additions & 0 deletions test/happydom.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { afterAll, beforeAll, describe, expect, test } from "vitest";
import { GlobalRegistrator } from "@happy-dom/global-registrator";

describe("happydom", () => {
// Lazy import after setting up globals to apply happydom polyfills
let h3: typeof import("../src/index.ts");

beforeAll(async () => {
await GlobalRegistrator.register({
url: "http://localhost:3000",
width: 1920,
height: 1080,
});
});

afterAll(async () => {
await GlobalRegistrator.unregister();
});

test("import h3", async () => {
h3 = await import("../src/index.ts");
});

test("render works", async () => {
const app = new h3.H3();
app.post("/", async (event) => {
return new Response(event.req.body, {
headers: event.req.headers,
});
});

const req = new Request("http://localhost:3000/", {
method: "POST",
body: JSON.stringify({ hello: "world" }),
headers: {
"Content-Type": "application/json",
},
});
const res = await app.fetch(req);
expect(res.status).toBe(200);
expect(res.headers.get("Content-Type")).toBe("application/json");
const json = await res.json();
expect(json).toEqual({ hello: "world" });
});
});