release: WRNexusJS 0.8.0
This commit is contained in:
@@ -1,6 +1,37 @@
|
||||
import { expect, test } from "bun:test";
|
||||
import { diagnose, formatDiagnostic, parse } from "../src/index.ts";
|
||||
|
||||
test("parses explicit rendering modes and the never hydration alias", () => {
|
||||
const ast = parse(`page Marketing {
|
||||
render = "static"
|
||||
hydrate = "never"
|
||||
view { <h1>Fast</h1> }
|
||||
}`);
|
||||
expect(ast.renderMode).toBe("static");
|
||||
expect(ast.hydrate).toBe("none");
|
||||
expect(() => parse('page Invalid { render = "sometimes" view { <p>No</p> } }')).toThrow(
|
||||
"Unknown render mode",
|
||||
);
|
||||
});
|
||||
|
||||
test("parses a declarative cache policy", () => {
|
||||
const ast = parse(`page Dashboard {
|
||||
cache {
|
||||
strategy = "stale-while-revalidate"
|
||||
ttl = "5m"
|
||||
tags = ["users", "dashboard"]
|
||||
vary = ["tenant", "language"]
|
||||
}
|
||||
view { <h1>Dashboard</h1> }
|
||||
}`);
|
||||
expect(ast.cache).toEqual({
|
||||
strategy: "stale-while-revalidate",
|
||||
ttl: "5m",
|
||||
tags: '["users", "dashboard"]',
|
||||
vary: '["tenant", "language"]',
|
||||
});
|
||||
});
|
||||
|
||||
test("parses native array and object literals in state and component props", () => {
|
||||
const ast = parse(`
|
||||
component Navigation {
|
||||
@@ -111,7 +142,7 @@ test("diagnoses server-only interactive roots and accessibility issues", () => {
|
||||
});
|
||||
|
||||
test("formats parser diagnostics with stable codes and source locations", () => {
|
||||
const source = `page Broken { runtime = "worker"\n view { <main></main> } }`;
|
||||
const source = `page Broken { runtime = "quantum"\n view { <main></main> } }`;
|
||||
const [diagnostic] = diagnose(source, { file: "Broken.wrn" });
|
||||
|
||||
expect(diagnostic?.code).toBe("WRN-RUNTIME-TARGET");
|
||||
@@ -161,3 +192,11 @@ test("parses public component event declarations inside props", () => {
|
||||
expect(ast.props.map((prop) => prop.name)).toEqual(["value"]);
|
||||
expect(ast.events).toEqual([{ name: "search" }, { name: "clear" }]);
|
||||
});
|
||||
|
||||
test("parses edge and worker execution targets", () => {
|
||||
for (const runtime of ["edge", "worker", "service-worker"] as const) {
|
||||
expect(parse(`page Runtime { runtime = "${runtime}" view { <p>Hi</p> } }`).runtime).toBe(
|
||||
runtime,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user