* Wait for the dev server to respond on its port. * Polls with 500ms intervals up to the timeout.
(port: number, timeoutMs = 30_000)
| 86 | * Polls with 500ms intervals up to the timeout. |
| 87 | */ |
| 88 | async function waitForServer(port: number, timeoutMs = 30_000): Promise<boolean> { |
| 89 | const start = Date.now(); |
| 90 | while (Date.now() - start < timeoutMs) { |
| 91 | try { |
| 92 | const res = await fetch(`http://localhost:${port}`, { |
| 93 | signal: AbortSignal.timeout(2000), |
| 94 | }); |
| 95 | // Any response (even 500) means the server is up |
| 96 | if (res.status) return true; |
| 97 | } catch { |
| 98 | // Not ready yet |
| 99 | } |
| 100 | await new Promise(r => setTimeout(r, 500)); |
| 101 | } |
| 102 | return false; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Spawn the dev server process and pipe its output. |