Skip to content

Commit 74401c4

Browse files
committed
test(org): report where each route's time goes
contentReadyMs starts after the document's load and says nothing about why, so a route now also reports its load and its slowest reads.
1 parent 649292a commit 74401c4

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

‎apps/sim/scripts/org-redesign-e2e/checks/walk.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ function routesFor(persona: Persona): { name: string; path: string }[] {
7070
return shared
7171
}
7272

73+
/** Enough to name what a slow route was waiting on. */
74+
const SLOWEST_READS = 5
7375
/** How far a probe grows the viewport to see which panes follow it. */
7476
const PANE_PROBE_PX = 200
7577
/** Home's composer types its suggestion out, then holds it this long before deleting it. */
@@ -132,7 +134,10 @@ async function walkOne(persona: Persona, viewport: Viewport, theme: Theme) {
132134
const failures: string[] = []
133135
if (persona === CONNECTED) await stubConnectedHome(page)
134136
for (const route of routesFor(persona)) {
137+
session.reads.length = 0
138+
const navigated = performance.now()
135139
const response = await page.goto(orgUrl(`/${route.path}`), { timeout: 60_000 })
140+
const documentMs = Math.round(performance.now() - navigated)
136141
const contentReadyMs = await session.contentReady().catch((error) => {
137142
failures.push(`${route.name}: ${getErrorMessage(error)}`)
138143
return null
@@ -174,6 +179,9 @@ async function walkOne(persona: Persona, viewport: Viewport, theme: Theme) {
174179
screenshot,
175180
platformSurfaces: facts.surfaces,
176181
contentReadyMs,
182+
documentMs,
183+
slowestReads: [...session.reads].sort((a, b) => b.ms - a.ms).slice(0, SLOWEST_READS),
184+
readCount: session.reads.length,
177185
})
178186
if ((response?.status() ?? 500) >= 400)
179187
failures.push(`${route.name} status ${response?.status()}`)

‎apps/sim/scripts/org-redesign-e2e/harness.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ interface Problem {
7878
detail: string
7979
}
8080

81+
interface PageRead {
82+
path: string
83+
ms: number
84+
}
85+
8186
interface FirstPaint {
8287
persona: string
8388
page: string
@@ -109,6 +114,11 @@ export const routes: {
109114
platformSurfaces: number
110115
/** From the document's load to no read or skeleton left, or null if it never got there. */
111116
contentReadyMs: number | null
117+
/** The document's own load, which `contentReadyMs` starts after. */
118+
documentMs: number
119+
/** Where the route's time went: its slowest reads, and how many it sent. */
120+
slowestReads: PageRead[]
121+
readCount: number
112122
}[] = []
113123
export const firstPaints: FirstPaint[] = []
114124
const unexpected: Problem[] = []
@@ -260,6 +270,9 @@ class Session {
260270
/** The document a navigation is loading, until it replaces the page. */
261271
private loadingDocument: Request | null = null
262272
readonly requests: { method: string; path: string; type: string }[] = []
273+
/** The page's own reads and how long each took, from the last navigation a walk started. */
274+
readonly reads: PageRead[] = []
275+
private readonly readStarted = new Map<Request, number>()
263276

264277
constructor(
265278
readonly context: BrowserContext,
@@ -287,6 +300,7 @@ class Session {
287300
if (isPageRead(request)) {
288301
this.inflight.add(request)
289302
this.lastActivity = Date.now()
303+
this.readStarted.set(request, Date.now())
290304
}
291305
if (isSameOrigin(request.url()))
292306
this.requests.push({
@@ -305,6 +319,13 @@ class Session {
305319
})
306320
const settled = (request: Request) => {
307321
if (this.inflight.delete(request)) this.lastActivity = Date.now()
322+
const started = this.readStarted.get(request)
323+
if (started === undefined) return
324+
this.readStarted.delete(request)
325+
this.reads.push({
326+
path: `${request.method()} ${pathOf(request.url())}`,
327+
ms: Date.now() - started,
328+
})
308329
}
309330
page.on('requestfinished', settled)
310331
page.on('requestfailed', (request) => {

0 commit comments

Comments
 (0)