dreamcli/testkit
Test utilities for running commands in-process.
ts
import {
runCommand,
createCaptureOutput,
createTestPrompter,
createTestAdapter,
PROMPT_CANCEL,
} from 'dreamcli/testkit';runCommand(command, argv, options?)
Run a command in-process and return a RunResult.
ts
const result = await runCommand(greet, ['Alice', '--loud']);Parameters
| Parameter | Type | Description |
|---|---|---|
command | CommandBuilder | The command to run |
argv | string[] | Simulated command-line arguments |
options | RunOptions | Optional configuration |
RunOptions
| Option | Type | Description |
|---|---|---|
env | Record<string, string> | Environment variables |
config | Record<string, unknown> | Config file values |
answers | unknown[] | Prompt answers in order |
prompter | PromptEngine | Custom prompt handler |
json | boolean | Simulate --json mode |
help | boolean | Simulate --help |
verbosity | Verbosity | Output verbosity |
adapter | RuntimeAdapter | Custom runtime adapter |
RunResult
| Field | Type | Description |
|---|---|---|
exitCode | number | Process exit code |
stdout | string[] | Captured stdout lines |
stderr | string[] | Captured stderr lines |
error | Error | undefined | Error if action threw |
activity | ActivityEvent[] | Spinner/progress events |
createCaptureOutput()
Create an output channel that captures all writes for assertions.
createTestPrompter(answers)
Create a prompt engine that returns pre-defined answers.
ts
const prompter = createTestPrompter(['eu', true, 'my-name']);createTestAdapter(options?)
Create a runtime adapter for testing (no real process access).
PROMPT_CANCEL
Sentinel value to simulate prompt cancellation.
ts
const result = await runCommand(cmd, [], {
prompter: createTestPrompter([PROMPT_CANCEL]),
});