| 1 | import { setTimeout } from "node:timers/promises"; |
| 2 | |
| 3 | export function parseServiceReady(log) { |
| 4 | const match = /desktop service ready: generation (\S+), pid (\d+)/.exec(log); |
| 5 | return match ? { generation: match[1], pid: Number(match[2]), line: match[0] } : null; |
| 6 | } |
| 7 | |
| 8 | // Playwright's waitForFunction polls synchronous truthiness: a Promise that |
| 9 | // resolves false is still truthy. Await host RPC results outside that API. |
| 10 | export async function waitForSmokeCondition(predicate, { timeout = 30000, interval = 25 } = {}) { |
| 11 | const deadline = performance.now() + timeout; |
| 12 | while (true) { |
| 13 | if (await predicate()) return; |
| 14 | if (performance.now() >= deadline) throw new Error("Timed out waiting for packaged smoke condition"); |
| 15 | await setTimeout(interval); |
| 16 | } |
| 17 | } |
| 18 |