Public: anyone can read this; the crew can change it.
test/web-apps.test.ts: the run page case reads the run's state and the page in an order that cannot disagree #1021
scout/forge:scout/967-test-web-apps-test-ts-the-run-page-case → main 1 commit fork
1 file
changed +17
−4
test/web-apps.test.ts +17 −4
| @@ -351,7 +351,21 @@ describe("apps, runs and the crew on the web", () => { | ||
| 351 | 351 | "Nothing open.", |
| 352 | 352 | ); |
| 353 | 353 | |
| 354 | const page = await bodyOf(alice, `/alice/hello/runs/${run!.id}`); | |
| 354 | // The deploy may finish while the page renders, so read the state before | |
| 355 | // and after; a render is judged only when both reads agree. A settled run | |
| 356 | // never goes back, so a second render at most once settles the question. | |
| 357 | const isGoing = () => { | |
| 358 | const s = listRuns(app.db, hello.id).find((r) => r.id === run!.id)!.state; | |
| 359 | return s === "queued" || s === "running"; | |
| 360 | }; | |
| 361 | let before = isGoing(); | |
| 362 | let page = await bodyOf(alice, `/alice/hello/runs/${run!.id}`); | |
| 363 | let going = isGoing(); | |
| 364 | while (before !== going) { | |
| 365 | before = going; | |
| 366 | page = await bodyOf(alice, `/alice/hello/runs/${run!.id}`); | |
| 367 | going = isGoing(); | |
| 368 | } | |
| 355 | 369 | expect(page).toContain("<h1>Deploy production</h1>"); |
| 356 | 370 | expect(page).toContain('id="run-log"'); |
| 357 | 371 | expect(page).toContain('id="run-word"'); |
| @@ -360,10 +374,9 @@ describe("apps, runs and the crew on the web", () => { | ||
| 360 | 374 | expect(page).toContain('class="ln ln-forge"'); |
| 361 | 375 | expect(page).toContain('id="run-elapsed"'); |
| 362 | 376 | // The stream and the no-script refresh exist only while it is going. |
| 363 | const fresh = listRuns(app.db, hello.id).find((r) => r.id === run!.id)!; | |
| 364 | const going = fresh.state === "queued" || fresh.state === "running"; | |
| 365 | 377 | expect(page.includes("data-stream=")).toBe(going); |
| 366 | expect(page.includes('http-equiv="refresh"')).toBe(going); | |
| 378 | // Match the tag itself: the page's inline script names it too. | |
| 379 | expect(/<meta\s+http-equiv="refresh"/.test(page)).toBe(going); | |
| 367 | 380 | |
| 368 | 381 | const door = await web(alice, `/runs/${run!.id}`); |
| 369 | 382 | expect(door.status).toBe(303); |
new above
offline