import { describe, expect, it } from "vitest"; import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { dirname, join } from "node:path"; import { summarizeCatalogUsage, type CatalogUsage } from "./catalogUsage.js"; import type { RegistryItemRecord } from "./projectConfig.js"; /** * Materialize a throwaway project, summarize it, and clean up. Every case here * needs the same fixture, so the shape lives once. */ function usageOf( files: Record, registryItems?: RegistryItemRecord[], entry = "index.html", ): CatalogUsage { const dir = mkdtempSync(join(tmpdir(), "hf-catalog-test-")); try { writeFileSync( join(dir, "hyperframes.json"), JSON.stringify({ registry: "https://example.test", ...(registryItems ? { registryItems } : {}), }), ); for (const [rel, html] of Object.entries(files)) { const path = join(dir, rel); mkdirSync(dirname(path), { recursive: true }); writeFileSync(path, html); } return summarizeCatalogUsage(dir, join(dir, entry)); } finally { rmSync(dir, { recursive: true, force: true }); } } /** Same as {@link usageOf}, but writes `hyperframes.json` verbatim. */ function usageOfRawConfig(configText: string | null): CatalogUsage { const dir = mkdtempSync(join(tmpdir(), "hf-catalog-test-")); try { if (configText !== null) writeFileSync(join(dir, "hyperframes.json"), configText); writeFileSync(join(dir, "index.html"), entryDoc()); return summarizeCatalogUsage(dir, join(dir, "index.html")); } finally { rmSync(dir, { recursive: true, force: true }); } } function mountTag(src: string): string { return `
`; } /** Render entry: a plain document, never `