Public: anyone can read this; the crew can change it.
A 360px picture of /claim and the first-login card on a spawned forge #15221
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/15220-a-360px-picture-of-claim-and-the-first-l → main 2 commits fork 1 thread · 1 unresolved
3 files
changed +51
−5
test/claim-360-fit.test.ts added +40
| @@ -0,0 +1,40 @@ | ||
| 1 | /** | |
| 2 | * A spawned forge's `/claim` (signed out) and `/` as its new owner (the first-login card) at 360 | |
| 3 | * px, each measured in a real Chromium with the shared `measurePageWidth`: the document must not | |
| 4 | * scroll sideways (#15220). /claim answers 404 to an admin of an ordinary forge, so only a spawned | |
| 5 | * child can be looked at. One spawned forge serves both pages. Skipped, and says so, where no | |
| 6 | * Chromium starts. | |
| 7 | */ | |
| 8 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 9 | import { findChromium } from "../src/looks/capture.ts"; | |
| 10 | import { chromiumRuns, measurePageWidth } from "./helpers/chrome.ts"; | |
| 11 | import { claimStarted, startedForge, type StartedForge } from "./helpers/claimed-forge.ts"; | |
| 12 | ||
| 13 | const found = findChromium(); | |
| 14 | const chromium = found !== undefined && chromiumRuns(found) ? found : undefined; | |
| 15 | if (chromium === undefined) console.log("SKIPPING: no chromium that starts on this machine, so /claim is not measured at 360 px"); | |
| 16 | ||
| 17 | const phone = { width: 360, height: 800 }; | |
| 18 | let forge: StartedForge; | |
| 19 | beforeAll(async () => { | |
| 20 | if (chromium !== undefined) forge = await startedForge("claim-360-"); | |
| 21 | }, 60_000); | |
| 22 | afterAll(async () => { | |
| 23 | await forge?.stop(); | |
| 24 | }); | |
| 25 | ||
| 26 | test.skipIf(chromium === undefined)("/claim and the first-login card do not scroll sideways at 360 px", async () => { | |
| 27 | const claim = await measurePageWidth(chromium!, `${forge.base}/claim`, phone); | |
| 28 | expect(claim.viewportWidth).toBe(phone.width); | |
| 29 | expect(claim.overflowing).toEqual([]); | |
| 30 | expect(claim.scrollWidth).toBeLessThanOrEqual(phone.width); | |
| 31 | ||
| 32 | const owner = await claimStarted(forge); | |
| 33 | const eq = owner.owner.indexOf("="); | |
| 34 | const card = await measurePageWidth(chromium!, `${owner.base}/`, phone, { | |
| 35 | name: owner.owner.slice(0, eq), | |
| 36 | value: owner.owner.slice(eq + 1), | |
| 37 | }); | |
| 38 | expect(card.overflowing).toEqual([]); | |
| 39 | expect(card.scrollWidth).toBeLessThanOrEqual(phone.width); | |
| 40 | }, 60_000); |
test/helpers/chrome.ts +3 −2
| @@ -218,7 +218,8 @@ export async function measurePageWidth( | ||
| 218 | 218 | binary: string, |
| 219 | 219 | url: string, |
| 220 | 220 | viewport: { width: number; height: number }, |
| 221 | cookie: { name: string; value: string }, | |
| 221 | /** The session to load the page with; none for a page a visitor sees signed out. */ | |
| 222 | cookie?: { name: string; value: string }, | |
| 222 | 223 | ): Promise<PageWidth> { |
| 223 | 224 | const expression = `(() => { |
| 224 | 225 | // documentElement.clientWidth, not window.innerWidth: after an |
| @@ -242,7 +243,7 @@ export async function measurePageWidth( | ||
| 242 | 243 | }); |
| 243 | 244 | })()`; |
| 244 | 245 | return JSON.parse( |
| 245 | await evaluateLoaded(binary, url, viewport, [cookie], expression), | |
| 246 | await evaluateLoaded(binary, url, viewport, cookie ? [cookie] : [], expression), | |
| 246 | 247 | ) as PageWidth; |
| 247 | 248 | } |
| 248 | 249 |
test/helpers/claimed-forge.ts +8 −3
| @@ -145,9 +145,9 @@ export async function startedForge(prefix: string): Promise<StartedForge> { | ||
| 145 | 145 | }; |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | /** Claim the started forge as Maria; her session cookie is `owner`. */ | |
| 149 | export async function claimedForge(prefix: string): Promise<ClaimedForge> { | |
| 150 | const { token, ...started } = await startedForge(prefix); | |
| 148 | /** Claim a started forge as Maria; returns it with her session cookie as `owner`. */ | |
| 149 | export async function claimStarted(forge: StartedForge): Promise<ClaimedForge> { | |
| 150 | const { token, ...started } = forge; | |
| 151 | 151 | const who = { token, username: "maria", email: "[email protected]" }; |
| 152 | 152 | const claimed = await fetch(`${started.base}/claim`, { |
| 153 | 153 | method: "POST", |
| @@ -161,3 +161,8 @@ export async function claimedForge(prefix: string): Promise<ClaimedForge> { | ||
| 161 | 161 | if (claimed.status !== 303) throw new Error(`claim ${claimed.status}`); |
| 162 | 162 | return { ...started, owner: (claimed.headers.get("set-cookie") ?? "").split(";")[0]! }; |
| 163 | 163 | } |
| 164 | ||
| 165 | /** Claim the started forge as Maria; her session cookie is `owner`. */ | |
| 166 | export async function claimedForge(prefix: string): Promise<ClaimedForge> { | |
| 167 | return claimStarted(await startedForge(prefix)); | |
| 168 | } |
new above
offline
Non-blocking: the first-login card assertions would also be worth checking with a 320px viewport, since 360 is the common phone width but not the smallest.