UNPKG

tui-tester

Version:

End-to-end testing framework for terminal user interfaces

255 lines (251 loc) 6.86 kB
import { i as TerminalTester, d as TesterConfig, K as KeyModifiers, P as Point, a as MouseEvent, S as ScreenCapture, W as WaitOptions, A as AssertionOptions, c as Snapshot, T as TerminalSize, e as Recording } from './types-I_UaGSPL.cjs'; /** * TmuxTester - Main E2E Testing Class * Provides comprehensive terminal UI testing through tmux */ declare class TmuxTester implements TerminalTester { private config; private adapter; private sessionName; private running; private _outputBuffer; private recording; private snapshots; private debugMode; constructor(config: TesterConfig); /** * Start the tmux session and launch the application */ start(): Promise<void>; /** * Stop the tmux session */ stop(): Promise<void>; /** * Restart the session */ restart(): Promise<void>; /** * Check if the session is running */ isRunning(): boolean; /** * Send text to the terminal */ sendText(text: string): Promise<void>; /** * Send a key with optional modifiers */ sendKey(key: string, modifiers?: KeyModifiers): Promise<void>; /** * Send multiple keys */ sendKeys(keys: string[]): Promise<void>; /** * Enable mouse support in the terminal */ enableMouse(): Promise<void>; /** * Disable mouse support in the terminal */ disableMouse(): Promise<void>; /** * Click at specific position */ click(x: number, y: number): Promise<void>; /** * Click on text in the terminal */ clickText(text: string): Promise<void>; /** * Double click at specific position */ doubleClick(x: number, y: number): Promise<void>; /** * Right click at specific position */ rightClick(x: number, y: number): Promise<void>; /** * Drag from one position to another */ drag(from: Point, to: Point): Promise<void>; /** * Scroll up or down */ scroll(direction: 'up' | 'down', lines?: number): Promise<void>; /** * Send a mouse event */ sendMouse(event: MouseEvent): Promise<void>; /** * Paste text (using bracketed paste mode) */ paste(text: string): Promise<void>; /** * Type text with optional delay between characters */ typeText(text: string, delayMs?: number): Promise<void>; /** * Capture the current screen */ captureScreen(): Promise<ScreenCapture>; /** * Get screen text without ANSI codes */ getScreenText(): Promise<string>; /** * Get screen lines without ANSI codes */ getScreenLines(): Promise<string[]>; /** * Get screen content (alias for getScreenText for backward compatibility) */ getScreenContent(): Promise<string>; /** * Get screen content with options */ getScreen(options?: { stripAnsi?: boolean; }): Promise<string>; /** * Get screen lines (alias for getScreenLines) */ getLines(): Promise<string[]>; /** * Wait for text to appear on screen */ waitForText(text: string, options?: WaitOptions): Promise<void>; /** * Wait for condition to be true */ waitFor(predicate: (screen: string) => boolean | Promise<boolean>, options?: WaitOptions): Promise<void>; /** * Wait for pattern to match screen content */ waitForPattern(pattern: RegExp, options?: WaitOptions): Promise<void>; /** * Wait for specific line to contain text */ waitForLine(lineNumber: number, text: string, options?: WaitOptions): Promise<void>; /** * Assert specific line contains text */ assertLine(lineNumber: number, predicate: string | ((line: string) => boolean)): Promise<void>; /** * Assert screen matches expected content or predicate */ assertScreen(expected: string[] | string | ((screen: string) => boolean), options?: AssertionOptions): Promise<void>; /** * Assert screen contains text */ assertScreenContains(text: string, options?: AssertionOptions): Promise<void>; /** * Assert screen matches pattern */ assertScreenMatches(pattern: RegExp, options?: AssertionOptions): Promise<void>; /** * Assert cursor is at specific position */ assertCursorAt(position: Point): Promise<void>; /** * Get current cursor position */ getCursor(): Promise<Point>; /** * Take a snapshot (alias for takeSnapshot for backward compatibility) */ snapshot(name: string, options?: { stripAnsi?: boolean; trim?: boolean; compare?: (expected: string, actual: string) => boolean; updateSnapshot?: boolean; customContent?: string; }): Promise<void>; /** * Take a snapshot */ takeSnapshot(name?: string): Promise<Snapshot>; /** * Compare current screen with snapshot */ compareSnapshot(snapshot: Snapshot | string): Promise<boolean>; /** * Save snapshot to file */ saveSnapshot(snapshot: Snapshot, path?: string): Promise<void>; /** * Load snapshot from file */ loadSnapshot(path: string): Promise<Snapshot>; /** * Resize the terminal */ resize(size: TerminalSize): Promise<void>; /** * Clear the screen */ clear(): Promise<void>; /** * Reset the terminal */ reset(): Promise<void>; /** * Get current terminal size */ getSize(): TerminalSize; /** * Get session name */ getSessionName(): string; /** * Get the last captured output (for debugging) */ getLastOutput(): string; /** * Clear the output buffer */ clearOutput(): void; /** * Execute a tmux command directly * Useful for advanced tmux operations not covered by higher-level methods */ exec(command: string): Promise<{ code: number; stdout: string; stderr: string; }>; /** * Capture screen with cursor position * Returns both screen content and cursor position */ capture(): Promise<ScreenCapture & { cursor: Point; }>; /** * Start recording session */ startRecording(): void; /** * Stop recording and return the recording */ stopRecording(): Recording; /** * Play back a recording */ playRecording(recording: Recording, speed?: number): Promise<void>; /** * Sleep for specified milliseconds */ sleep(ms: number): Promise<void>; /** * Debug log */ debug(message: string): void; private ensureRunning; /** * Send a command to the terminal (public method) */ sendCommand(command: string): Promise<void>; private recordEvent; } export { TmuxTester };