|
| 1 | +import { describe, expect, it, vi } from "vitest"; |
| 2 | +import { runE2eUi } from "./e2e-ui.js"; |
| 3 | + |
| 4 | +describe("runE2eUi", () => { |
| 5 | + it("cleans stale output directories before running playwright and report generation", async () => { |
| 6 | + const removeDir = vi.fn<(_: string) => Promise<void>>().mockResolvedValue(undefined); |
| 7 | + const runCommand = vi |
| 8 | + .fn<(command: string, args?: string[], options?: { cwd?: string }) => Promise<void>>() |
| 9 | + .mockResolvedValue(undefined); |
| 10 | + |
| 11 | + const code = await runE2eUi({ |
| 12 | + repoRoot: "/repo", |
| 13 | + removeDir, |
| 14 | + runCommand, |
| 15 | + }); |
| 16 | + |
| 17 | + expect(code).toBe(0); |
| 18 | + expect(removeDir).toHaveBeenCalledTimes(2); |
| 19 | + expect(removeDir).toHaveBeenNthCalledWith(1, "/repo/e2e-ui/output"); |
| 20 | + expect(removeDir).toHaveBeenNthCalledWith(2, "/repo/e2e-ui/test-results"); |
| 21 | + expect(runCommand).toHaveBeenNthCalledWith( |
| 22 | + 1, |
| 23 | + "pnpm", |
| 24 | + ["--dir", "e2e-ui", "exec", "playwright", "test", "--config", "playwright.config.ts"], |
| 25 | + { cwd: "/repo" } |
| 26 | + ); |
| 27 | + expect(runCommand).toHaveBeenNthCalledWith( |
| 28 | + 2, |
| 29 | + "pnpm", |
| 30 | + ["--dir", "e2e-ui", "exec", "tsx", "report/build-report.ts"], |
| 31 | + { cwd: "/repo" } |
| 32 | + ); |
| 33 | + }); |
| 34 | + |
| 35 | + it("still builds the report when the playwright run fails and returns a non-zero exit code", async () => { |
| 36 | + const runCommand = vi |
| 37 | + .fn<(command: string, args?: string[], options?: { cwd?: string }) => Promise<void>>() |
| 38 | + .mockRejectedValueOnce(new Error("playwright failed")) |
| 39 | + .mockResolvedValueOnce(undefined); |
| 40 | + |
| 41 | + const code = await runE2eUi({ |
| 42 | + repoRoot: "/repo", |
| 43 | + removeDir: vi.fn().mockResolvedValue(undefined), |
| 44 | + runCommand, |
| 45 | + }); |
| 46 | + |
| 47 | + expect(code).toBe(1); |
| 48 | + expect(runCommand).toHaveBeenCalledTimes(2); |
| 49 | + expect(runCommand).toHaveBeenNthCalledWith( |
| 50 | + 2, |
| 51 | + "pnpm", |
| 52 | + ["--dir", "e2e-ui", "exec", "tsx", "report/build-report.ts"], |
| 53 | + { cwd: "/repo" } |
| 54 | + ); |
| 55 | + }); |
| 56 | + |
| 57 | + it("returns a non-zero exit code when report generation fails after a successful playwright run", async () => { |
| 58 | + const runCommand = vi |
| 59 | + .fn<(command: string, args?: string[], options?: { cwd?: string }) => Promise<void>>() |
| 60 | + .mockResolvedValueOnce(undefined) |
| 61 | + .mockRejectedValueOnce(new Error("report failed")); |
| 62 | + |
| 63 | + const code = await runE2eUi({ |
| 64 | + repoRoot: "/repo", |
| 65 | + removeDir: vi.fn().mockResolvedValue(undefined), |
| 66 | + runCommand, |
| 67 | + }); |
| 68 | + |
| 69 | + expect(code).toBe(1); |
| 70 | + expect(runCommand).toHaveBeenCalledTimes(2); |
| 71 | + }); |
| 72 | +}); |
0 commit comments