| 1 |
import { test } from "node:test"; |
| 2 |
import assert from "node:assert/strict"; |
| 3 |
import { ago, caseId, caseOutcome, casesBySuite, duration, jobTimings, live, look, newlyFinished, runDescription, runLabel, waitingApproval } 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 |
}); |
| 34 |
|
| 35 |
test("a job's timings: its wait, its phases and its peaks", () => { |
| 36 |
const job = { name: "test", status: "passed", queued_ms: 1_000, started_ms: 13_000, phases: [{ name: "image", ms: 850 }, { name: "run", ms: 125_000 }], peak_disk_mib: 2150, peak_memory_mib: 900 }; |
| 37 |
assert.deepEqual(jobTimings(job), ["waited 12.0 s", "image 850 ms", "run 2 min 5 s", "peak disk 2.1 GiB, memory 900 MiB"]); |
| 38 |
assert.deepEqual(jobTimings({ name: "x", status: "queued" }), [], "nothing reported, nothing said"); |
| 39 |
}); |
| 40 |
|
| 41 |
test("a job waits for approval only while queued", () => { |
| 42 |
assert.ok(waitingApproval({ status: "queued", approval: "waiting" })); |
| 43 |
assert.ok(!waitingApproval({ status: "running", approval: "waiting" })); |
| 44 |
assert.ok(!waitingApproval({ status: "queued", approval: "approved" })); |
| 45 |
}); |
| 46 |
|
| 47 |
test("test cases by suite, with stable ids and VS Code's outcomes", () => { |
| 48 |
const c = (suite, name, status) => ({ suite, classname: "cls", name, status, message: "", output: "", time_ms: 5 }); |
| 49 |
const by = casesBySuite([c("a", "one", "passed"), c("b", "two", "failed"), c("a", "three", "skipped"), c("", "four", "error")]); |
| 50 |
assert.deepEqual([...by.keys()], ["a", "b", "cls"]); |
| 51 |
assert.deepEqual(by.get("a").map((x) => x.name), ["one", "three"]); |
| 52 |
assert.equal(caseId("hub/o/n", c("a", "one", "passed")), "hub/o/n::a::cls::one"); |
| 53 |
assert.deepEqual(["passed", "failed", "error", "skipped"].map(caseOutcome), ["passed", "failed", "errored", "skipped"]); |
| 54 |
}); |