23 lines
1.1 KiB
TypeScript
23 lines
1.1 KiB
TypeScript
import { expect, test } from "bun:test";
|
|
import { compile } from "../src/index.ts";
|
|
import { runWithRequestContext } from "@wrnexus/core";
|
|
import { renderDocument } from "@wrnexus/ssr";
|
|
|
|
test("deep conditional components render each branch once with bounded document size", async () => {
|
|
let view = "<p>Leaf</p>";
|
|
for (let i = 0; i < 12; i++) view = `{#if open}${view}{:else}<i>Closed</i>{/if}`;
|
|
const source = `component Nested {\n state open = true\n view { ${view} }\n }`;
|
|
const code = new Bun.Transpiler({ loader: "ts" }).transformSync(
|
|
compile(source, "Nested.wrn").code,
|
|
);
|
|
const mod = await import("data:text/javascript;base64," + Buffer.from(code).toString("base64"));
|
|
runWithRequestContext({} as never, () => {
|
|
const body = mod.render({});
|
|
const document = renderDocument({ meta: {}, body });
|
|
expect(body).toContain("<p>Leaf</p>");
|
|
expect(document.length).toBeLessThan(30000);
|
|
const registry = JSON.parse(document.match(/data-wrn-controls[^>]*>(.*?)<\/script>/s)![1]!);
|
|
expect(registry.filter(Array.isArray)).toHaveLength(12);
|
|
});
|
|
});
|