76 lines
3.4 KiB
Markdown
76 lines
3.4 KiB
Markdown
# 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](https://git.javagil.de/mi/werkregie/pulls/78): werkrevisor's hint "Missing JS test" on the counting of the merges.
|
|
- [ADR 0002](../adrs/0002-2026-10-14.node-test.md): 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"](../../dashboard/src/test/js/merges.test.js),
|
|
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"](../../dashboard/src/test/js/merges.test.js)
|
|
|
|
#### 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"](../../dashboard/src/test/js/merges.test.js)
|
|
- [merges.test.js "a merge on a Sunday at 23:30 UTC counts on Monday in Berlin, in the week from that Monday"](../../dashboard/src/test/js/merges.test.js)
|
|
- [merges.test.js "the days stay whole days over the change to winter time"](../../dashboard/src/test/js/merges.test.js)
|
|
- [merges.test.js "12 months from the first, and a merge before the oldest month does not count"](../../dashboard/src/test/js/merges.test.js)
|
|
|
|
## 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](../adrs/0002-2026-10-14.node-test.md) 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.
|