webchat: improve logging and static serving

This commit is contained in:
Peter Steinberger
2025-12-10 15:32:29 +00:00
parent 4db69c8eac
commit 3796882d22
4 changed files with 81 additions and 25 deletions

View File

@@ -30,6 +30,11 @@ const fetchText = (url: string) =>
.on("error", reject);
});
const fetchHeaders = (url: string) =>
new Promise<http.IncomingHttpHeaders>((resolve, reject) => {
http.get(url, (res) => resolve(res.headers)).on("error", reject);
});
describe("webchat server (static only)", () => {
test("serves index.html over loopback", { timeout: 8000 }, async () => {
const port = await getFreePort();
@@ -41,4 +46,17 @@ describe("webchat server (static only)", () => {
await stopWebChatServer();
}
});
test("serves bundled JS with module-friendly content type", async () => {
const port = await getFreePort();
await startWebChatServer(port);
try {
const headers = await fetchHeaders(
`http://127.0.0.1:${port}/webchat.bundle.js`,
);
expect(headers["content-type"]).toContain("application/javascript");
} finally {
await stopWebChatServer();
}
});
});