Public: anyone can read this; the crew can change it.

Each look records whether its page scrolls sideways and how many screens tall it is, and the pull's looks name any phone page that scrolls sideways #9256

Parked opened this
Closed without merging

scout/forge:scout/9249-each-look-records-whether-its-page-scrol → main 3 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
7 files changed +139 −11
src/checks/looks.ts +8 −1
@@ -48,7 +48,14 @@ export function parseLooks(raw: unknown): LookVitals[] {
4848 const skipped = words(rec.skipped);
4949 if (skipped !== null) out.push({ look, skipped });
5050 else if (rec.entries && typeof rec.entries === "object" && !Array.isArray(rec.entries))
51 out.push({ look, entries: rec.entries });
51 out.push({
52 look,
53 entries: rec.entries,
54 ...(typeof rec.sideways === "boolean" ? { sideways: rec.sideways } : {}),
55 ...(typeof rec.screens === "number" && Number.isFinite(rec.screens) && rec.screens >= 0
56 ? { screens: rec.screens }
57 : {}),
58 });
5259 }
5360 return out;
5461 }
src/checks/progress.ts +3 −2
@@ -9,7 +9,7 @@
99
1010 import type { CheckSummary } from "../core/runs.ts";
1111 import { readLooks } from "./looks.ts";
12 import { checkSteps, stepsWords, vitalsRows, type LookVitals } from "./summary.ts";
12 import { checkSteps, sidewaysNotices, stepsWords, vitalsRows, type LookVitals } from "./summary.ts";
1313 import { parseTestsRow, testsRowLine } from "./tests-row.ts";
1414 import { readRunLog } from "../runs/log.ts";
1515
@@ -120,5 +120,6 @@ export function vitalsLine(looks: readonly LookVitals[]): string {
120120 ? `${g.look}: skipped: ${g.skipped}`
121121 : `${g.look}: ${g.rows.map((r) => `${r.vital} ${r.value}${r.grade === "n/a" ? "" : ` ${r.grade}`}`).join(", ")}`,
122122 );
123 return groups.length === 0 ? "" : `vitals ${groups.join("; ")}`;
123 const said = groups.length === 0 ? "" : `vitals ${groups.join("; ")}`;
124 return [said, ...sidewaysNotices(looks)].filter((w) => w !== "").join(" · ");
124125 }
src/checks/summary.ts +23 −1
@@ -220,7 +220,14 @@ export function stepsWords(steps: readonly CheckStep[]): string {
220220
221221 /** One look's recorded entries, or why it has none; plain data from the caller. */
222222 export type LookVitals =
223 | { readonly look: string; readonly entries: Entries }
223 | {
224 readonly look: string;
225 readonly entries: Entries;
226 /** `scrollWidth > innerWidth`; absent when the page did not say. */
227 readonly sideways?: boolean;
228 /** `scrollHeight / innerHeight`, one decimal; absent when unknown. */
229 readonly screens?: number;
230 }
224231 | { readonly look: string; readonly skipped: string };
225232
226233 /** One cell row of a look's table: words only, escaped where they are rendered. */
@@ -267,3 +274,18 @@ export function vitalsRows(looks: readonly LookVitals[]): readonly LookRows[] {
267274 return { look: l.look, skipped: "", rows };
268275 });
269276 }
277
278 /**
279 * One plain line for each phone look whose page scrolls sideways, e.g.
280 * `/preview-admin/sample/held scrolls sideways at phone width`. A page that
281 * fits, or one that did not say, adds nothing; no verdict.
282 */
283 export function sidewaysNotices(looks: readonly LookVitals[]): string[] {
284 const out: string[] = [];
285 for (const l of looks) {
286 if (!("entries" in l) || l.sideways !== true) continue;
287 if (l.look !== "phone" && !l.look.startsWith("phone ")) continue;
288 out.push(`${l.look.slice(6).trim() || "/"} scrolls sideways at phone width`);
289 }
290 return out;
291 }
src/looks/capture.ts +30 −1
@@ -58,8 +58,20 @@ export interface LookInput {
5858 /** What the page recorded while it loaded; a type the browser lacks is an empty list. */
5959 export interface Recorded {
6060 readonly entries: Entries;
61 /** The page's own size after load; a number the page did not give is absent. */
62 readonly page?: PageSize | undefined;
6163 }
6264
65 /** `document.documentElement.scroll*` and the viewport, in whole pixels. */
66 export interface PageSize {
67 readonly scrollWidth?: number;
68 readonly scrollHeight?: number;
69 readonly innerWidth?: number;
70 readonly innerHeight?: number;
71 }
72
73 const PAGE_FIELDS = ["scrollWidth", "scrollHeight", "innerWidth", "innerHeight"] as const;
74
6375 /**
6476 * What takes the picture: the real browser, or a test's stand-in. One that
6577 * recorded nothing returns empty entries.
@@ -137,6 +149,13 @@ const OBSERVER = `(() => {
137149 watch("longtask", "longtask", (e) => ({ startTime: e.startTime, duration: e.duration }));
138150 })()`;
139151
152 /** Read back after load, in the one evaluation: the entries and the page's size. */
153 const PAGE_READ = `JSON.stringify(window.__forgeVitals ? Object.assign({}, window.__forgeVitals, { page: {
154 scrollWidth: document.documentElement.scrollWidth,
155 scrollHeight: document.documentElement.scrollHeight,
156 innerWidth: window.innerWidth,
157 innerHeight: window.innerHeight } }) : null)`;
158
140159 const finite = (v: unknown): v is number =>
141160 typeof v === "number" && Number.isFinite(v) && v >= 0;
142161
@@ -172,7 +191,17 @@ export function parseRecorded(raw: unknown): Recorded {
172191 }
173192 return out;
174193 };
194 const size: Record<string, number> = {};
195 const given =
196 rec["page"] !== null && typeof rec["page"] === "object"
197 ? (rec["page"] as Record<string, unknown>)
198 : {};
199 for (const f of PAGE_FIELDS) {
200 const v = given[f];
201 if (finite(v) && Number.isInteger(v)) size[f] = v;
202 }
175203 return {
204 ...(Object.keys(size).length > 0 ? { page: size as PageSize } : {}),
176205 entries: {
177206 lcp: list("lcp", ["startTime", "size"], "startTime"),
178207 layoutShift: list("layoutShift", ["startTime", "value", "hadRecentInput"], "value"),
@@ -470,7 +499,7 @@ async function shoot(
470499 const read = await dt.send(
471500 "Runtime.evaluate",
472501 {
473 expression: "JSON.stringify(window.__forgeVitals ?? null)",
502 expression: PAGE_READ,
474503 returnByValue: true,
475504 },
476505 sessionId,
src/looks/service.ts +28 −2
@@ -69,10 +69,32 @@ import { createLog } from "../kernel/log.ts";
6969 import { err, ok, type Result } from "../kernel/result.ts";
7070 import { writeCommitLooks } from "../checks/looks.ts";
7171 import type { LookVitals } from "../checks/summary.ts";
72 import { findChromium, isNoBrowser, takeLook, type Capture } from "./capture.ts";
72 import { findChromium, isNoBrowser, takeLook, type Capture, type PageSize } from "./capture.ts";
7373
7474 const log = createLog("looks");
7575
76 const tenth = (n: number): number => Math.round(n * 10) / 10;
77
78 /**
79 * What the page's size says: whether it scrolls sideways and how many
80 * screens tall it is. Each is absent when its numbers were not given.
81 */
82 export function pageFacts(page: PageSize | undefined): {
83 sideways?: boolean;
84 screens?: number;
85 } {
86 const out: { sideways?: boolean; screens?: number } = {};
87 if (page?.scrollWidth !== undefined && page.innerWidth !== undefined)
88 out.sideways = page.scrollWidth > page.innerWidth;
89 if (
90 page?.scrollHeight !== undefined &&
91 page.innerHeight !== undefined &&
92 page.innerHeight > 0
93 )
94 out.screens = tenth(page.scrollHeight / page.innerHeight);
95 return out;
96 }
97
7698 export interface LooksOptions {
7799 /** The forge's own listener, plain http: where the browser is pointed. */
78100 readonly localUrl: string;
@@ -432,7 +454,11 @@ export function startLooks(app: App, options: LooksOptions): LooksHandle {
432454 // The thumb is the desktop page again, as a stranger: it adds no row.
433455 if (kind !== "thumb" && theme === "light") {
434456 const look = page === "/" ? kind : `${kind} ${page}`;
435 if (shot.ok) vitals.push({ look, entries: shot.value.entries });
457 if (shot.ok) vitals.push({
458 look,
459 entries: shot.value.entries,
460 ...pageFacts(shot.value.page),
461 });
436462 else if (isNoBrowser(shot.error))
437463 vitals.push({ look, skipped: "no browser" });
438464 }
src/web/studio/vitals.ts +3 −2
@@ -4,13 +4,14 @@
44 * look recorded anything.
55 */
66
7 import { vitalsRows, type LookVitals } from "../../checks/summary.ts";
7 import { sidewaysNotices, vitalsRows, type LookVitals } from "../../checks/summary.ts";
88 import { html, type Html } from "../html.ts";
99
1010 export function vitalsTable(looks: readonly LookVitals[]): Html {
1111 const groups = vitalsRows(looks);
1212 if (groups.length === 0) return html``;
13 return html`<div class="table-scroll" tabindex="0" role="region" aria-label="Web vitals per look">
13 const notices = sidewaysNotices(looks);
14 return html`${notices.map((n) => html`<p>${n}</p>`)}<div class="table-scroll" tabindex="0" role="region" aria-label="Web vitals per look">
1415 <table class="table" data-dense>
1516 <thead><tr><th>Look</th><th>Vital</th><th>Value</th><th>Thresholds</th><th>Grade</th></tr></thead>
1617 <tbody>
test/looks.test.ts +44 −2
@@ -31,7 +31,7 @@ import type { Pull } from "../src/core/pulls.ts";
3131 import type { Repo } from "../src/core/repos.ts";
3232 import { createRun, listRuns, type Run } from "../src/core/runs.ts";
3333 import { readLooks } from "../src/checks/looks.ts";
34 import { vitalsRows } from "../src/checks/summary.ts";
34 import { sidewaysNotices, vitalsRows } from "../src/checks/summary.ts";
3535 import { createUser, type User } from "../src/core/users.ts";
3636 import { serve, type Servers } from "../src/http/server.ts";
3737 import { err, ok } from "../src/kernel/result.ts";
@@ -44,7 +44,9 @@ import {
4444 type Capture,
4545 type LookInput,
4646 } from "../src/looks/capture.ts";
47 import { startLooks, type LooksHandle } from "../src/looks/service.ts";
47 import { vitalsLine } from "../src/checks/progress.ts";
48 import { vitalsTable } from "../src/web/studio/vitals.ts";
49 import { pageFacts, startLooks, type LooksHandle } from "../src/looks/service.ts";
4850
4951 quietLogs();
5052
@@ -92,6 +94,10 @@ describe("the look", () => {
9294 writeFileSync(input.out, input.width === 1280 ? DESKTOP_PNG : PNG);
9395 // What the page recorded: a slow paint for the phone, a shift for the desktop.
9496 return ok({
97 page:
98 input.width === 390
99 ? { scrollWidth: 500, scrollHeight: 2000, innerWidth: 390, innerHeight: 800 }
100 : { scrollWidth: 1280, scrollHeight: 800, innerWidth: 1280, innerHeight: 800 },
95101 entries:
96102 input.width === 390
97103 ? { lcp: [{ startTime: 3100, size: 10 }] }
@@ -294,6 +300,10 @@ describe("the look", () => {
294300 expect(recorded).toHaveLength(2);
295301 expect(recorded.map((l) => l.look).sort()).toEqual(["desktop", "phone"]);
296302 const graded = vitalsRows(recorded);
303 // The page's own size is stored beside the vitals.
304 expect(recorded.find((l) => l.look === "phone")).toMatchObject({ sideways: true, screens: 2.5 });
305 expect(recorded.find((l) => l.look === "desktop")).toMatchObject({ sideways: false, screens: 1 });
306 expect(sidewaysNotices(recorded)).toEqual(["/ scrolls sideways at phone width"]);
297307 expect(graded.find((g) => g.look === "phone")!.rows[0]).toMatchObject({
298308 vital: "LCP",
299309 value: "3100 ms",
@@ -562,6 +572,38 @@ describe("the look", () => {
562572 expect(parseRecorded("x").entries.lcp).toEqual([]);
563573 });
564574
575 test("the page's size is kept as whole numbers, a missing or malformed one as absent", () => {
576 const size = { scrollWidth: 500, scrollHeight: 2000, innerWidth: 390, innerHeight: 800 };
577 expect(parseRecorded({ page: size }).page).toEqual(size);
578 expect(parseRecorded({}).page).toBeUndefined();
579 expect(parseRecorded({ page: "x" }).page).toBeUndefined();
580 expect(
581 parseRecorded({ page: { scrollWidth: "500", scrollHeight: -1, innerWidth: 390.5, innerHeight: 800 } }).page,
582 ).toEqual({ innerHeight: 800 });
583 expect(pageFacts({ scrollWidth: 391, innerWidth: 390, scrollHeight: 1000, innerHeight: 800 })).toEqual({
584 sideways: true,
585 screens: 1.3,
586 });
587 expect(pageFacts({ scrollWidth: 390, innerWidth: 390 })).toEqual({ sideways: false });
588 expect(pageFacts(undefined)).toEqual({});
589 });
590
591 test("a sideways phone look is named in one plain line, a page that fits says nothing", () => {
592 const entries = {};
593 const looks = [
594 { look: "phone /preview-admin/sample/held", entries, sideways: true, screens: 3 },
595 { look: "phone /ok", entries, sideways: false, screens: 1 },
596 { look: "desktop /wide", entries, sideways: true },
597 { look: "phone /unknown", entries },
598 ];
599 expect(sidewaysNotices(looks)).toEqual(["/preview-admin/sample/held scrolls sideways at phone width"]);
600 expect(sidewaysNotices(looks.slice(1))).toEqual([]);
601 expect(vitalsLine(looks)).toContain("/preview-admin/sample/held scrolls sideways at phone width");
602 expect(vitalsLine(looks.slice(1))).not.toContain("sideways");
603 expect(vitalsTable(looks).text).toContain("/preview-admin/sample/held scrolls sideways at phone width");
604 expect(vitalsTable(looks.slice(1)).text).not.toContain("sideways");
605 });
606
565607 test("a closed pull's pictures go with its preview", async () => {
566608 const env = `pull-${unpictured.number}`;
567609 expect(looksForEnv(app.db, record.id, env).length).toBeGreaterThan(0);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs