UNPKG

@stacksjs/clapp

Version:

A toolkit for building CLI prompts in TypeScript.

79 lines 2.4 kB
import { MockReadable, MockWritable } from '../test/utils'; import process from 'node:process'; import type { CLI } from './CLI'; /** * Creates a test instance of a CLI application, enabling isolated testing without side effects. */ export declare function createTestCLI(options?: Record<string, any>): CLI; /** * Prepares a CLI instance for testing by disabling process exits and redirecting outputs. */ export declare function setupTest(): TestContext; /** * Restore the process state after testing */ export declare function teardownTest(context: TestContext): void; /** * Executes a command on the CLI instance and returns the result. */ export declare function execCommand(cliInstance: CLI, argv: string[], options?: ExecCommandOptions): Promise<ExecCommandResult>; /** * Mocks user responses to interactive prompts. */ export declare function mockPrompt(responses: PromptResponses): void; /** * Gets the mocked response for a prompt if available */ export declare function getMockResponse(prompt: string): any; /** * Reset mock prompt responses */ export declare function resetMockPrompts(): void; /** * Captures all output during test execution. */ export declare function captureOutput(): { stdout: string[] stderr: string[] stop: () => { stdout: string, stderr: string } }; /** * Gets the most recent output from the test CLI. */ export declare function getLastOutput(): string; /** * Creates a temporary test directory with the specified file structure. */ export declare function createTestFS(structure: Record<string, any>): Promise<string>; /** * Cleans up the test directory. */ export declare function cleanupTestFS(testDir: string): Promise<void>; export declare interface TestContext { stdout: MockWritable stderr: MockWritable stdin: MockReadable originalExit: typeof process.exit originalStdout: typeof process.stdout originalStderr: typeof process.stderr originalStdin: typeof process.stdin originalConsoleLog: typeof console.log } export declare interface ExecCommandOptions { inputs?: string[] env?: Record<string, string> cwd?: string timeout?: number } export declare interface ExecCommandResult { stdout: string stderr: string exitCode: number duration: number outputs: string[] result: any } /** * Response map for mocking prompts */ export type PromptResponses = Record<string, string | boolean | number>