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#