Skip to content
TypeScript

test(web): attachment preview tests wait long enough for cold workers and fonts (#26342)

Theo Brownecadbdafc063e
diff --git a/apps/web/src/components/files/AttachmentFilePreview.browser.test.tsx b/apps/web/src/components/files/AttachmentFilePreview.browser.test.tsx
index 5fd8b055052..9879edfeedb 100644
--- a/apps/web/src/components/files/AttachmentFilePreview.browser.test.tsx
+++ b/apps/web/src/components/files/AttachmentFilePreview.browser.test.tsx
@@ -2154,8 +2154,10 @@ it("refreshes authorization and retries a failed streamed attachment", async ()
asset={{ environmentId: EnvironmentId.make("test"), attachmentId: "retry" }}
/>,
);
- await vi.waitFor(() =>
- expect(screen.container.textContent).toContain("This file contains binary data."),
+ // A cold large-text worker can take longer than waitFor's default to boot on CI.
+ await vi.waitFor(
+ () => expect(screen.container.textContent).toContain("This file contains binary data."),
+ { timeout: 10_000 },
);
await act(() =>
screen.container.querySelector<HTMLButtonElement>('[role="alert"] button')!.click(),
@@ -2217,7 +2219,10 @@ it("copies every indexed line rather than the mounted preview rows", async () =>
<LargeTextViewer name="whole.txt" text={text} delimiter={null} copyContents={copyContents} />,
);
await vi.waitFor(() => expect(screen.container.textContent).toContain("line-0"));
- await vi.waitFor(async () => expect(await copyContents.current!()).toBe(text));
+ // Copy rejects until the worker finishes indexing, which a cold worker can delay past waitFor's default on CI.
+ await vi.waitFor(async () => expect(await copyContents.current!()).toBe(text), {
+ timeout: 10_000,
+ });
const first = copyContents.current!();
await expect(copyContents.current!()).rejects.toThrow("Another copy is in progress.");
expect(await first).toBe(text);
@@ -2284,8 +2289,6 @@ it("loads a font attachment through the lazy preview", async () => {
const { default: fontUrl } =
await import("../../../node_modules/@betteroffice/fonts/assets/Carlito-Regular.ttf?url");
const file = await (await fetch(fontUrl)).blob();
- // Both lazy chunks can take longer than waitFor allows to load cold on CI.
- await Promise.all([import("./FontFilePreview"), import("./FontViewer")]);
await using screen = await render(
<AttachmentFilePreview
name="Carlito.ttf"
@@ -2294,12 +2297,16 @@ it("loads a font attachment through the lazy preview", async () => {
file={file}
/>,
);
- await vi.waitFor(() => {
- const frame = screen.container.querySelector("iframe");
- expect(frame?.title).toBe("Carlito.ttf");
- expect(frame?.srcdoc).toContain("@font-face");
- expect(frame?.srcdoc).toContain("The quick brown fox");
- });
+ // Two cold lazy chunks plus decoding a 600 KB font can take longer than waitFor's default on CI.
+ await vi.waitFor(
+ () => {
+ const frame = screen.container.querySelector("iframe");
+ expect(frame?.title).toBe("Carlito.ttf");
+ expect(frame?.srcdoc).toContain("@font-face");
+ expect(frame?.srcdoc).toContain("The quick brown fox");
+ },
+ { timeout: 10_000 },
+ );
expect(screen.container.querySelector('[role="alert"]')).toBeNull();
});