Testing guide / Browser
What the page did
A screen can look right and still have thrown. The page handle keeps what the browser saw: page.errors is what the page threw, its console.error calls and any Mesa warning, and page.failed is each response of 400 and above. check.clean(step) fails the step if either grew since the last clean, and page.shot(path) writes a PNG as evidence.
import { existsSync } from 'node:fs'
import { drive } from '@frontierjs/testing/drive'
const PORT = 49232
const URL = `http://127.0.0.1:${PORT}/`
const html = '<title>Home</title><script>fetch("/account")</script>'
const server = `Bun.serve({ port: ${PORT}, fetch: (req) => new URL(req.url).pathname === '/account'
? new Response('no', { status: 401 })
: new Response(${JSON.stringify(html)}, { headers: { 'content-type': 'text/html' } }) })`
await drive({
servers: [{ name: 'app', cmd: ['bun', '-e', server], url: URL }],
open: URL,
}, async (page, check) => {
check.allow(/401 .*account/)
check.clean('loading the page')
await page.shot('./home.png')
check('the screenshot was written', existsSync('./home.png'))
})
errors and failed are separate on purpose: a signed-out page asks for its account and gets a 401 by design. check.allow names that one by pattern, and everything else still fails the step. Read errors after every step that can fail, since a component that throws mid-render leaves a partial tree and assertions about what is there still pass.
What else it can do
check.cleanruns by itself after the last step, so a throw in the last step cannot slip outpage.evaluate(body)runs the body of an async function in the page andreturnanswers it; never return a barenull, wrap it in an objectpage.newPage(url)opens a second page whose errors land in the sameerrorsarrayopenChrome({ clock: true })holds the page's time still untilpage.clock(500),page.clock('settle')orpage.clock('real')moves itcreateNetwork(page)from@frontierjs/mesa/drivegoes offline and back, and closes the page's sockets the way a real outage doesPAGE_AUDITis an expression that returns the page-level accessibility problems a machine can settle, such aslang, one<main>and one<h1>page.downloadsis the directory every downloaded file lands in- Focus is emulated, since a headless window would blur about thirty seconds in and
el.focus()would then fire nofocusevent
In depth: Mesa's drive, Mesa's testing