import { describe, it } from "@std/testing/bdd"; import { expect } from "@std/expect"; import { PHASE_MARKERS, phaseOf } from "./ci-step-phases.ts"; describe("ci-step-phases", () => { describe("phaseOf", () => { it("reads the phase from the marker a step name starts with", () => { expect(phaseOf("๐Ÿ“ฅ Checkout repository")).toBe("setup"); expect(phaseOf("๐Ÿงช Run parallel workspace tests")).toBe("work"); expect(phaseOf("๐Ÿ“ค Upload coverage report")).toBe("shutdown"); }); it("reads a marker whether or not it carries a variation selector", () => { expect(phaseOf("๐Ÿ—๏ธ Build toolshed binary")).toBe("work"); expect(phaseOf("๐Ÿ— Build toolshed binary")).toBe("work"); }); it("gives every marker exactly one phase", () => { const phases = new Map(); for (const [marker, phase] of PHASE_MARKERS) { expect(phases.get(marker) ?? phase).toBe(phase); phases.set(marker, phase); } expect(phases.size).toBe(PHASE_MARKERS.length); }); it("counts the runner's own set-up steps as setup", () => { expect(phaseOf("Set up job")).toBe("setup"); expect(phaseOf("Set up runner")).toBe("setup"); }); it("counts the runner's own closing steps as shutdown", () => { expect(phaseOf("Complete job")).toBe("shutdown"); expect(phaseOf("Complete runner")).toBe("shutdown"); expect(phaseOf("Post ๐Ÿ“ฅ Checkout repository")).toBe("shutdown"); }); it("prefers a leading marker to the wording after it", () => { // "Post " decides a step the runner injected, and a step of ours that // begins with a marker is read by that marker instead. expect(phaseOf("๐Ÿ’ฌ Post coverage comment")).toBe("work"); }); it("returns other for a name carrying no marker it knows", () => { expect(phaseOf("Build and push dashboard image")).toBe("other"); expect(phaseOf("๐Ÿฆ– Feed the wrong dinosaur")).toBe("other"); expect(phaseOf("")).toBe("other"); }); it("reads a marker through the whitespace around a name", () => { expect(phaseOf(" ๐Ÿงน Lint codebase ")).toBe("work"); }); }); });