Public: anyone can read this; the crew can change it.
Every animation in the stylesheet is switched off under prefers-reduced-motion, proven by a test #14878
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/14866-every-animation-in-the-stylesheet-is-swi → main 2 commits fork
1 file
changed +60
−0
test/reduced-motion.test.ts added +60
| @@ -0,0 +1,60 @@ | ||
| 1 | import { expect, test } from "bun:test"; | |
| 2 | import { readFileSync } from "node:fs"; | |
| 3 | import { motionFindings, scanMotion, type MotionFinding } from "../scripts/design-lint.ts"; | |
| 4 | import { bootCss } from "../src/design/themes.ts"; | |
| 5 | import { css } from "../src/web/style.ts"; | |
| 6 | import { homeFlowCss } from "../src/web/pages/home_flow_style.ts"; | |
| 7 | import { mapCss } from "../src/web/pages/map.ts"; | |
| 8 | import { studioCss } from "../src/web/studio/style.ts"; | |
| 9 | ||
| 10 | /** | |
| 11 | * Scope: the checker (src/design/motion.ts) only counts motion longer than 100 ms, a transition's | |
| 12 | * delay included. Anything at 100 ms or less is not proven here; the shared override's `*` block | |
| 13 | * collapses it, but this test is not full coverage of those. | |
| 14 | */ | |
| 15 | ||
| 16 | /** One line per uncovered rule, naming it; the sheet tests fail with this text. */ | |
| 17 | const describeUncovered = (found: MotionFinding[]): string[] => found.map((f) => `${f.selector} — ${f.property} ${f.ms}ms`); | |
| 18 | ||
| 19 | /** The shared sheet with its reduced-motion blocks removed. */ | |
| 20 | const withoutCalm = (sheet: string): string => sheet.replace(/@media \(prefers-reduced-motion: reduce\) \{[\s\S]*?\n\}\n/g, ""); | |
| 21 | ||
| 22 | /** Each sheet is judged as the page gets it: the shared stylesheet plus its own. */ | |
| 23 | const sheets: Record<string, string> = { | |
| 24 | "shared stylesheet": css, | |
| 25 | "boot css": css + bootCss, | |
| 26 | "home flow": css + homeFlowCss, | |
| 27 | "map": css + mapCss, | |
| 28 | "studio": css + studioCss, | |
| 29 | }; | |
| 30 | ||
| 31 | for (const [name, sheet] of Object.entries(sheets)) { | |
| 32 | test(`${name}: every transition and animation is covered by a reduced-motion override`, () => { | |
| 33 | expect(describeUncovered(motionFindings(sheet))).toEqual([]); | |
| 34 | }); | |
| 35 | } | |
| 36 | ||
| 37 | test("every css template in the tree, per-page sheets included, is covered", () => { | |
| 38 | expect(scanMotion(".")).toEqual([]); | |
| 39 | }); | |
| 40 | ||
| 41 | test("the failure output names the uncovered rule", () => { | |
| 42 | const found = motionFindings(`.zz-new { animation: spin 2s infinite; }`); | |
| 43 | expect(describeUncovered(found)).toContain(".zz-new — animation 2000ms"); | |
| 44 | }); | |
| 45 | ||
| 46 | test("without its reduced-motion block the shipped sheet has uncovered rules", () => { | |
| 47 | const stripped = withoutCalm(css); | |
| 48 | expect(stripped.length).toBeLessThan(css.length); | |
| 49 | expect(motionFindings(stripped).length).toBeGreaterThan(0); | |
| 50 | }); | |
| 51 | ||
| 52 | // Pages with an inline <style> of their own. Their sheets define no motion at all, so there is | |
| 53 | // nothing to override; this fails the day one gains an animation, so it must then be covered. | |
| 54 | const inline = ["src/web/layout.ts", "src/web/ui.ts", "src/web/compact.ts", "src/web/pages/offline.ts", "src/web/pages/waking.ts", "src/web/failed_page.ts"]; | |
| 55 | for (const file of inline) { | |
| 56 | test(`${file} holds no animation or transition`, () => { | |
| 57 | const code = readFileSync(file, "utf8").replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|\s)\/\/.*$/gm, "$1"); | |
| 58 | expect(code).not.toMatch(/@keyframes|(^|[\s;{"'`])(animation|transition)(-\w+)?\s*:/m); | |
| 59 | }); | |
| 60 | } |
new above
offline