Give the frontend tests, and fix what they found - #267
Merged
Merged
Conversation
The frontend had no automated check beyond tsc, which is
strict and already clean. This adds vitest and starts
where reading cannot settle the question: pure functions
whose output depends on a locale or a clock.
Two bugs, both found by the first tests written against
them.
Org timestamps with a non-English weekday lost their time.
relativeDate matched the weekday with \w{3}. Kaisho writes
an English three-letter abbreviation on purpose
(_EN_WEEKDAYS in kaisho/org/clock.py, with a comment
explaining that it keeps the file locale-independent), but
these files are edited in Emacs too, and Emacs writes the
weekday in the running locale: German gives Mo, Di, Mi.
Those failed the pattern, then failed new Date(), and fell
through to the date-only branch, which drops the time --
so a 09:00 entry rendered as midnight. The Python parser
takes \S+ for exactly this reason.
The clock widget heading was always English.
formatDateHeading hardcoded en-US, and ClockWidget renders
either the translated word for today or this, so a German
user saw Heute one day and Apr 12 the next.
formatDateLabel has always used i18n.language.
src/test/setup.ts restores jsdom's localStorage: Node 22+
ships an experimental built-in that is undefined without
--localstorage-file and shadows jsdom's, so window exists
while localStorage does not. Anything importing i18n needs
it.
pnpm-workspace.yaml approves esbuild's install script.
pnpm blocks build scripts by default, which is the right
default, and vitest will not start without the binary.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The frontend had no automated check beyond
tsc, which is strict and already clean. This adds vitest and starts where reading cannot settle the question: pure functions whose output depends on a locale or a clock.Two bugs, both found by the first tests written against them.
Org timestamps with a non-English weekday lost their time.
relativeDatematched the weekday with\w{3}. Kaisho writes an English three-letter abbreviation on purpose —_EN_WEEKDAYSinkaisho/org/clock.py, with a comment explaining that it keeps the file locale-independent — but these org files are edited in Emacs too, and Emacs writes the weekday in the running locale. German givesMo,Di,Mi: two letters.Those failed the pattern, then failed
new Date(), and fell through to the date-only branch, which drops the time:The Python parser takes
\S+for exactly this reason. Now so does this one.The clock widget heading was always English.
formatDateHeadinghardcoded"en-US".ClockWidgetrenders either the translated word for today or this, so a German user saw "Heute" one day and "Apr 12" the next.formatDateLabelindateLabel.tshas always usedi18n.language; this is the same rule.Setup note.
src/test/setup.tsrestores jsdom'slocalStorage. Node 22+ ships an experimental built-in that isundefinedwithout--localstorage-file, and it shadows jsdom's — sowindowexists whilelocalStoragedoes not, which reads like a broken jsdom and is not. Anything importingi18nneeds it, sincedetectLanguage()reads the stored language at import time.pnpm testruns it. 15 tests.tscclean, build clean.The
pnpm-workspace.yamlapproves esbuild's install script; pnpm blocks build scripts by default, which is the right default, and vitest will not start without the binary it puts in place.