release: WRNexusJS 0.3.2

This commit is contained in:
2026-07-22 20:10:44 +05:30
parent 304819dfe9
commit 58ba2f2046
63 changed files with 242 additions and 121 deletions
+84 -1
View File
@@ -1,5 +1,5 @@
import { test, expect } from "bun:test";
import { writeFileSync, mkdirSync } from "node:fs";
import { writeFileSync, mkdirSync, mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { pathToFileURL } from "node:url";
@@ -1105,3 +1105,86 @@ test("WRN 0.3 metadata, computed values, loaders, and actions compile additively
expect(output).toContain("export const __wrnexusActions");
expect(output).toContain('data-wrn-hydrate="idle"');
});
test("page state is available inside server-rendered if blocks", () => {
const source = `
page Pricing {
state billingCycle = "monthly"
view {
{#if billingCycle === "annual"}
<p>Annual</p>
{:else}
<p>Monthly</p>
{/if}
}
}
`;
const ast = parse(source);
const code = generate(ast);
expect(code).toContain("const { billingCycle } = __state;");
expect(code).toContain('billingCycle === "annual"');
});
test("page state SSR condition renders without ReferenceError", async () => {
const root = mkdtempSync(join(tmpdir(), "wrnexus-page-state-"));
const generatedFile = join(root, "pricing.generated.ts");
try {
const source = `
page Pricing {
state billingCycle = "monthly"
view {
{#if billingCycle === "annual"}
<p>Annual</p>
{:else}
<p>Monthly</p>
{/if}
}
}
`;
const code = generate(parse(source));
expect(code).toContain("const { billingCycle } = __state;");
expect(code).toContain('billingCycle === "annual"');
writeFileSync(generatedFile, code, "utf8");
const moduleUrl = pathToFileURL(generatedFile).href + `?test=${Date.now()}-${Math.random()}`;
const generatedModule = await import(moduleUrl);
const html = await generatedModule.default({});
expect(html).toContain("<p>Monthly</p>");
expect(html).not.toContain("<p>Annual</p>");
} finally {
rmSync(root, {
recursive: true,
force: true,
});
}
});
test("page state is declared for server-rendered control blocks", () => {
const source = `
page Pricing {
state billingCycle = "monthly"
view {
{#if billingCycle === "annual"}
<p>Annual</p>
{:else}
<p>Monthly</p>
{/if}
}
}
`;
const code = generate(parse(source));
expect(code).toContain("const { billingCycle } = __state;");
expect(code).toContain('billingCycle === "annual"');
});