Add frontend checks, run from the repo
The server has go test; the frontend had nothing, and the things most likely to break there are the ones hardest to see: the arithmetic behind the charts, a panel lost while shuffling tabs, a label that truncates on a phone none of us owns. There is no browser in this loop, so these are what can be checked without one. They read the real code rather than copying it. The app is one long IIFE with nothing exported, and adding a module system or a build step to make it testable would be a large change in service of a small one — so checks/extract.mjs reads src/app.js, brace-matches the declarations a check asks for, and evaluates them. Rename a function and it throws by name. A check quietly exercising a stale copy of the code would be worse than no check, and that is the failure mode this avoids. calendarGridStart is pulled out of renderCalendar as part of this. It is the one line of the month grid that is easy to get wrong and impossible to notice — a month starting on the week's first day needs no backing up, one starting the day before needs six — so it earns a name and a test. The width figures are estimates, not measurements: layout numbers come out of style.css so they cannot drift, text is sized from per-character advances, and the pass mark demands a few pixels of headroom because the estimate is only good to a few percent. They will catch a sixth tab or a longer label. They will not settle a two-pixel question, and nothing here replaces looking at a phone. No new dependencies: nodejs is already in the devShell for `node --check`, and checks/ sits outside src/ so it is not served with the app.
This commit is contained in:
@@ -104,6 +104,13 @@ puppy-tracker/
|
||||
│ ├── webpush.go # VAPID + RFC 8291/8188 message encryption
|
||||
│ ├── pedigree.go # SKK lookup, background crawl, per-dog cache
|
||||
│ └── htmlutil.go # scraping helpers for the pedigree crawl
|
||||
├── checks/ # frontend checks (see Checks); `node checks/run.mjs`
|
||||
│ ├── run.mjs # runs every suite, exits non-zero on a failure
|
||||
│ ├── extract.mjs # pulls declarations out of app.js so checks run real code
|
||||
│ ├── assert.mjs
|
||||
│ ├── excluded-days.mjs
|
||||
│ ├── calendar.mjs
|
||||
│ └── layout.mjs
|
||||
└── src/ # the web app
|
||||
├── index.html
|
||||
├── app.js
|
||||
@@ -115,6 +122,37 @@ puppy-tracker/
|
||||
└── icon-180.png, icon-192.png, icon-512.png
|
||||
```
|
||||
|
||||
## Checks
|
||||
|
||||
```sh
|
||||
nix develop -c sh -c 'cd server && go test ./...' # the server
|
||||
nix develop -c node checks/run.mjs # the frontend
|
||||
```
|
||||
|
||||
The server has `go test`; `checks/` is the other half. The frontend has no
|
||||
build step and no test framework, so these are plain scripts with no
|
||||
dependencies beyond the `nodejs` already in the devShell. They cover the things
|
||||
that are invisible until they bite:
|
||||
|
||||
- **Arithmetic behind the charts** — what a day marked *not counted* does and
|
||||
does not take out of the numbers, and the month grid's week starts, leap
|
||||
years and month boundaries.
|
||||
- **Structure** — that every panel still sits in exactly one tab (losing one
|
||||
while shuffling tabs is silent), that the stylesheet's braces and comments
|
||||
balance, that the global `[hidden]` rule is still there.
|
||||
- **Width budgets** — whether the tab labels and the two day-bar timers still
|
||||
fit the phones people use.
|
||||
|
||||
Two things worth knowing about them. They **extract the real functions out of
|
||||
`src/app.js`** rather than copying them, so a check cannot quietly go on
|
||||
testing a stale copy — rename a function and `checks/extract.mjs` throws by
|
||||
name. And the width figures are **estimates, not measurements**: there is no
|
||||
browser in the loop, so the layout numbers are read out of `style.css` and the
|
||||
text is sized from per-character advances, with a couple of pixels of headroom
|
||||
demanded because the estimate is only good to a few percent. They will catch a
|
||||
sixth tab or a longer label; they will not settle a two-pixel question. A real
|
||||
phone is still the arbiter of anything visual.
|
||||
|
||||
## Run locally
|
||||
|
||||
```sh
|
||||
|
||||
Reference in New Issue
Block a user