Something went wrong. Try again.
a reactive (signals based) hypermedia web framework (wip) stormlightlabs.github.io/volt
hypermedia frontend signals
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108import { getLibSrcPath } from "$utils/paths.js";import { readFile } from "node:fs/promises";import path from "node:path";import { describe, expect, it } from "vitest";
describe("docs generation", () => { it("should extract function documentation", async () => { const srcPath = await getLibSrcPath(); const testFile = path.join(srcPath, "core", "signal.ts"); const content = await readFile(testFile, "utf8");
expect(content).toContain("Creates a new signal"); expect(content).toContain("@param initialValue"); expect(content).toContain("@returns A Signal object"); expect(content).toContain("@example"); });
it("should extract interface documentation", async () => { const srcPath = await getLibSrcPath(); const typesFile = path.join(srcPath, "types", "volt.d.ts"); const content = await readFile(typesFile, "utf8");
expect(content).toContain("interface Signal"); expect(content).toContain("interface ComputedSignal"); });
it("should handle JSDoc with examples", () => { const jsdoc = `/** * Creates a signal * @example * const count = signal(0); * count.set(1); */`;
const hasExample = jsdoc.includes("@example"); expect(hasExample).toBe(true);
const lines = jsdoc.split("\n"); const exampleLines: string[] = []; let inExample = false;
for (const line of lines) { const trimmed = line.trim().replace(/^\*\s?/, "");
if (trimmed.startsWith("@example")) { inExample = true; continue; }
if (trimmed.startsWith("@") && !trimmed.startsWith("@example")) { inExample = false; continue; }
if (inExample && trimmed !== "" && !trimmed.startsWith("*/")) { exampleLines.push(trimmed); } }
expect(exampleLines.length).toBeGreaterThan(0); expect(exampleLines.join("\n")).toContain("signal(0)"); });
it("should clean up JSDoc comments", () => { const jsdoc = `/** * This is a description * with multiple lines * @param foo - description */`;
const lines = jsdoc.split("\n").map((line) => line.trim()).map((line) => line.replace(/^\/\*\*\s?/, "")).map(( line, ) => line.replace(/^\*\s?/, "")).map((line) => line.replace(/\*\/\s*$/, "")).filter((line) => !line.startsWith("@") && line !== "" );
const description = lines.join("\n").trim();
expect(description).toContain("This is a description"); expect(description).toContain("with multiple lines"); expect(description).not.toContain("@param"); });
it("should parse markdown structure", () => { const markdown = `# Module
## Function
Description here
\`\`\`typescriptfunction foo(): void\`\`\`
**Example:**
\`\`\`typescriptfoo();\`\`\``;
expect(markdown).toContain("# Module"); expect(markdown).toContain("## Function"); expect(markdown).toContain("**Example:**"); expect(markdown).toMatch(/```typescript[\s\S]*?```/); });});