import { PadroneRuntime } from "../core/runtime.mjs"; import { AnyPadroneCommand } from "../types/command.mjs"; //#region src/feature/test.d.ts /** * Result from a single command execution in test mode. * Extends the standard PadroneCommandResult with captured I/O. */ type TestCliResult = { /** The matched command. */command: AnyPadroneCommand; /** Validated arguments (undefined if validation failed). */ args: unknown; /** Action handler return value (undefined if validation failed or no action). */ result: unknown; /** Validation issues, if any. */ issues: { message: string; path?: PropertyKey[]; }[] | undefined; /** All values passed to `runtime.output()`. */ stdout: unknown[]; /** All strings passed to `runtime.error()`. */ stderr: string[]; /** The thrown error, if the command threw (routing error, action error, etc.). */ error?: unknown; }; /** * Result from a REPL test session. */ type TestReplResult = { /** One entry per successfully executed command (validation errors are captured in stderr, not here). */results: Omit[]; /** All output from the entire REPL session. */ stdout: unknown[]; /** All errors from the entire REPL session. */ stderr: string[]; }; /** * Fluent builder for setting up CLI test scenarios. */ type TestCliBuilder = { /** Set the CLI input string (e.g. `'deploy --env production'`). */args(input: string): TestCliBuilder; /** Set environment variables visible to the command. */ env(vars: Record): TestCliBuilder; /** Provide mock answers for interactive prompts. Keys are field names. */ prompt(answers: Record): TestCliBuilder; /** Provide mock stdin data (simulates piped input). */ stdin(data: string): TestCliBuilder; /** * Execute a single command via `eval()` and return the result with captured I/O. * @param input - Optional CLI input string. Overrides `.args()` if provided. */ run(input?: string): Promise; /** * Run a REPL session with the given sequence of inputs. * Each string in the array is fed as one line of input. * The session ends after all inputs are consumed (EOF). */ repl(inputs: string[]): Promise; }; /** * Creates a fluent test builder for a Padrone program. * Captures all I/O and provides a clean interface for assertions. * * Works with any test framework (bun:test, vitest, jest, node:test, etc.). * * @example * ```ts * import { testCli } from 'padrone/test' * * const result = await testCli(myProgram) * .args('deploy --env production') * .env({ API_KEY: 'xxx' }) * .run() * * expect(result.result).toBe('Deployed') * expect(result.stdout).toContain('Deploying...') * ``` * * @example * ```ts * // Shorthand: pass input directly to run() * const result = await testCli(myProgram).run('deploy --env production') * ``` * * @example * ```ts * // Test interactive prompts * const result = await testCli(myProgram) * .args('init') * .prompt({ name: 'myapp', template: 'react' }) * .run() * * expect(result.args).toEqual({ name: 'myapp', template: 'react' }) * ``` * * @example * ```ts * // Test REPL sessions * const { results } = await testCli(myProgram) * .repl(['greet World', 'add --a=2 --b=3']) * * expect(results[0].result).toBe('Hello, World!') * expect(results[1].result).toBe(5) * ``` */ /** * Any program-like object that has `eval`, `runtime`, and `repl` methods. * Avoids strict variance issues with `AnyPadroneProgram`. */ type TestableProgram = { eval: (input: string, prefs?: Record) => any; runtime: (runtime: PadroneRuntime) => TestableProgram; repl: (options?: { greeting?: false; hint?: false; }) => AsyncIterable; }; declare function testCli(program: TestableProgram): TestCliBuilder; //#endregion export { TestCliBuilder, TestCliResult, TestReplResult, testCli }; //# sourceMappingURL=test.d.mts.map