import { assert, assertEquals, assertRejects, assertStringIncludes, } from "@std/assert"; import { fromFileUrl, join } from "@std/path"; import { regenerateFavicons } from "./regenerate-favicons.ts"; Deno.test("favicon regeneration writes missing output and preserves current output", async () => { const directory = await Deno.makeTempDir({ prefix: "dashboard-favicons-" }); const output = join(directory, "favicon-png.generated.ts"); try { assert(await regenerateFavicons(output)); const generated = await Deno.readTextFile(output); assertStringIncludes( generated, "Generated by `deno task regenerate-favicons`", ); assertStringIncludes(generated, "export const FAVICON_VERSION"); assertStringIncludes(generated, '"bad-crying": decodePng('); assertEquals(await regenerateFavicons(output), false); assertEquals(await Deno.readTextFile(output), generated); } finally { await Deno.remove(directory, { recursive: true }); } }); Deno.test("favicon regeneration preserves read errors", async () => { const directory = await Deno.makeTempDir({ prefix: "dashboard-favicons-" }); try { const error = await assertRejects(() => regenerateFavicons(directory)); assert(!(error instanceof Deno.errors.NotFound)); } finally { await Deno.remove(directory, { recursive: true }); } }); Deno.test("favicon regeneration command verifies the committed output", async () => { // The command runs under the Deno running this test, not the program named // `deno`, which would be whichever copy comes first on `PATH`. const result = await new Deno.Command(Deno.execPath(), { args: [ "run", "--allow-read", "--allow-ffi", "--allow-sys=cpus,networkInterfaces,hostname", "regenerate-favicons.ts", ], cwd: fromFileUrl(new URL(".", import.meta.url)), stdout: "piped", stderr: "piped", }).output(); const decoder = new TextDecoder(); assert(result.success, decoder.decode(result.stderr)); assertEquals( decoder.decode(result.stdout), "Dashboard favicons are already up to date.\n", ); });