| 1 |
import { test } from "node:test"; |
| 2 |
import assert from "node:assert/strict"; |
| 3 |
import { ago, duration, live, look, newlyFinished, runDescription, runLabel } from "../out/flowview.mjs"; |
| 4 |
|
| 5 |
const run = (over = {}) => ({ number: 12, bookmark: "main", heads: ["a".repeat(64)], status: "passed", trigger: "push", actor: "andy", created_ms: 1_000_000, finished_ms: 1_125_000, url: "", state: "", pipeline_hash: "", error: "", ...over }); |
| 6 |
|
| 7 |
test("statuses look the part", () => { |
| 8 |
assert.equal(look("running").icon, "sync~spin", "running turns"); |
| 9 |
assert.equal(look("passed").color, "testing.iconPassed"); |
| 10 |
assert.equal(look("failed").icon, "error"); |
| 11 |
assert.equal(look("queued").word, "queued"); |
| 12 |
assert.ok(live("queued") && live("running") && !live("passed")); |
| 13 |
}); |
| 14 |
|
| 15 |
test("runs are labelled and described", () => { |
| 16 |
assert.equal(runLabel(run()), "#12 main"); |
| 17 |
assert.equal(runLabel(run({ bookmark: "" })), `#12 change ${"a".repeat(12)}`); |
| 18 |
assert.equal(runDescription(run(), 1_125_000 + 10_000), "passed in 2 min 5 s · push by andy · 3 minutes ago"); |
| 19 |
assert.match(runDescription(run({ status: "queued", finished_ms: null, queue_position: 3, trigger: "rerun:9" }), 1_000_000), /^queued \(#3 in line\) · re-run of #9 by andy · just now$/); |
| 20 |
assert.equal(duration(3200), "3.2 s"); |
| 21 |
assert.equal(ago(0, 7_200_000), "2 hours ago"); |
| 22 |
}); |
| 23 |
|
| 24 |
test("a run is announced once, when it stops being live", () => { |
| 25 |
const before = new Map([["a#1", "running"], ["a#2", "passed"], ["a#3", "queued"]]); |
| 26 |
const now = [ |
| 27 |
{ key: "a#1", run: run({ status: "failed" }) }, |
| 28 |
{ key: "a#2", run: run({ status: "passed" }) }, |
| 29 |
{ key: "a#3", run: run({ status: "running" }) }, |
| 30 |
{ key: "a#4", run: run({ status: "passed" }) }, |
| 31 |
]; |
| 32 |
assert.deepEqual(newlyFinished(before, now).map((x) => x.key), ["a#1"], "only the one that finished; new runs are not news"); |
| 33 |
}); |