| name | terminal-emulator |
| description | Test interactive CLI/TUI applications using @microsoft/tui-test. Use when you need to test CLI tools with interactive prompts, TUI rendering, arrow key navigation, or any command that requires a TTY. Triggers include "test CLI", "test TUI", "run interactively", "automate terminal input", "simulate user input in terminal". |
| allowed-tools | Bash(npx tui-test:*), Bash(node:*) |
Testing Interactive CLI / TUI with @microsoft/tui-test
Playwright-like API for terminals. Real PTY per test. Made by Microsoft.
Install
yarn add -D @microsoft/tui-test
Usage
import { test, expect } from '@microsoft/tui-test';
test.use({ program: { file: 'node', args: ['./my-cli.js'] } });
test('selects option and proceeds', async ({ terminal }) => {
await expect(terminal.getByText('Select an option')).toBeVisible();
await terminal.write('\x1B[B');
await terminal.submit();
await expect(terminal.getByText('Option 2 selected')).toBeVisible();
});
test('matches snapshot', async ({ terminal }) => {
await expect(terminal).toMatchSnapshot();
});
API
await terminal.write('\x1B[A');
await terminal.write('\x1B[B');
await terminal.write('\x1B[C');
await terminal.write('\x1B[D');
await terminal.submit();
await terminal.write('\t');
await terminal.write('\x03');
await terminal.write('\x1B');
await terminal.write('\x7F');
await terminal.write('hello');
await expect(terminal.getByText('pattern')).toBeVisible();
await expect(terminal.getByText('pattern', { full: true })).toBeVisible();
await expect(terminal).toMatchSnapshot();
const content = terminal.content;
Running
npx tui-test
npx tui-test --update-snapshots
npx tui-test my-test.ts
Reference
- Used by VS Code terminal team
- Real PTY isolation per test (no mocking)
- Auto-waits for terminal renders
- Cross-platform (macOS, Linux, Windows)
- Snapshot testing built-in