Skip to content

@kjanat/dreamcli/testkit

Test utilities for running commands in-process.

ts
import {
  ,
  ,
  ,
  ,
  ,
} from '@kjanat/dreamcli/testkit';

runCommand(command, argv, options?)

Run a command in-process and return a RunResult.

ts
import {  } from '@kjanat/dreamcli/testkit';

const  = await (, ['Alice', '--loud']);

Parameters

ParameterTypeDescription
commandCommandBuilderThe command to run
argvstring[]Simulated command-line arguments
optionsRunOptionsOptional configuration

RunOptions

OptionTypeDescription
envRecord<string, string | undefined>Environment variables
configRecord<string, unknown>Config file values
stdinDatastring | nullData to pipe to process stdin for tests
answersunknown[]Prompt answers in order
prompterPromptEngineCustom prompt handler
jsonModebooleanSimulate --json mode
helpHelpOptionsHelp formatting options
verbosityVerbosityOutput verbosity
isTTYbooleanSimulate TTY connection

RunResult

FieldTypeDescription
exitCodenumberProcess exit code
stdoutstring[]Captured stdout lines
stderrstring[]Captured stderr lines
errorCLIError | undefinedStructured error, undefined on success
activityActivityEvent[]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
import {  } from '@kjanat/dreamcli/testkit';

const  = ([
  'eu',
  true,
  'my-name',
]);

createTestAdapter(options?)

Returns a runtime adapter for testing (no real process access).

PROMPT_CANCEL

Sentinel value to simulate prompt cancellation.

ts
import {
  ,
  ,
  ,
} from '@kjanat/dreamcli/testkit';

const  = await (, [], {
  : ([]),
});

Released under the MIT License.