Files
WRNexusJS/packages/dev-server/test/production-hmr.test.ts
T
Clintchiz 586a6db8ff
Quality / quality (ubuntu-latest) (push) Failing after 21s
Quality / quality (windows-latest) (push) Canceled after 0s
release: WRNexusJS 0.8.0
2026-08-02 23:18:51 +05:30

75 lines
2.7 KiB
TypeScript

import { expect, test } from "bun:test";
import { createProductionHandlers, type ProdManifest } from "../src/prod.ts";
const manifest: ProdManifest = {
pages: [
{
raw: "/",
mod: { default: () => "<main>Production artifact</main>", meta: { title: "Prod" } },
},
{
raw: "/partial",
staticShell:
'<main>Build shell<template data-wrn-dynamic-placeholder="wrn-region-0"></template></main>',
mod: {
default: () =>
'<main>Request shell<wrn-dynamic-region data-wrn-dynamic="true"><strong>User 42</strong></wrn-dynamic-region></main>',
meta: { title: "Partial" },
__wrnexusRender: "partial-static",
},
},
{
raw: "/async",
mod: {
default: () => "<main>Async page</main>",
meta: { title: "Async" },
__wrnexusClientLoad: async () => ({ users: [{ id: 1, name: "Ada" }] }),
},
},
],
api: [],
realtime: [],
middleware: [],
components: [],
layouts: [],
};
const server = { upgrade: () => false } as never;
test("supervised production runtime injects reconnecting DOM-morph support", async () => {
const handlers = createProductionHandlers(manifest, { developmentRuntime: true });
const response = await handlers.fetch(new Request("http://localhost/"), server);
expect(response).toBeInstanceOf(Response);
expect(await (response as Response).text()).toContain("/__wrnexus/hmr");
});
test("production streams request regions into the build-time static shell", async () => {
const handlers = createProductionHandlers(manifest, {});
const response = (await handlers.fetch(
new Request("http://localhost/partial"),
server,
)) as Response;
const html = await response.text();
expect(response.headers.get("x-wrnexus-static-shell")).toBe("build");
expect(html).toContain("Build shell");
expect(html).not.toContain("Request shell");
expect(html).toContain("User 42");
});
test("normal production output remains free of development HMR", async () => {
const handlers = createProductionHandlers(manifest, {});
const response = await handlers.fetch(new Request("http://localhost/"), server);
expect(await (response as Response).text()).not.toContain("/__wrnexus/hmr");
});
test("production client-load endpoint returns only the requested named result", async () => {
const handlers = createProductionHandlers(manifest, {});
const response = (await handlers.fetch(
new Request("http://localhost/__wrnexus/client-load?route=%2Fasync&name=users"),
server,
)) as Response;
expect(response.status).toBe(200);
expect(response.headers.get("cache-control")).toBe("private, no-store");
expect(await response.json()).toEqual({ data: [{ id: 1, name: "Ada" }] });
});