1 Commits
Author SHA1 Message Date
sneak e465ddf45f Frontend unit tests cover durations, colours, statistics and health (closes #21)
check / check (push) Successful in 2m47s
New table-driven tests in test/unit/main.test.js: humanDuration, the
figure and sparkline colours either side of each latency boundary, a
target's min, max, average and median over an empty history, an
all-unreachable one, a mixed one, one of only answers and one whose
answers have different numbers of digits, and the four health states
either side of their thresholds, with targets found unreachable counted
as timed out. src/main.js exports the four names they need.

package.json gains a test script, which script/frontend-test runs with
the dot reporter and, if a test fails, again with the spec reporter
before failing. NODE_OPTIONS picks the reporter, since yarn appends its
arguments after the test files.

Model: opus-5-5
2026-10-04 00:50:18 +00:00
+7
View File
@@ -311,6 +311,13 @@ for (const { history, latencies, statistics } of [
latencies: [10, 40, 20, 25], latencies: [10, 40, 20, 25],
statistics: { min: 10, max: 40, average: 24, median: 23 }, statistics: { min: 10, max: 40, average: 24, median: 23 },
}, },
{
// Sorted as text rather than as numbers, these answers would put
// 100 in the middle. The average, 39.67, is rounded.
history: "answers with different numbers of digits",
latencies: [100, 9, 10],
statistics: { min: 9, max: 100, average: 40, median: 10 },
},
]) { ]) {
test(`a target's min, max, average and median latency over ${history}`, () => { test(`a target's min, max, average and median latency over ${history}`, () => {
const host = hostAfter(latencies); const host = hostAfter(latencies);