Something went wrong. Try again.
Something went wrong. Try again.
2.6 kB · 41 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233343536373839404142import { afterEach, describe, expect, it } from "vitest";import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";import { tmpdir } from "node:os";import { join } from "node:path";import { JSDOM } from "jsdom";import { findChrome } from "../helpers/chrome";import { makeKit, readerFiles } from "../../tools/panelKit";
/** P4-7 preparation in real Chrome: every case really fails the way it was designed to, and the reports hand nothing away. */
let out: string | undefined;afterEach(() => out && rmSync(out, { recursive: true, force: true }));
const EXPECTED_REASON: Record<string, string> = { typo: "mismatch", balance: "mismatch", error: "mismatch", "restyled-link": "drifted", "heading-reworded": "mismatch", capitals: "mismatch", pending: "mismatch", menu: "not-visible", gone: "not-found" };
describe("the cold-reader kit", () => { it("makes nine reports from real runs, each failing the designed way, with the answers kept in a separate file", async () => { out = mkdtempSync(join(tmpdir(), "aite-kit-")); const entries = await makeKit({ chrome: findChrome(), outDir: out, seed: 42 }); expect(entries).toHaveLength(9); expect(readerFiles(out)).toEqual(Array.from({ length: 9 }, (_, i) => `report-${i + 1}.html`)); expect(existsSync(join(out, "answers.json"))).toBe(true); for (const e of entries) expect(e.failure.reason, e.case).toBe(EXPECTED_REASON[e.case]); expect(JSON.parse(readFileSync(join(out, "answers.json"), "utf8"))).toHaveLength(9); }, 600_000);
it("the reports do not give the answer away: no case id, no verdict word, no hint of the truth, a failed step with a picture in each", async () => { out = mkdtempSync(join(tmpdir(), "aite-kit-")); const entries = await makeKit({ chrome: findChrome(), outDir: out, seed: 3 }); for (const e of entries) { const html = readFileSync(join(out, e.file), "utf8"); expect(html, e.file).not.toMatch(/app[- ]broken|script[- ]out|out of date|answers\.json|cold-reader/i); for (const id of ["restyled-link", "heading-reworded", "capitals", "typo"]) expect(html, `${e.file} ${id}`).not.toContain(id); const doc = new JSDOM(html).window.document; expect(doc.querySelector("article.failed"), e.file).not.toBeNull(); expect(doc.querySelector("article.failed img"), e.file).not.toBeNull(); expect(doc.title).toBe("aite: send money - FAILED"); expect(doc.querySelectorAll("script, button").length).toBe(0); // the file report: no script, and no verdict buttons to hint at the choices } }, 600_000);});