( endpoint: string, child: ChildProcess, output: () => string, )
| 800 | } |
| 801 | |
| 802 | async function waitForHealth( |
| 803 | endpoint: string, |
| 804 | child: ChildProcess, |
| 805 | output: () => string, |
| 806 | ): Promise<void> { |
| 807 | const deadline = Date.now() + 60_000; |
| 808 | let lastError: unknown; |
| 809 | while (Date.now() < deadline) { |
| 810 | if (child.exitCode !== null) { |
| 811 | throw new Error( |
| 812 | `SimDeck isolated service exited with ${child.exitCode}.\n${output()}`, |
| 813 | ); |
| 814 | } |
| 815 | try { |
| 816 | await requestJson(endpoint, "GET", "/api/health"); |
| 817 | return; |
| 818 | } catch (error) { |
| 819 | lastError = error; |
| 820 | await new Promise((resolve) => setTimeout(resolve, 50)); |
| 821 | } |
| 822 | } |
| 823 | throw new Error( |
| 824 | `Timed out waiting for isolated SimDeck service: ${ |
| 825 | lastError instanceof Error ? lastError.message : String(lastError) |
| 826 | }\n${output()}`, |
| 827 | ); |
| 828 | } |
| 829 | |
| 830 | function captureChildOutput(child: ChildProcess): () => string { |
| 831 | const chunks: string[] = []; |
no test coverage detected