import { rnxExit } from '../../run-rnx' import { inspectWaitSelector } from './core' import type { WsBridge } from '../../ws-bridge' // blocks until a node with the given testID is visible and laid out, or — with // `--gone` — until it is absent. `--structural` drops the visibility test and // waits only for the node to exist, which is what a marker rendered as proof // (a build id, a launch phase) needs: it is 1x1 and painted under the app, so // it is permanently occluded and the visible check can never match it. the // engine owns the polling loop and this handler sends one request, then // reports. export async function runWaitSelectorSubcommand(opts: { bridge: WsBridge args: string[] positional: string[] inspectUsage: (name: string, tail: string) => string }): Promise { const { bridge, args, positional, inspectUsage } = opts const rawTestId = positional[1] if (!rawTestId) { console.error( inspectUsage( 'selector', ' [--max-ms 5000 | --timeout 5000] [--gone] [--structural]', ), ) rnxExit(1) } const testId = rawTestId.replace(/^#/, '') // the wait budget. `--max-ms` names it, and `--timeout` (the global // per-command budget) means the same thing for a command whose whole job is // to wait — without this it parsed away and the wait silently stayed at 5s, // reporting a false timeout. const maxMsIdx = args.indexOf('--max-ms') const budgetIdx = maxMsIdx >= 0 ? maxMsIdx : args.indexOf('--timeout') const timeoutMs = budgetIdx >= 0 && args[budgetIdx + 1] ? Math.max(100, Number(args[budgetIdx + 1])) : 5000 const gone = args.includes('--gone') const structural = args.includes('--structural') const { found, node, elapsed } = await inspectWaitSelector(bridge, testId, timeoutMs, { gone, structural, }) if (gone) { if (found) { console.log(` #${testId} gone after ${elapsed}ms`) } else { console.error( ` ⚠ wait selector #${testId} --gone timed out after ${elapsed ?? timeoutMs}ms (still present)`, ) rnxExit(1) } return } if (found && node) { const loc = `@(${Math.round(node.geometry.x)},${Math.round(node.geometry.y)})` const size = `${Math.round(node.geometry.width)}x${Math.round(node.geometry.height)}` console.log(` found #${testId} in ${elapsed}ms ${size} ${loc}`) } else { console.error( ` ⚠ wait selector #${testId} timed out after ${elapsed ?? timeoutMs}ms`, ) rnxExit(1) } }