GeezerVison is showing github.com — test(web): ban frame and transition waits in browser tests · pingdotgg/t3code@3357dcc
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/ChatMarkdown.browser.test.tsx +5-14Lines changed: 5 additions & 14 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1181,8 +1181,6 @@ describe("ChatMarkdown thread find", () => { | 1181 | 1181 | </div> | 1182 | 1182 | ); | 1183 | 1183 | } | 1184 | | - const frame = () => | 1185 | | - act(() => new Promise<void>((resolve) => requestAnimationFrame(() => resolve()))); | 1186 | 1184 | // Highlights live in a document-wide registry the rendered tree does not own. | 1187 | 1185 | const clearHighlights = () => ({ [Symbol.dispose]: () => CSS.highlights.clear() }); | 1188 | 1186 | const activeHighlights = () => | @@ -1219,17 +1217,14 @@ describe("ChatMarkdown thread find", () => { | 1219 | 1217 |
| 1220 | 1218 | expect(container.textContent).not.toContain("nothing here"); | 1221 | 1219 | await show("needle", 0); | 1222 | | - await frame(); | | 1220 | + await vi.waitFor(() => expect(activeHighlights()).toEqual(["needle"])); | 1223 | 1221 | expect(openStates()).toEqual(["false", "false", "false"]); | 1224 | 1222 | expect(container.textContent).toContain("nothing here"); | 1225 | | - expect(activeHighlights()).toEqual(["needle"]); | 1226 | 1223 | expect(CSS.highlights.get("t3-thread-find")?.size ?? 0).toBe(0); | 1227 | 1224 |
| 1228 | 1225 | await show("needle", 1); | 1229 | | - await frame(); | 1230 | | - await frame(); | 1231 | | - expect(openStates()).toEqual(["false", "true", "true"]); | 1232 | | - expect(CSS.highlights.get("t3-thread-find-active")?.size).toBe(1); | | 1226 | + await vi.waitFor(() => expect(openStates()).toEqual(["false", "true", "true"])); | | 1227 | + await vi.waitFor(() => expect(CSS.highlights.get("t3-thread-find-active")?.size).toBe(1)); | 1233 | 1228 | }); | 1234 | 1229 |
| 1235 | 1230 | it("keeps Mermaid diagrams rendered until find selects a match in their source", async () => { | @@ -1245,12 +1240,9 @@ describe("ChatMarkdown thread find", () => { | 1245 | 1240 | const diagrams = () => container.querySelectorAll('svg[aria-label="Diagram"]').length; | 1246 | 1241 |
| 1247 | 1242 | await using screen = await render(probe("Needle"), { container }); | 1248 | | - await frame(); | 1249 | | - expect(diagrams()).toBe(2); | | 1243 | + await vi.waitFor(() => expect(diagrams()).toBe(2)); | 1250 | 1244 | await screen.rerender(probe("Alpha")); | 1251 | | - await frame(); | 1252 | | - await frame(); | 1253 | | - expect(diagrams()).toBe(1); | | 1245 | + await vi.waitFor(() => expect(diagrams()).toBe(1)); | 1254 | 1246 | await vi.waitFor(() => expect(activeHighlights()).toEqual(["Alpha"])); | 1255 | 1247 | }); | 1256 | 1248 |
| @@ -1305,7 +1297,6 @@ describe("ChatMarkdown thread find", () => { | 1305 | 1297 | </FindProbe>, | 1306 | 1298 | { container }, | 1307 | 1299 | ); | 1308 | | - await frame(); | 1309 | 1300 | // Lazy blocks such as Mermaid can swap their source text after the first frame, | 1310 | 1301 | // emptying a range for a moment, so wait for the highlights to settle. | 1311 | 1302 | await vi.waitFor(() => { | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/DiffPanel.browser.test.tsx -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -164,7 +164,6 @@ async function scrollToStart(container: HTMLElement) { | 164 | 164 | await act(async () => { | 165 | 165 | viewport(container).scrollTop = 0; | 166 | 166 | viewport(container).dispatchEvent(new Event("scroll")); | 167 | | - await new Promise(requestAnimationFrame); | 168 | 167 | }); | 169 | 168 | } | 170 | 169 | async function selectTreeFile(container: HTMLElement, path: string) { | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/ThreadStatusIndicators.subscriptions.browser.test.tsx +8-5Lines changed: 8 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -114,7 +114,6 @@ it("leases only visible palette results while retaining observed and cached PR b | 114 | 114 | const scrollTo = async (top: number) => { | 115 | 115 | await act(async () => { | 116 | 116 | viewport().scrollTop = top; | 117 | | - await new Promise((resolve) => requestAnimationFrame(() => setTimeout(resolve, 50))); | 118 | 117 | }); | 119 | 118 | }; | 120 | 119 | const badgeCount = () => | @@ -158,15 +157,19 @@ it("leases only visible palette results while retaining observed and cached PR b | 158 | 157 |
| 159 | 158 | // Band [1000, 1340]: rows 0..7. | 160 | 159 | await scrollTo(SPACER + 160); | 161 | | - expect(state.queries).toHaveLength(8); | | 160 | + await vi.waitFor(() => { | | 161 | + expect(state.queries).toHaveLength(8); | | 162 | + expect(badgeCount()).toBe(9); | | 163 | + }); | 162 | 164 | expect(state.queries.filter((key) => key.startsWith("vcs:"))).toHaveLength(4); | 163 | 165 | expect(state.queries.filter((key) => key.startsWith("pr:"))).toHaveLength(4); | 164 | | - expect(badgeCount()).toBe(9); | 165 | 166 |
| 166 | 167 | // Band [1370, 1710]: rows 8..15. | 167 | 168 | await scrollTo(SPACER + 8 * ROW_HEIGHT + 10 + 160); | 168 | | - expect(state.queries).toHaveLength(16); | 169 | | - expect(badgeCount()).toBe(17); | | 169 | + await vi.waitFor(() => { | | 170 | + expect(state.queries).toHaveLength(16); | | 171 | + expect(badgeCount()).toBe(17); | | 172 | + }); | 170 | 173 | }); | 171 | 174 |
| 172 | 175 | it("keeps a long PR hover list in the viewport and lets the last row be selected", async () => { | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/chat/ChangedFilesTree.browser.test.tsx +13-17Lines changed: 13 additions & 17 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -23,12 +23,14 @@ function buttonWithText(container: HTMLElement, label: string) { | 23 | 23 | return button!; | 24 | 24 | } | 25 | 25 |
| 26 | | -async function scrollTo(element: HTMLElement, top: number) { | | 26 | +async function scrollTo(element: HTMLElement, top: number, revealedText?: string) { | 27 | 27 | await act(async () => { | 28 | 28 | element.scrollTop = top; | 29 | 29 | element.dispatchEvent(new Event("scroll")); | 30 | | - await new Promise(requestAnimationFrame); | 31 | 30 | }); | | 31 | + if (revealedText !== undefined) { | | 32 | + await vi.waitFor(() => expect(text(element)).toContain(revealedText)); | | 33 | + } | 32 | 34 | } | 33 | 35 |
| 34 | 36 | describe("ChangedFilesCard", () => { | @@ -145,8 +147,7 @@ describe("ChangedFilesTree", () => { | 145 | 147 | expect(text(container)).not.toContain("folder-0999"); | 146 | 148 |
| 147 | 149 | const viewport = container.firstElementChild as HTMLElement; | 148 | | - await scrollTo(viewport, viewport.scrollHeight); | 149 | | - expect(text(container)).toContain("folder-0999"); | | 150 | + await scrollTo(viewport, viewport.scrollHeight, "folder-0999"); | 150 | 151 | expect(container.querySelectorAll("button").length).toBeLessThan(60); | 151 | 152 | await act(async () => buttonWithText(container, "folder-0999").click()); | 152 | 153 | expect(text(container)).toContain("index.ts"); | @@ -188,13 +189,11 @@ describe("ChangedFilesTree", () => { | 188 | 189 | expect(text(container)).toContain("file-00000.ts"); | 189 | 190 | expect(text(container)).not.toContain("file-08000.ts"); | 190 | 191 |
| 191 | | - await scrollTo(viewport, 420 + 8_001 * 28); | 192 | | - expect(text(container)).toContain("file-08000.ts"); | | 192 | + await scrollTo(viewport, 420 + 8_001 * 28, "file-08000.ts"); | 193 | 193 | expect(text(container)).not.toContain("file-00000.ts"); | 194 | 194 | expect(container.querySelectorAll("button").length).toBeLessThan(60); | 195 | 195 |
| 196 | | - await scrollTo(viewport, viewport.scrollHeight); | 197 | | - expect(text(container)).toContain("file-16184.ts"); | | 196 | + await scrollTo(viewport, viewport.scrollHeight, "file-16184.ts"); | 198 | 197 | await act(async () => buttonWithText(container, "file-16184.ts").click()); | 199 | 198 | expect(onOpenTurnDiff).toHaveBeenCalledWith(RunId.make("run-1"), "src/file-16184.ts"); | 200 | 199 | await act(async () => | @@ -235,17 +234,15 @@ describe("ChangedFilesTree", () => { | 235 | 234 | ); | 236 | 235 | const { container } = screen; | 237 | 236 | const viewport = container.firstElementChild as HTMLElement; | 238 | | - await scrollTo(viewport, 420); | | 237 | + await scrollTo(viewport, 420, "src"); | 239 | 238 | await act(async () => buttonWithText(container, "src").click()); | 240 | 239 | expect(container.querySelectorAll("button").length).toBeLessThan(60); | 241 | 240 |
| 242 | | - await scrollTo(viewport, 420 + 8_001 * 28); | 243 | | - expect(text(container)).toContain("file-08000.ts"); | | 241 | + await scrollTo(viewport, 420 + 8_001 * 28, "file-08000.ts"); | 244 | 242 | expect(container.querySelectorAll("button").length).toBeLessThan(60); | 245 | 243 |
| 246 | | - await scrollTo(viewport, viewport.scrollHeight); | 247 | | - expect(text(container)).toContain("file-16184.ts"); | 248 | | - await scrollTo(viewport, 420); | | 244 | + await scrollTo(viewport, viewport.scrollHeight, "file-16184.ts"); | | 245 | + await scrollTo(viewport, 420, "src"); | 249 | 246 | await act(async () => buttonWithText(container, "src").click()); | 250 | 247 | expect(text(container)).not.toContain("file-00000.ts"); | 251 | 248 | expect(container.querySelectorAll("button").length).toBe(1); | @@ -267,8 +264,7 @@ describe("ChangedFilesTree", () => { | 267 | 264 | const viewport = container.firstElementChild as HTMLElement; | 268 | 265 | const focusedFile = buttonWithText(container, "file-00000.ts"); | 269 | 266 | await act(async () => focusedFile.focus()); | 270 | | - await scrollTo(viewport, 8_001 * 28); | 271 | | - expect(text(container)).toContain("file-08000.ts"); | | 267 | + await scrollTo(viewport, 8_001 * 28, "file-08000.ts"); | 272 | 268 | expect(document.activeElement).toBe(focusedFile); | 273 | 269 | expect(container.querySelectorAll("button").length).toBeLessThan(60); | 274 | 270 |
| @@ -294,7 +290,7 @@ describe("ChangedFilesTree", () => { | 294 | 290 | await using screen = await render(content(140, 0)); | 295 | 291 | const { container } = screen; | 296 | 292 | const viewport = container.firstElementChild as HTMLElement; | 297 | | - await scrollTo(viewport, 8_001 * 28); | | 293 | + await scrollTo(viewport, 8_001 * 28, "file-08000.ts"); | 298 | 294 | const beforeResize = container.querySelectorAll("button").length; | 299 | 295 | await screen.rerender(content(560, 560)); | 300 | 296 | await expect | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/chat/ComposerBannerStack.browser.test.tsx +6-14Lines changed: 6 additions & 14 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import "../../index.css"; | 2 | 2 |
| 3 | | -import { expect, it } from "vite-plus/test"; | | 3 | +import { expect, it, vi } from "vite-plus/test"; | 4 | 4 | import { page, userEvent } from "vite-plus/test/browser"; | 5 | 5 |
| 6 | 6 | import { act, render } from "../../../test/render"; | @@ -12,9 +12,6 @@ function sized(width: number) { | 12 | 12 | return container; | 13 | 13 | } | 14 | 14 |
| 15 | | -const nextFrame = () => | 16 | | - act(() => new Promise<void>((resolve) => requestAnimationFrame(() => setTimeout(resolve, 0)))); | 17 | | - | 18 | 15 | const usage = (description: string) => ( | 19 | 16 | <ComposerBannerStack | 20 | 17 | items={[{ id: "usage", variant: "info", icon: null, title: "Usage limits", description }]} | @@ -25,25 +22,20 @@ it("only offers notice details when the description cannot fit", async () => { | 25 | 22 | await using screen = await render(usage("OpenCode"), { container: sized(700) }); | 26 | 23 | const { container } = screen; | 27 | 24 | const hasDetails = () => container.querySelector('[aria-label="Show notice details"]') !== null; | 28 | | - await nextFrame(); | 29 | | - expect(hasDetails()).toBe(false); | | 25 | + await vi.waitFor(() => expect(hasDetails()).toBe(false)); | 30 | 26 |
| 31 | 27 | await screen.rerender(usage("OpenCode ".repeat(40))); | 32 | | - await nextFrame(); | 33 | | - expect(hasDetails()).toBe(true); | | 28 | + await vi.waitFor(() => expect(hasDetails()).toBe(true)); | 34 | 29 |
| 35 | 30 | container.style.width = "4000px"; | 36 | | - await nextFrame(); | 37 | | - expect(hasDetails()).toBe(false); | | 31 | + await vi.waitFor(() => expect(hasDetails()).toBe(false)); | 38 | 32 |
| 39 | 33 | await screen.rerender(usage("OpenCode")); | 40 | | - await nextFrame(); | 41 | | - expect(hasDetails()).toBe(false); | | 34 | + await vi.waitFor(() => expect(hasDetails()).toBe(false)); | 42 | 35 |
| 43 | 36 | // A narrow composer hides the description entirely, so details are the only way to read it. | 44 | 37 | container.style.width = "300px"; | 45 | | - await nextFrame(); | 46 | | - expect(hasDetails()).toBe(true); | | 38 | + await vi.waitFor(() => expect(hasDetails()).toBe(true)); | 47 | 39 | }); | 48 | 40 |
| 49 | 41 | it("keeps only the usage limit attached while an active goal waits in the collapsible stack", async () => { | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/chat/MessagesTimeline.browser.test.tsx +5-2Lines changed: 5 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1590,6 +1590,9 @@ describe("MessagesTimeline scroll position", () => { | 1590 | 1590 | await userEvent.wheel(viewport, { delta: { y: -2000 } }); | 1591 | 1591 | await click(toggle()); | 1592 | 1592 | await click(toggle()); | | 1593 | + // The restore decision runs in the timeline's second disclosure-settle frame and leaves no | | 1594 | + // DOM trace when it declines, so this negative check has to outlast those two frames. | | 1595 | + // oxlint-disable-next-line t3code/no-frame-waits-in-browser-tests -- negative check needs the settle frames to have run | 1593 | 1596 | await new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve))); | 1594 | 1597 | expect(composerState()).toBe("collapsed"); | 1595 | 1598 | }); | @@ -1614,14 +1617,14 @@ describe("MessagesTimeline send anchor", () => { | 1614 | 1617 |
| 1615 | 1618 | it("does not anchor a follow-up user message that is not the newest turn", async () => { | 1616 | 1619 | const onAnchorReady = vi.fn(); | 1617 | | - await using _screen = await renderTimeline( | | 1620 | + await using screen = await renderTimeline( | 1618 | 1621 | [message("First prompt."), message("Newest prompt.", {}, "message-2")], | 1619 | 1622 | { | 1620 | 1623 | anchorMessageId: MessageId.make("message-2"), | 1621 | 1624 | onAnchorReady, | 1622 | 1625 | }, | 1623 | 1626 | ); | 1624 | | - await new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve))); | | 1627 | + await vi.waitFor(() => expect(screen.container.textContent).toContain("Newest prompt.")); | 1625 | 1628 | expect(onAnchorReady).not.toHaveBeenCalled(); | 1626 | 1629 | }); | 1627 | 1630 | }); | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/chat/ThreadDetailsPrRows.browser.test.tsx +24-5Lines changed: 24 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -240,6 +240,21 @@ it("lets only watched pull requests stop their watch", async () => { | 240 | 240 | }); | 241 | 241 | }); | 242 | 242 |
| | 243 | +function nextResize(element: Element): Promise<void> { | | 244 | + return new Promise((resolve) => { | | 245 | + let initialHeight: number | undefined; | | 246 | + const observer = new ResizeObserver(([entry]) => { | | 247 | + const height = entry!.contentRect.height; | | 248 | + if (initialHeight === undefined) initialHeight = height; | | 249 | + else if (height !== initialHeight) { | | 250 | + observer.disconnect(); | | 251 | + resolve(); | | 252 | + } | | 253 | + }); | | 254 | + observer.observe(element); | | 255 | + }); | | 256 | +} | | 257 | + | 243 | 258 | it("keeps workspace controls after expanding and collapsing 70 linked pull requests", async () => { | 244 | 259 | await using test = await setup(); | 245 | 260 | const { screen, container } = test; | @@ -284,15 +299,19 @@ it("keeps workspace controls after expanding and collapsing 70 linked pull reque | 284 | 299 | await expect.element(runContext).toBeVisible(); | 285 | 300 | await expect.element(editor).toBeVisible(); | 286 | 301 |
| 287 | | - await userEvent.click(page.getByRole("button", { name: "Show 69 more" })); | | 302 | + const showMore = page.getByRole("button", { name: "Show 69 more" }); | | 303 | + const content = showMore | | 304 | + .element() | | 305 | + .closest('[data-slot="scroll-area-viewport"]')!.firstElementChild!; | | 306 | + // The card measures this element through the shared ResizeObserver, created before this one, | | 307 | + // so this observer seeing the expanded size means the card has measured it too. | | 308 | + const expandedSizeDelivered = nextResize(content); | | 309 | + await userEvent.click(showMore); | 288 | 310 | await expect.element(page.getByRole("button", { name: "Show less" })).toBeInTheDocument(); | 289 | 311 | const extraRows = () => | 290 | 312 | container.querySelectorAll('[aria-label^="https://github.com/pingdotgg/t3code/pull/"]'); | 291 | 313 | expect(extraRows()).toHaveLength(69); | 292 | | - // Let native ResizeObserver deliver the expanded content size before collapsing it. | 293 | | - await act(async () => { | 294 | | - await new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve))); | 295 | | - }); | | 314 | + await act(() => expandedSizeDelivered); | 296 | 315 | await userEvent.click(page.getByRole("button", { name: "Show less" })); | 297 | 316 | await expect.element(page.getByRole("button", { name: "Show 69 more" })).toBeVisible(); | 298 | 317 | expect(extraRows()).toHaveLength(0); | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/chat/WorkflowOpeningBlock.browser.test.tsx +8-8Lines changed: 8 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -79,18 +79,14 @@ async function renderOpening(script: string, query = "") { | 79 | 79 | <Find container={container} query={query} /> | 80 | 80 | </AppAtomRegistryProvider> | 81 | 81 | ); | 82 | | - const nextFrame = () => | 83 | | - act(() => new Promise<void>((resolve) => requestAnimationFrame(() => resolve()))); | 84 | 82 | await using stack = new AsyncDisposableStack(); | 85 | 83 | stack.defer(() => CSS.highlights.clear()); | 86 | 84 | const screen = stack.use(await render(block(script, query), { container })); | 87 | | - await nextFrame(); | 88 | 85 | const environment = stack.move(); | 89 | 86 | return { | 90 | 87 | container, | 91 | 88 | rerender: async (script: string, query: string) => { | 92 | 89 | await screen.rerender(block(script, query)); | 93 | | - await nextFrame(); | 94 | 90 | }, | 95 | 91 | [Symbol.asyncDispose]: () => environment.disposeAsync(), | 96 | 92 | }; | @@ -115,7 +111,9 @@ it("shows a short script as highlighted code with nothing to open", async () => | 115 | 111 |
| 116 | 112 | it("folds a long script until it is opened", async () => { | 117 | 113 | await using screen = await renderOpening(LONG_SCRIPT); | 118 | | - expect(foldToggle(screen.container)?.getAttribute("aria-expanded")).toBe("false"); | | 114 | + await vi.waitFor(() => | | 115 | + expect(foldToggle(screen.container)?.getAttribute("aria-expanded")).toBe("false"), | | 116 | + ); | 119 | 117 | expect(screen.container.querySelector("[data-thread-find-fold]")).not.toBeNull(); | 120 | 118 | await act(() => foldToggle(screen.container)?.click()); | 121 | 119 | expect(foldToggle(screen.container)?.getAttribute("aria-expanded")).toBe("true"); | @@ -124,10 +122,12 @@ it("folds a long script until it is opened", async () => { | 124 | 122 |
| 125 | 123 | it("finds the workflow's name and opens a folded script on a match below the fold", async () => { | 126 | 124 | await using screen = await renderOpening(LONG_SCRIPT, "repo-check"); | 127 | | - expect(CSS.highlights.get("t3-thread-find-active")?.size).toBe(1); | | 125 | + await vi.waitFor(() => expect(CSS.highlights.get("t3-thread-find-active")?.size).toBe(1)); | 128 | 126 | expect(foldToggle(screen.container)?.getAttribute("aria-expanded")).toBe("false"); | 129 | 127 |
| 130 | 128 | await screen.rerender(LONG_SCRIPT, "TAILONLY"); | 131 | | - expect(CSS.highlights.get("t3-thread-find-active")?.size).toBe(1); | 132 | | - expect(foldToggle(screen.container)?.getAttribute("aria-expanded")).toBe("true"); | | 129 | + await vi.waitFor(() => | | 130 | + expect(foldToggle(screen.container)?.getAttribute("aria-expanded")).toBe("true"), | | 131 | + ); | | 132 | + await vi.waitFor(() => expect(CSS.highlights.get("t3-thread-find-active")?.size).toBe(1)); | 133 | 133 | }); |
|