Files
gerbeur/api/test/lib/index-html.test.ts

24 lines
1001 B
TypeScript

import { TEST_DIR } from "../helpers.ts";
import { assertEquals, assertRejects } from "@std/assert";
import { loadIndexHtml } from "../../lib/index-html.ts";
Deno.test("loadIndexHtml: fills the placeholders, and rereads a rebuilt file", async () => {
const root = `${TEST_DIR}/index-html-${crypto.randomUUID()}`;
await Deno.mkdir(root, { recursive: true });
const path = `${root}/index.html`;
await Deno.writeTextFile(
path,
"<title>__SITE_NAME__</title><body>__BANDCAMP_PLAYER__ __DEFAULT_STYLE__ __EMAIL_ENABLED__ __FEDERATION_INCOMING__ __FEDERATION_OUTGOING__</body>",
);
assertEquals(
await loadIndexHtml(root),
"<title>gerbeur</title><body>embed smooth off on on</body>",
);
await Deno.writeTextFile(path, "<title>rebuilt __SITE_NAME__</title>");
await Deno.utime(path, new Date(), new Date(Date.now() + 60_000));
assertEquals(await loadIndexHtml(root), "<title>rebuilt gerbeur</title>");
await assertRejects(() => loadIndexHtml(`${root}/missing`));
});