|
| 1 | +import { test, describe } from "node:test" |
| 2 | +import assert from "node:assert/strict" |
| 3 | +import { OUTCOMES, emojiFor } from "../src/outcome.mjs" |
| 4 | +import { renderJobSummary } from "../src/report.mjs" |
| 5 | + |
| 6 | +/** |
| 7 | + * The outcome should be readable at a glance. |
| 8 | + * |
| 9 | + * "## Test Companion — Run broke" and "## Test Companion — Succeeded" look the |
| 10 | + * same in a crowded pull request thread, and the one that needs attention is |
| 11 | + * the one that blends in. |
| 12 | + */ |
| 13 | + |
| 14 | +describe("every outcome has a mark of its own", () => { |
| 15 | + test("no two outcomes share one", () => { |
| 16 | + const marks = Object.values(OUTCOMES).map(emojiFor) |
| 17 | + assert.equal(new Set(marks).size, marks.length, `marks collide: ${marks.join(" ")}`) |
| 18 | + }) |
| 19 | + |
| 20 | + test("every outcome has one", () => { |
| 21 | + for (const o of Object.values(OUTCOMES)) { |
| 22 | + assert.ok(emojiFor(o), `${o} has no mark`) |
| 23 | + } |
| 24 | + }) |
| 25 | + |
| 26 | + test("an outcome we do not know does not break the heading", () => { |
| 27 | + // A newer CLI could report something this Action has never heard of. |
| 28 | + // A missing mark is a cosmetic loss; a crash is a lost report. |
| 29 | + assert.equal(emojiFor("Something new"), "") |
| 30 | + assert.equal(emojiFor(undefined), "") |
| 31 | + }) |
| 32 | + |
| 33 | + test("the heading carries it", () => { |
| 34 | + const body = renderJobSummary({ workflow: "fix", outcome: OUTCOMES.RUN_BROKE, summary: {}, runUrl: "https://run" }) |
| 35 | + assert.match(body.split("\n")[0], /^## Test Companion — .+ Run broke$/u) |
| 36 | + assert.ok(body.split("\n")[0].includes(emojiFor(OUTCOMES.RUN_BROKE))) |
| 37 | + }) |
| 38 | + |
| 39 | + test("and so does the row, so the table reads on its own", () => { |
| 40 | + const body = renderJobSummary({ workflow: "fix", outcome: OUTCOMES.TESTS_FAILED, summary: {}, runUrl: "https://run" }) |
| 41 | + assert.match(body, new RegExp(`\\| Outcome \\| ${emojiFor(OUTCOMES.TESTS_FAILED)} Tests failed \\|`, "u")) |
| 42 | + }) |
| 43 | + |
| 44 | + test("a success still reads as a success", () => { |
| 45 | + const body = renderJobSummary({ workflow: "generate", outcome: OUTCOMES.SUCCEEDED, summary: {}, runUrl: "https://run" }) |
| 46 | + assert.match(body.split("\n")[0], /Succeeded$/) |
| 47 | + }) |
| 48 | +}) |
0 commit comments