@@ -51,6 +51,7 @@ import { boundedZip } from "@t3tools/client-runtime/zip/bounded-zip"; |
51 | 51 | import BinaryViewer from "./BinaryViewer"; |
52 | 52 | import { decodeImagePreview } from "./decodeImagePreview"; |
53 | 53 | import type { BinaryWorkerResult } from "./binaryPreviewProtocol"; |
| 54 | +import type { TextPreviewResult } from "./largeTextProtocol"; |
54 | 55 |
|
55 | 56 | // Real worker imports and WASM initialization can exceed waitFor's default second |
56 | 57 | // when the full browser project runs concurrently on CI. |
@@ -462,12 +463,20 @@ describe("large text preview recovery", () => { |
462 | 463 | const original = URL.createObjectURL(new Blob(["original\n".repeat(1000)])); |
463 | 464 | const changed = URL.createObjectURL(new Blob(["changed\n".repeat(1000)])); |
464 | 465 | const workers: Worker[] = []; |
| 466 | + const indexed: Promise<void>[] = []; |
465 | 467 | using _worker = stubGlobal( |
466 | 468 | "Worker", |
467 | 469 | class extends Worker { |
468 | 470 | constructor(...args: ConstructorParameters<typeof Worker>) { |
469 | 471 | super(...args); |
470 | 472 | workers.push(this); |
| 473 | + indexed.push( |
| 474 | + new Promise((resolve) => |
| 475 | + this.addEventListener("message", (event: MessageEvent<TextPreviewResult>) => { |
| 476 | + if (event.data.type === "meta" && event.data.complete) resolve(); |
| 477 | + }), |
| 478 | + ), |
| 479 | + ); |
471 | 480 | } |
472 | 481 | }, |
473 | 482 | ); |
@@ -499,6 +508,8 @@ describe("large text preview recovery", () => { |
499 | 508 | await using screen = await render(preview("first")); |
500 | 509 | await vi.waitFor(() => expect(workers).toHaveLength(1)); |
501 | 510 | await vi.waitFor(() => expect(screen.container.textContent).toContain("original")); |
| 511 | + // A cold worker can take longer than waitFor allows to load and index on CI. |
| 512 | + await indexed[0]; |
502 | 513 | await vi.waitFor(() => expect(screen.container.textContent).toContain("1,000 lines")); |
503 | 514 | const viewport = screen.container.querySelector<HTMLElement>('[tabindex="0"]')!; |
504 | 515 | await act(() => |
@@ -2273,6 +2284,8 @@ it("loads a font attachment through the lazy preview", async () => { |
2273 | 2284 | const { default: fontUrl } = |
2274 | 2285 | await import("../../../node_modules/@betteroffice/fonts/assets/Carlito-Regular.ttf?url"); |
2275 | 2286 | const file = await (await fetch(fontUrl)).blob(); |
| 2287 | + // Both lazy chunks can take longer than waitFor allows to load cold on CI. |
| 2288 | + await Promise.all([import("./FontFilePreview"), import("./FontViewer")]); |
2276 | 2289 | await using screen = await render( |
2277 | 2290 | <AttachmentFilePreview |
2278 | 2291 | name="Carlito.ttf" |
|