Workbench / The TiffinBox Build
S26 · V2·26
Tests That Catch Things
Volume 2, chapter 26. The stage scripts so far were evidence, run by hand; this stage builds the regression net and then tests the tests. A pytest and Playwright suite runs keyboard tasks, axe in both themes, accessibility-tree checks and a visual comparison of the order card in all three views (24 tests, 11–12 s, six clean runs). It found two real problems: focus left at the top of the page after a form error, with the field not marked invalid (axe passed both), and a React card rendering 71 pixels differently because JSX split one line into three text nodes. fast-check found a snapshot bug in two generated inputs; a hand-rolled mutation run showed the 20,000-sequence state-machine test killed 4 of 15 mutants, and a transition table raised the module to 12 (25 of 29 overall, the rest equivalent).
Stage 26: tests that catch things
The brief
What you'll build.
web-tests/suite/, the browser regression suite (pytest, Playwright, Chromium): a session server seeded through the public API, a fresh context per test, console errors and CSP violations failing any test at teardown, afresh_serverfixture for tests that need fixed data, and anax.pyhelper reading Chromium's accessibility tree;- suite tests: keyboard use of the filter and of an action, in the plain, React and Angular views; axe-core (pinned, 4.14.0) on six pages in light and dark; every order a heading and the status regions in the tree; the order form's errors announced, focused and linked; the order card identical in all three views and to a reviewed baseline;
- property tests (
web-tests/props.test.mjs, fast-check 4.10.2) for the filter, open orders, snapshots and lateness; in Java, 2,000 random strings throughHtml.scriptJsonand 300 random customer strings through the order form; web-tests/mutate.mjs: a small mutation runner over the pure modules, and the transition-table test it called for;- fixes found by the tests: the order form's error page (
autofocus, links to fields,aria-invalidandaria-describedby), React's card text, andapplySnapshot.
Why a real company needs this. A suite that nobody trusts is worse than none: it slows every change and catches nothing. Trust comes from tests that check what users do and see, fail for real reasons, pass reliably otherwise, and are themselves tested. Most teams learn these lessons from a production incident; this stage learns them from the build's own code.
Why now. Chapter 26 is frontend testing: levels, techniques, visual, accessibility and contract testing. The build has three views on one core, a server, a contract and twenty stage scripts; it's time for one suite that runs on every change and says whether anything broke.
What you'll have at the end.
- a 24-test browser suite, a 31-test unit layer and 33 server tests, with measured costs;
- two accessibility bugs, one rendering difference and one logic bug found and fixed;
- a mutation score for the pure modules, and ADR-0028: the testing strategy.
Theory to own
- Levels and their blind spots. What can a unit test, a jsdom component test and a real-browser test each see? (Companion, Gaps 1.)
- Accessibility testing. What does axe check, and what needs a task-based test? (Companion, Gaps 2 and drill D2.)
- Test isolation and data. When must a test own its data? (Companion, drill D1.)
- Properties and oracles. What makes a property strong enough to catch a wrong answer, not just an invalid one? (Companion, Gaps 3 and drill D4.)
- Testing the tests. What does mutation testing measure that coverage doesn't? (The chapter's lab, Experiment 2.)
Build it
Step 1: a suite with honest fixtures
Write conftest.py: start the server jar on its own port (18320, so the suite can run beside a stage script), seed only through the HTTP API (Api.order, Api.event), launch one browser per session and a new context per test. The page fixture collects console errors and uncaught exceptions and fails the test at teardown if there are any; a test that expects an error page sets page.expect_errors. Poll conditions with evaluate (the CSP blocks wait_for_function, stage 17). Write ax.py: nodes by role, names, and what is focused, from Accessibility.queryAXTree and getFullAXTree.
Checkpoint. An empty test file runs; a page with a console error fails its test.
Step 2: keyboard and accessibility-tree tests, in every view
Parametrise by view. The filter: focus the checked radio, press ArrowRight, and check the URL, the visible cards and what the accessibility tree says is focused. An action: focus a card's button, press Enter, wait for the new status, and check that focus is on the same card's new button, by role and name. Then accessibility: axe on six pages in both themes (the context bypasses CSP so axe can be injected), every order a heading in the tree, the status regions present, and the order form's error page as a keyboard and screen-reader user meets it.
Checkpoint. The keyboard tests pass in all views; you know what the error page test found.
Step 3: visual regression across the three views
Screenshot the first card in each view, in light and dark, masking the age line (it depends on the clock). Compare the three with each other and the plain one with a reviewed baseline in baselines/, counting pixels whose largest channel difference exceeds 2. UPDATE=1 rewrites baselines. Then break the stylesheet on purpose (the card's corner radius from 8 px to 6 px) and check the test fails.
Checkpoint. The test is stable across repeated full-suite runs and fails on the planted change.
Step 4: properties, and a bug in two inputs
Write props.test.mjs: any query string gives a known screen, and withShow then parseShow round-trips while keeping other parameters; after any sequence of order events, the open orders are exactly the latest version of each order still open (compared with a three-line model); a snapshot reports every card that must go; lateness never decreases with time and "late" matches the limit. In Java, check Html.scriptJson on 2,000 random strings from an alphabet of dangerous characters (no <, no `