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

studio.test.ts waits for a pull's preview to deploy instead of racing its own 30 s timeout #979

Closed opened this
Closed without merging

scout/forge:scout/896-studio-test-ts-waits-for-a-pull-s-previe → main 1 commit fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
1 file changed +32 −9
test/studio.test.ts +32 −9
@@ -79,6 +79,30 @@ const PNG = Buffer.from(
7979 "base64",
8080 );
8181
82 /** The longest a test waits for a preview to deploy. */
83 const PREVIEW_DEPLOY_WAIT_MS = 45_000;
84 /** Test timeout: the deploy wait plus at least 30 s of headroom. */
85 const PREVIEW_TEST_TIMEOUT_MS = PREVIEW_DEPLOY_WAIT_MS + 45_000;
86
87 /** Waits for a pull's preview to be running; a failure names the state it reached. */
88 async function waitForPreview(
89 runtime: { envStatus(record: any, env: any): { state: string } | undefined },
90 record: unknown,
91 env: string,
92 ): Promise<void> {
93 const deadline = Date.now() + PREVIEW_DEPLOY_WAIT_MS;
94 while (
95 Date.now() < deadline &&
96 runtime.envStatus(record, env)?.state !== "running"
97 )
98 await Bun.sleep(100);
99 const state = runtime.envStatus(record, env)?.state;
100 if (state !== "running")
101 throw new Error(
102 `preview ${env} did not reach "running" within ${PREVIEW_DEPLOY_WAIT_MS} ms; last state: ${state ?? "none"}`,
103 );
104 }
105
82106 /**
83107 * A runtime registered for `app`, never started, answering every app's
84108 * production with `stateOf` (running unless told) — the door shows only
@@ -2622,6 +2646,11 @@ describe("every open pull's preview on the studio page", () => {
26222646 });
26232647 if (!opened.ok) throw new Error(String(opened.error));
26242648 const pull = opened.value;
2649 await waitForPreview(
2650 runtime,
2651 getAppByRepo(app.db, repo.id)!,
2652 `pull-${pull.number}`,
2653 );
26252654
26262655 const page = await (await get("/alice/widget")).text();
26272656 expect(page).toContain("<h2>Previews</h2>");
@@ -2633,7 +2662,7 @@ describe("every open pull's preview on the studio page", () => {
26332662 const after = await (await get("/alice/widget")).text();
26342663 expect(after).not.toContain("<h2>Previews</h2>");
26352664 expect(after).not.toContain(`pull-${pull.number}/open`);
2636 }, 30_000);
2665 }, PREVIEW_TEST_TIMEOUT_MS);
26372666
26382667 test("a change's page names its preview's data as its own copy and gives the moment it was taken; production's card does not", async () => {
26392668 const alice = getUserByName(app.db, "alice")!;
@@ -2655,13 +2684,7 @@ describe("every open pull's preview on the studio page", () => {
26552684 const record = getAppByRepo(app.db, repo.id)!;
26562685 const env = `pull-${pull.number}` as const;
26572686
2658 const deadline = Date.now() + 30_000;
2659 while (
2660 Date.now() < deadline &&
2661 runtime.envStatus(record, env)?.state !== "running"
2662 )
2663 await Bun.sleep(100);
2664 expect(runtime.envStatus(record, env)?.state).toBe("running");
2687 await waitForPreview(runtime, record, env);
26652688
26662689 const note = "its own copy of production's data, taken";
26672690
@@ -2676,7 +2699,7 @@ describe("every open pull's preview on the studio page", () => {
26762699 ).text();
26772700 expect(changePage).toContain("<h2>Preview</h2>");
26782701 expect(changePage).toContain(note);
2679 }, 30_000);
2702 }, PREVIEW_TEST_TIMEOUT_MS);
26802703 });
26812704
26822705 /**

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs