Files
werkregie/doc/prs/2026-10-14-PR#83-js-tests.md
claude-code 3989dbf0f0
werkator build succeeded after 00:46
werkator/deploy build succeeded after 00:25
The build tests the JavaScript of the page (#83)
Co-authored-by: claude-code <claude-code@javagil.de>
2026-10-14 21:33:54 +02:00

3.4 KiB

PR#83: The Build Tests the JavaScript of the Page

Version: patch

WARNING: This document describes only the change applied in this PR. It may already be outdated once the next PR is merged. Historic PR documentation is not maintained along with new PRs; treat it as a snapshot.

  • werkregie PR#78: werkrevisor's hint "Missing JS test" on the counting of the merges.
  • ADR 0002: Node's own test runner for the JavaScript of the page.

Problem

index.html holds all JavaScript of the page; no automated test checks any of it. The merge chart counts the merges by the days, weeks and months of the browser's time zone, a logic with boundaries that a later change could break unnoticed, e.g. a week from Monday or a change to summer time.

Non-Goals

  • No tests of the rendered HTML or of the DOM; that would need jsdom and npm, see the ADR.
  • No move of other functions out of index.html; each later PR moves what it tests.

Specification

Feature: the build tests the JavaScript of the page

Scenario#83.01: a wrong count of the merges fails the build

… so that a change to the counting cannot reach main unnoticed.

  • Given a change that counts a merge in the wrong period
  • When the build runs
  • Then the build fails and names the test of the counting
Verified by

Scenario#83.02: the periods follow the browser's time zone

… so that a merge late in the evening counts on the day the human saw it.

  • Given a browser in the time zone Europe/Berlin and a merge on a Sunday at 23:30 UTC
  • When the merge chart counts by days and by weeks
  • Then the merge counts on Monday, in the week from that Monday
Verified by

Solution

  • MERGE_PERIODS, mergeSeries and median move from index.html into static/merges.js, a classic script that the page loads before its own; Node reads it by require. The service worker keeps it for offline starts.
  • src/test/js/merges.test.js tests them with node:test and node:assert; the Gradle task jsTest runs node --test with TZ=Europe/Berlin and is part of check.
  • With a week from Sunday, (d.getDay() + 6) % 7 replaced by d.getDay(), the test of the Sunday merge failed; with the code as it is, all 8 tests pass.
  • ADR 0002 records the choice of mi and the alternatives.

Additional Changes

  • AGENTS.md and dashboard/README.md name jsTest and that the build needs Node.

Open Questions

None.