import { describe, expect, it } from "vitest"; import { runLighthouse } from "./run-lighthouse.mjs"; function createStream() { let output = ""; return { stream: { write: (chunk) => { output += chunk; } }, get output() { return output; }, }; } describe("run-lighthouse", () => { it("skips cleanly when npx is unavailable", () => { const stdout = createStream(); const exitCode = runLighthouse({ spawn: () => ({ error: { code: "ENOENT" }, stdout: "", stderr: "", status: null }), stdout: stdout.stream, stderr: createStream().stream, }); expect(exitCode).toBe(0); expect(stdout.output).toContain("SKIP lhci not installable"); }); it("skips cleanly when Chrome is unavailable", () => { const stdout = createStream(); const exitCode = runLighthouse({ spawn: () => ({ stdout: "Chrome installation not found\nHealthcheck failed!\n", stderr: "", status: 1 }), stdout: stdout.stream, stderr: createStream().stream, }); expect(exitCode).toBe(0); expect(stdout.output).toContain("SKIP Chrome not installed"); }); it("returns the lhci exit status for real failures", () => { const exitCode = runLighthouse({ spawn: () => ({ stdout: "assertion failed\n", stderr: "", status: 1 }), stdout: createStream().stream, stderr: createStream().stream, }); expect(exitCode).toBe(1); }); });