Something went wrong. Try again.
Something went wrong. Try again.
2.6 kB · 52 lines
TypeScript
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253import { afterEach, describe, expect, it } from "vitest";import { existsSync, readFileSync } from "node:fs";import { join, resolve } from "node:path";import { realSelfCheckMainDeps, selfCheckMain } from "../../tools/selfCheckMain";import { makeTempRepo, type TempRepo } from "../helpers/tempRepo";
const root = resolve(__dirname, "../..");let repo: TempRepo;afterEach(() => repo?.cleanup());
function capture() { const out: string[] = []; const err: string[] = []; return { out, err, deps: { ...realSelfCheckMainDeps(), cwd: root, out: (s: string) => out.push(s), err: (s: string) => err.push(s) } };}
describe("the self-check command line, on the real fixture scripts and the real file system", () => { it("--list names every fixture script and none is a MISTAKE", async () => { const c = capture(); expect(await selfCheckMain(["--list"], c.deps)).toBe(0); expect(c.out.length).toBeGreaterThanOrEqual(56); expect(c.out.filter((l) => l.includes("MISTAKE"))).toEqual([]); expect(c.out.some((l) => /^hello\s+pass/.test(l))).toBe(true); });
it("a usage error exits 2 and prints nothing on stdout", async () => { const c = capture(); expect(await selfCheckMain(["--parallel", "0"], c.deps)).toBe(2); expect(c.out).toEqual([]); expect(c.err.join("\n")).toContain("--parallel"); });
it("a run writes report.txt and summary.json to the folder asked for, whatever the check said", async () => { repo = makeTempRepo({ git: false }); const c = capture(); const deps = { ...c.deps, chromePath: () => "/chrome", runCheck: async () => ({ exitCode: 1, report: "SELF-CHECK FAILED (stand-in)", scripts: [{ name: "x" }] }) as never }; const out = join(repo.dir, "nested/out"); expect(await selfCheckMain(["--out", out, "--sabotage", "verify"], deps)).toBe(1); expect(existsSync(join(out, "report.txt"))).toBe(true); expect(readFileSync(join(out, "report.txt"), "utf8")).toBe("SELF-CHECK FAILED (stand-in)\n"); expect(JSON.parse(readFileSync(join(out, "summary.json"), "utf8"))).toMatchObject({ exitCode: 1, sabotage: "verify" }); });
it("with no pinned Chrome installed under the folder it is exit 3 and says how to install it, not a skip", async () => { repo = makeTempRepo({ git: false }); repo.write("package.json", JSON.stringify({ scripts: { "chrome:install": "npx @puppeteer/browsers install chrome@155.0.8059.39" } })); const c = capture(); const code = await selfCheckMain([], { ...c.deps, cwd: repo.dir }); expect(code).toBe(3); expect(c.err.join("\n")).toMatch(/COULD NOT RUN.*not installed.*npm run chrome:install/s); });});