(
readText: () => string,
predicate: (text: string) => boolean,
options?: {
readonly timeoutMs?: number
readonly label?: string
},
)
| 178 | } |
| 179 | |
| 180 | export async function waitForText( |
| 181 | readText: () => string, |
| 182 | predicate: (text: string) => boolean, |
| 183 | options?: { |
| 184 | readonly timeoutMs?: number |
| 185 | readonly label?: string |
| 186 | }, |
| 187 | ): Promise<string> { |
| 188 | const deadline = Date.now() + (options?.timeoutMs ?? 4000) |
| 189 | let lastText = '' |
| 190 | while (Date.now() < deadline) { |
| 191 | lastText = readText() |
| 192 | if (predicate(lastText)) { |
| 193 | return lastText |
| 194 | } |
| 195 | await Bun.sleep(20) |
| 196 | } |
| 197 | |
| 198 | throw new Error( |
| 199 | `Timed out waiting for ${options?.label ?? 'text condition'}. Last capture:\n${lastText}`, |
| 200 | ) |
| 201 | } |
| 202 | |
| 203 | export function getFrameByLabel<T extends { readonly label: string }>( |
| 204 | frames: readonly T[], |
no test coverage detected