| 4 | const BASE_URL = process.env.TEST_BASE_URL ?? "http://127.0.0.1:7330"; |
| 5 | |
| 6 | const isApiReachable = async (): Promise<boolean> => { |
| 7 | try { |
| 8 | const res = await fetch(`${BASE_URL}/health`, { |
| 9 | signal: AbortSignal.timeout(500), |
| 10 | }); |
| 11 | |
| 12 | if (!res.ok) { |
| 13 | return false; |
| 14 | } |
| 15 | |
| 16 | /* |
| 17 | * Strict content-type check so unrelated processes on the same port |
| 18 | * (Vite, nginx, etc. — common during local dev when the API isn't |
| 19 | * running) don't pass as "reachable" and crash the JSON parser below. |
| 20 | */ |
| 21 | const contentType = res.headers.get("content-type") ?? ""; |
| 22 | |
| 23 | return contentType.includes("application/json"); |
| 24 | } catch { |
| 25 | return false; |
| 26 | } |
| 27 | }; |
| 28 | |
| 29 | test("GET /health returns status ok", async () => { |
| 30 | if (!(await isApiReachable())) { |