| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { waitForThreadShellReady } from "./threadForkNavigation"; |
| 4 | |
| 5 | describe("waitForThreadShellReady", () => { |
| 6 | it("returns true when the forked thread shell arrives before the deadline", async () => { |
| 7 | let elapsedMs = 0; |
| 8 | |
| 9 | const ready = await waitForThreadShellReady({ |
| 10 | read: () => elapsedMs >= 80, |
| 11 | timeoutMs: 120, |
| 12 | pollIntervalMs: 40, |
| 13 | now: () => elapsedMs, |
| 14 | delay: async (durationMs) => { |
| 15 | elapsedMs += durationMs; |
| 16 | }, |
| 17 | }); |
| 18 | |
| 19 | expect(ready).toBe(true); |
| 20 | }); |
| 21 | |
| 22 | it("returns false instead of navigating when the shell never arrives", async () => { |
| 23 | let elapsedMs = 0; |
| 24 | |
| 25 | const ready = await waitForThreadShellReady({ |
| 26 | read: () => false, |
| 27 | timeoutMs: 80, |
| 28 | pollIntervalMs: 40, |
| 29 | now: () => elapsedMs, |
| 30 | delay: async (durationMs) => { |
| 31 | elapsedMs += durationMs; |
| 32 | }, |
| 33 | }); |
| 34 | |
| 35 | expect(ready).toBe(false); |
| 36 | expect(elapsedMs).toBe(80); |
| 37 | }); |
| 38 | }); |