Phone, notch and dark mode
A responsive page checked as a phone. The check switches the screen to a phone's with emulate, adds a notch and a home bar with safeArea, asks for less motion and then for dark mode, and checks the layout with expressions that measure the page.
Run it#
cd examples/phone-dark
npx brokit check --verbose # --verbose lists every step, as below$ brokit check --verbose
brokit check: 1 scenario, Chrome 158.0.8127.36, software drawing
✓ checks/trips 11 steps, 0.9 s, 2 baselines written
✓ expect getComputedStyle(document.querySelector('.trips')).gridTempl… equals 2
✓ emulate {"size":"393x852","dpr":2,"mobile":true,"reducedMotion":"reduce"} 112 ms
✓ expect getComputedStyle(document.querySelector('.trips')).gridTempl… equals 1
✓ safeArea [59,0,34,0]
✓ expect document.querySelector('header h1').getBoundingClientRect().… ≥ 59
✓ expect innerHeight - document.querySelector('nav a').getBoundingCli… ≥ 34
✓ expect getComputedStyle(document.querySelector('.live')).animationN… equals "none"
✓ screenshot light → brokit-out/checks/trips/light.png (786×1704) [baseline: new] 286 ms
✓ emulate {"colorScheme":"dark"}
✓ expect getComputedStyle(document.body).backgroundColor equals "rgb(16, 18, 23)"
✓ screenshot dark → brokit-out/checks/trips/dark.png (786×1704) [baseline: new] 183 ms
1 scenario passed in 0.9 sThe first run writes the baselines (checks/baselines/trips/light.png and dark.png); the runs after it compare against them. In a real project you commit the baselines. They're not committed here, since they depend on the fonts of the machine that made them.

The baselines: light and dark, on a phone with a notch.
The page#
index.html is a list of trips with a header and a tab bar. style.css does four things a phone page often needs:
viewport-fit=coverin the viewport meta tag lets the page draw under the notch, andenv(safe-area-inset-top)andenv(safe-area-inset-bottom)pad the header and the tab bar so their content stays clear of it.@media (prefers-color-scheme: dark)swaps the colors.@media (min-width: 700px)puts the trips in two columns on wider screens.- A green dot pulses forever, and the cards rise in as the page opens, unless the user asked for less motion (
prefers-reduced-motion: reduce).
The check#
The check, checks/trips.check.json:
{
"note": "The trips page, first on a laptop, then as a phone with a notch, in light and dark.",
"url": "/index.html",
"viewport": { "size": "1024x700" },
"ready": "document.readyState === 'complete'",
"steps": [
{
"expect": "getComputedStyle(document.querySelector('.trips')).gridTemplateColumns.split(' ').length",
"equals": 2,
"note": "on a laptop, two columns"
},
{
"emulate": { "size": "393x852", "dpr": 2, "mobile": true, "reducedMotion": "reduce" },
"note": "now a phone, whose user asked for less motion"
},
{
"expect": "getComputedStyle(document.querySelector('.trips')).gridTemplateColumns.split(' ').length",
"equals": 1,
"note": "on a phone, one column"
},
{ "safeArea": [59, 0, 34, 0], "note": "the notch at the top, the home bar at the bottom" },
{
"expect": "document.querySelector('header h1').getBoundingClientRect().top",
"atLeast": 59,
"note": "the title is clear of the notch"
},
{
"expect": "innerHeight - document.querySelector('nav a').getBoundingClientRect().bottom",
"atLeast": 34,
"note": "the tab bar's buttons are clear of the home bar"
},
{
"expect": "getComputedStyle(document.querySelector('.live')).animationName",
"equals": "none",
"note": "with reduced motion, the pulsing dot holds still"
},
{ "screenshot": "light", "baseline": true },
{ "emulate": { "colorScheme": "dark" } },
{
"expect": "getComputedStyle(document.body).backgroundColor",
"equals": "rgb(16, 18, 23)",
"note": "the page follows the phone's dark mode"
},
{ "screenshot": "dark", "baseline": true }
]
}- The page opens on a 1024×700 laptop screen, where the first expectation sees two columns.
emulateturns the screen into a phone mid-run, as DevTools' device mode does: 393×852 CSS pixels, 2 device pixels per CSS pixel, a mobile viewport and touch. The page lays itself out again, and the next expectation sees one column.{ "safeArea": [59, 0, 34, 0] }gives the screen a 59-pixel notch at the top and a 34-pixel home bar at the bottom (top, right, bottom, left), as an iPhone has. The page sees them throughenv(safe-area-inset-*).- The two expectations after it measure the page with
getBoundingClientRect(): the title starts below the notch, and the tab bar's buttons end above the home bar. Without thesafeAreastep they fail withexpected ≥ 59, got 12. "reducedMotion": "reduce"is what makes the screenshots stable. The pulsing dot never stops, so without it two runs catch the dot at different moments: the second run fails, and brokit says why (never stops: span.live: pulse).{ "emulate": { "colorScheme": "dark" } }switches to dark mode; what's left out (the size, the motion) stays as it was.
Learn more#
- Steps:
emulate,safeAreaand expectations. - Checks and baselines: screenshots and motion.
- Scenarios:
viewportandready.