3.4 KiB
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.
Related Links
- 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
- merges.test.js "a merge on a Sunday at 23:30 UTC counts on Monday in Berlin, in the week from that Monday", red with a week from Sunday, see "Solution"
- merges.test.js "30 days up to today, oldest first, each merge of each author on its day"
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
- merges.test.js "the time zone of the tests is Europe/Berlin"
- merges.test.js "a merge on a Sunday at 23:30 UTC counts on Monday in Berlin, in the week from that Monday"
- merges.test.js "the days stay whole days over the change to winter time"
- merges.test.js "12 months from the first, and a merge before the oldest month does not count"
Solution
MERGE_PERIODS,mergeSeriesandmedianmove fromindex.htmlintostatic/merges.js, a classic script that the page loads before its own; Node reads it byrequire. The service worker keeps it for offline starts.src/test/js/merges.test.jstests them withnode:testandnode:assert; the Gradle taskjsTestrunsnode --testwithTZ=Europe/Berlinand is part ofcheck.- With a week from Sunday,
(d.getDay() + 6) % 7replaced byd.getDay(), the test of the Sunday merge failed; with the code as it is, all 8 tests pass. - ADR 0002 records the choice of
miand the alternatives.
Additional Changes
AGENTS.mdanddashboard/README.mdnamejsTestand that the build needs Node.
Open Questions
None.