Skip to content

Commit 88ecad2

Browse files
committed
test: wait for guided start failure state
1 parent c82d818 commit 88ecad2

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/cli/__tests__/ui.test.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,10 @@ test("guided start preserves an inline-submitted scope after failure", async ()
467467
});
468468
const screen = render(<InteractiveApp initialModel={uninitializedModel()} services={services} dimensions={{ columns: 88, rows: 28 }} />);
469469
screen.stdin.write("xss\r");
470-
await tick();
471-
await tick();
470+
await waitFor(() => {
471+
const frame = screen.lastFrame() ?? "";
472+
return frame.includes("› xss") && frame.includes("paste submission failed");
473+
});
472474
assert.deepEqual(submitted, ["xss"]);
473475
assert.match(screen.lastFrame() ?? "", / xss/);
474476
assert.match(screen.lastFrame() ?? "", /paste submission failed/);
@@ -617,3 +619,11 @@ function finding(input: {
617619
function tick(): Promise<void> {
618620
return new Promise((resolve) => setTimeout(resolve, 20));
619621
}
622+
623+
async function waitFor(predicate: () => boolean, timeoutMs = 1_000): Promise<void> {
624+
const deadline = Date.now() + timeoutMs;
625+
while (!predicate()) {
626+
if (Date.now() >= deadline) throw new Error(`condition not met within ${timeoutMs}ms`);
627+
await tick();
628+
}
629+
}

0 commit comments

Comments
 (0)