Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ render(<Counter />);
- [instagram-cli](https://github.com/supreme-gg-gg/instagram-cli) - Instagram client.
- [ElevenLabs CLI](https://github.com/elevenlabs/cli) - ElevenLabs agents client.
- [SSH AI Chat](https://github.com/miantiao-me/ssh-ai-chat) - Chat with AI over SSH.
- [blade-code](https://github.com/echoVic/blade-code) - AI-powered CLI coding agent with 20+ built-in tools, MCP support, and multi-model providers.

*(PRs welcome. Append new entries at the end. Repos must have 100+ stars and showcase Ink beyond a basic list picker.)*

Expand Down
44 changes: 32 additions & 12 deletions test/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ import {
import {run} from './helpers/run.js';
import {renderAsync} from './helpers/test-renderer.js';

async function waitForWriteMatching(
stdout: ReturnType<typeof createStdout>,
predicate: (writes: string[]) => boolean,
timeout = 5000,
): Promise<void> {
const deadline = Date.now() + timeout;
while (Date.now() < deadline) {
if (predicate(stdout.getWrites().map(w => stripAnsi(w)))) {
return;
}

// eslint-disable-next-line no-await-in-loop
await new Promise(resolve => {
setTimeout(resolve, 50);
});
}
}

test('text', t => {
const output = renderToString(<Text>Hello World</Text>);

Expand Down Expand Up @@ -876,9 +894,10 @@ test('render only last frame when stdout is not a TTY', async t => {
debug: false,
});

await new Promise(resolve => {
setTimeout(resolve, 200);
});
// Poll until the final state is reached instead of using a fixed delay
await waitForWriteMatching(stdout, writes =>
writes.some(w => w.includes('Count: 3')),
);

unmount();
await waitUntilExit();
Expand Down Expand Up @@ -932,9 +951,10 @@ test('render all frames when interactive is explicitly true', async t => {
interactive: true,
});

await new Promise(resolve => {
setTimeout(resolve, 500);
});
// Poll until the final state is reached instead of using a fixed delay
await waitForWriteMatching(stdout, writes =>
writes.some(w => w.includes('Count: 2')),
);

unmount();
await waitUntilExit();
Expand Down Expand Up @@ -974,9 +994,10 @@ test('interactive option overrides TTY detection', async t => {
interactive: false,
});

await new Promise(resolve => {
setTimeout(resolve, 200);
});
// Poll until the final state is reached instead of using a fixed delay
await waitForWriteMatching(stdout, writes =>
writes.some(w => w.includes('Count: 3')),
);

unmount();
await waitUntilExit();
Expand Down Expand Up @@ -1480,9 +1501,8 @@ test('static output is written immediately in non-interactive mode', async t =>
debug: false,
});

await new Promise(resolve => {
setTimeout(resolve, 200);
});
// Poll until static item B is written instead of using a fixed delay
await waitForWriteMatching(stdout, writes => writes.join('').includes('B'));

// Capture writes BEFORE unmount — static items must already be here
const writesBeforeUnmount = stdout.getWrites().map(w => stripAnsi(w));
Expand Down