Chapter 19
Testing
19.1 Automated#
npm run typecheck # whole repo, strict mode
npm test # unit tests: sanitiser, SecureBuffer, Secret, RateLimiter, rules, PFE1 round trip
npm run test:pfe # PFE1 conformance across Node, Python, Go, C#, Ruby, PHP, Java (skips missing toolchains)
Write new unit tests in tests/*.test.ts with node:test and node:assert/strict. Import with explicit .ts
extensions; modules used by the tests must only use erasable TypeScript (no enums, no parameter properties).
19.2 Browser end-to-end#
Controls render to canvas, so drive them like a user: real mouse, touch and keyboard input through the DevTools protocol (Puppeteer or Playwright), with assertions on screenshots, network payloads and accessibility state. Useful assertions that need no pixel matching:
// The proxy never holds field content
await page.evaluate(() => document.querySelector('input').value) // ''
// The focused control's accessible name
await page.evaluate(() => document.querySelector('input').getAttribute('aria-label'))
// Typed text never appears in the DOM
(await page.evaluate(() => document.body.innerText)).includes('secret') // false
// Passwords go over the wire encrypted
request.postData() // contains "pfe1." and not the plaintext
19.3 Manual QA checklist#
- Tab through every control; the focus ring is visible; Shift+Tab goes back.
- Submit empty: errors appear, the first invalid field is focused, the toast shows the count.
- Fix a field: its error clears as you type.
- Paste text containing emoji, RTL markers and zero-width characters into a text field.
- Password: eye toggle, auto re-obscure after 10 s, copy blocked, Caps Lock warning.
- Dropdown: keyboard, type-ahead, wheel and touch scroll, flips near the bottom of the screen.
- Phone: swipe over fields scrolls without opening the keyboard; tapping opens it; the field stays visible.
- Switch light/dark and accent colours at runtime;
checkContrast()reports nothing. - Hover, tap and F1 each open an info tooltip; tapping a checkbox's ⓘ doesn't toggle it.
- OTP: wrong code shows attempts left and shakes; pasting
123-456fills every box and auto-submits. - Date: keyboard navigation (arrows, PageUp/Down, Shift+PageUp), month/year views, disabled days can't be picked, time steppers, popup fits on a phone.
- Phone:
098765 43210drops the 0 and formats; pasting+44 7911 123456switches to 🇬🇧; type-ahead in the country menu. - Network tab: password fields are
pfe1.…envelopes; replaying a request returns 400. - Switch to another window: the privacy screen covers the form.