* Poll until the terminal output contains the given text. * Throws if the timeout is exceeded.
(pattern: string, timeoutMs = 30_000)
| 161 | * Throws if the timeout is exceeded. |
| 162 | */ |
| 163 | async waitForText(pattern: string, timeoutMs = 30_000): Promise<string> { |
| 164 | const start = Date.now() |
| 165 | while (Date.now() - start < timeoutMs) { |
| 166 | const output = await this.capture() |
| 167 | if (output.includes(pattern)) return output |
| 168 | await new Promise((resolve) => setTimeout(resolve, 500)) |
| 169 | } |
| 170 | const finalOutput = await this.capture() |
| 171 | throw new Error( |
| 172 | `Timed out after ${timeoutMs}ms waiting for "${pattern}".\n` + |
| 173 | `Last output:\n${finalOutput}`, |
| 174 | ) |
| 175 | } |
| 176 | |
| 177 | /** Stop the tmux session and clean up the temp directory. */ |
| 178 | async stop(): Promise<void> { |