| 407 | } |
| 408 | |
| 409 | async function waitForExit(child, timeoutMs = 2_000) { |
| 410 | let stderr = ""; |
| 411 | child.stderr.setEncoding("utf8"); |
| 412 | child.stderr.on("data", (chunk) => { |
| 413 | stderr += chunk; |
| 414 | }); |
| 415 | |
| 416 | return new Promise((resolve, reject) => { |
| 417 | const timeout = setTimeout(() => { |
| 418 | child.kill("SIGKILL"); |
| 419 | reject(new Error("timed out waiting for computerd to exit")); |
| 420 | }, timeoutMs); |
| 421 | |
| 422 | child.once("exit", (code, signal) => { |
| 423 | clearTimeout(timeout); |
| 424 | resolve({ code, signal, stderr }); |
| 425 | }); |
| 426 | }); |
| 427 | } |
| 428 | |
| 429 | async function waitForHTTPOK(url, child, output, timeoutMs = 5_000) { |
| 430 | const started = Date.now(); |