(getStdout: () => string, timeoutMs = 90_000)
| 116 | } |
| 117 | |
| 118 | function waitForDevServerURL(getStdout: () => string, timeoutMs = 90_000) { |
| 119 | const started = Date.now() |
| 120 | |
| 121 | return new Promise<string>((resolvePromise, rejectPromise) => { |
| 122 | const attempt = () => { |
| 123 | const stdout = stripAnsi(getStdout()) |
| 124 | const match = stdout.match(/Local:\s+(https?:\/\/[^\s]+)/) |
| 125 | if (match?.[1]) { |
| 126 | resolvePromise(match[1].replace(/\/$/, '')) |
| 127 | return |
| 128 | } |
| 129 | |
| 130 | if (Date.now() - started > timeoutMs) { |
| 131 | rejectPromise(new Error('Timed out waiting for dev server URL in output')) |
| 132 | return |
| 133 | } |
| 134 | |
| 135 | setTimeout(attempt, 250) |
| 136 | } |
| 137 | |
| 138 | attempt() |
| 139 | }) |
| 140 | } |
| 141 | |
| 142 | async function stopChild(child: ReturnType<typeof spawn>) { |
| 143 | if (child.killed || child.exitCode !== null) { |
no test coverage detected