UNPKG

tui-tester

Version:

End-to-end testing framework for terminal user interfaces

257 lines (245 loc) 9.07 kB
import { P as Point, R as Rectangle, A as AssertionOptions, C as ChildProcess } from './types-I_UaGSPL.cjs'; export { b as KeyEvent, K as KeyModifiers, M as MouseButton, a as MouseEvent, f as RecordedEvent, e as Recording, g as Runtime, h as RuntimeAdapter, S as ScreenCapture, c as Snapshot, m as StepResult, T as TerminalSize, i as TerminalTester, l as TestResult, j as TestScenario, k as TestStep, d as TesterConfig, W as WaitOptions } from './types-I_UaGSPL.cjs'; import { TmuxTester } from './tmux-tester.cjs'; import { BaseRuntimeAdapter } from './adapters/index.cjs'; export { createAdapter, detectRuntime, getAdapter, registerAdapter, resetAdapter, setAdapter, setDefaultAdapter } from './adapters/index.cjs'; export { TestRunner, TestRunnerOptions, runTest, scenario, step } from './helpers/test-runner.cjs'; export { cancel, clickAt, clickOnText, confirmDialog, copySelection, drag, executeCommand, exitApplication, fillField, login, navigateMenu, openCommandPalette, pasteFromClipboard, scroll, search, selectMenuItem, selectText, submitForm, switchTab, takeAnnotatedSnapshot, waitForLoading, waitForPrompt } from './helpers/interactions.cjs'; export { SnapshotManager, SnapshotOptions, getSnapshotManager, resetSnapshotManager } from './snapshot/snapshot-manager.cjs'; /** * E2E Testing Utilities * Helper functions for terminal output parsing and manipulation */ /** * Strip ANSI escape codes from text */ declare function stripAnsi(text: string): string; /** * Parse screen content into a 2D grid */ declare function parseScreen(content: string, cols: number, rows: number): string[][]; /** * Find text position in screen content */ declare function findText(content: string, searchText: string): Point[]; /** * Extract a rectangular region from screen content */ declare function extractRegion(content: string, region: Rectangle): string; /** * Normalize text for comparison */ declare function normalizeText(text: string, options?: AssertionOptions): string; /** * Compare two screen contents with options */ declare function compareScreens(actual: string, expected: string, options?: AssertionOptions): boolean; /** * Generate diff between two screen contents */ declare function screenDiff(actual: string, expected: string): string; /** * Wait with timeout */ declare function waitFor<T>(fn: () => Promise<T | undefined>, options?: { timeout?: number; interval?: number; message?: string; }): Promise<T>; /** * Sleep for specified milliseconds */ declare function sleep(ms: number): Promise<void>; declare const delay: typeof sleep; /** * Format timestamp for logging */ declare function formatTimestamp(timestamp: number): string; /** * Generate session name */ declare function generateSessionName(prefix?: string): string; /** * Parse screen lines from content */ declare function parseScreenLines(content: string): string[]; /** * Wait for a condition to be met */ declare function waitForCondition(condition: () => boolean | Promise<boolean>, options?: { timeout?: number; interval?: number; }): Promise<boolean>; /** * Escape regex special characters */ declare function escapeRegex(str: string): string; /** * Normalize line endings */ declare function normalizeLineEndings(text: string): string; /** * Trim empty lines from screen content */ declare function trimScreenContent(content: string | string[]): string | string[]; /** * Check if a command is available */ declare function isCommandAvailable(command: string): Promise<boolean>; /** * Get terminal size */ declare function getTerminalSize(): { cols: number; rows: number; }; /** * Escape shell arguments */ declare function escapeShellArg(arg: string): string; /** * Parse tmux key notation */ declare function parseTmuxKey(key: string, modifiers?: { ctrl?: boolean; alt?: boolean; shift?: boolean; }): string; /** * Parse mouse event for tmux */ declare function parseTmuxMouse(x: number, y: number, button?: 'left' | 'middle' | 'right'): string; /** * Extract cursor position from ANSI sequence */ declare function extractCursorPosition(ansiResponse: string): Point | null; /** * Split text into lines preserving empty lines */ declare function splitLines(text: string): string[]; /** * Join lines with proper line endings */ declare function joinLines(lines: string[], lineEnding?: '\n' | '\r\n'): string; /** * Calculate text dimensions (accounting for wide characters) */ declare function getTextDimensions(text: string): { width: number; height: number; }; /** * Get display width of a string (accounting for wide characters) */ declare function getStringWidth(str: string): number; /** * Get display width of a character */ declare function getCharWidth(char: string): number; /** * Bun Runtime Adapter * Fully async implementation for Bun */ declare class BunAdapter extends BaseRuntimeAdapter { private processes; exec(command: string): Promise<{ stdout: string; stderr: string; code: number; }>; spawn(command: string, args: string[], options?: any): Promise<ChildProcess>; kill(proc: ChildProcess, signal?: string): Promise<boolean>; write(proc: ChildProcess, data: string | Uint8Array): Promise<boolean>; read(proc: ChildProcess, timeout?: number): Promise<string>; resize(_proc: ChildProcess, _cols: number, _rows: number): Promise<boolean>; isAlive(proc: ChildProcess): Promise<boolean>; cleanup(): Promise<void>; readFile(path: string): Promise<string>; writeFile(path: string, content: string): Promise<void>; exists(path: string): Promise<boolean>; mkdir(path: string, options?: { recursive?: boolean; }): Promise<void>; rmdir(path: string, options?: { recursive?: boolean; }): Promise<void>; } /** * Node.js Runtime Adapter * Fully async implementation for Node.js */ declare class NodeAdapter extends BaseRuntimeAdapter { private processes; /** * Check if command is available with proper PATH */ commandExists(command: string): Promise<boolean>; exec(command: string): Promise<{ stdout: string; stderr: string; code: number; }>; spawn(command: string, args: string[], options?: any): Promise<ChildProcess>; kill(proc: ChildProcess, signal?: string): Promise<boolean>; write(proc: ChildProcess, data: string): Promise<boolean>; read(proc: ChildProcess, timeout?: number): Promise<string>; resize(_proc: ChildProcess, _cols: number, _rows: number): Promise<boolean>; isAlive(proc: ChildProcess): Promise<boolean>; cleanup(): Promise<void>; readFile(filePath: string): Promise<string>; writeFile(filePath: string, content: string): Promise<void>; exists(filePath: string): Promise<boolean>; mkdir(dirPath: string, options?: { recursive?: boolean; }): Promise<void>; rmdir(dirPath: string, options?: { recursive?: boolean; }): Promise<void>; } /** * Deno Runtime Adapter * Fully async implementation for Deno */ declare class DenoAdapter extends BaseRuntimeAdapter { private processes; exec(command: string): Promise<{ stdout: string; stderr: string; code: number; }>; spawn(command: string, args: string[], options?: any): Promise<ChildProcess>; kill(proc: ChildProcess, signal?: string): Promise<boolean>; write(proc: ChildProcess, data: string): Promise<boolean>; read(proc: ChildProcess, timeout?: number): Promise<string>; resize(_proc: ChildProcess, _cols: number, _rows: number): Promise<boolean>; isAlive(proc: ChildProcess): Promise<boolean>; cleanup(): Promise<void>; readFile(path: string): Promise<string>; writeFile(path: string, content: string): Promise<void>; exists(path: string): Promise<boolean>; mkdir(path: string, options?: { recursive?: boolean; }): Promise<void>; rmdir(path: string, options?: { recursive?: boolean; }): Promise<void>; } /** * Terminal E2E Testing Framework * Complete solution for testing terminal UI applications */ /** * Quick start function to create a tester */ declare function createTester(command: string | string[], options?: { cols?: number; rows?: number; env?: Record<string, string>; cwd?: string; debug?: boolean; shell?: string; sessionName?: string; recordingEnabled?: boolean; snapshotDir?: string; }): TmuxTester; export { AssertionOptions, BaseRuntimeAdapter, BunAdapter, ChildProcess, DenoAdapter, NodeAdapter, Point, Rectangle, TmuxTester, compareScreens, createTester, TmuxTester as default, delay, escapeRegex, escapeShellArg, extractCursorPosition, extractRegion, findText, formatTimestamp, generateSessionName, getCharWidth, getStringWidth, getTerminalSize, getTextDimensions, isCommandAvailable, joinLines, normalizeLineEndings, normalizeText, parseScreen, parseScreenLines, parseTmuxKey, parseTmuxMouse, screenDiff, sleep, splitLines, stripAnsi, trimScreenContent, waitFor, waitForCondition };