runtime/mock.ts

Mock RuntimeDeps for testing.

Provides a fully controllable runtime implementation for unit tests. Consumer projects can extend MockRuntime with project-specific helpers (e.g. setup_mock_tx_config) that stay local.

Declarations
#

5 declarations

view source

create_mock_runtime
#

runtime/mock.ts view source

(args?: string[]): MockRuntime

Create a mock RuntimeDeps for testing.

args

CLI arguments

type string[]
default []

returns

MockRuntime

MockRuntime with controllable state

examples

const runtime = create_mock_runtime(['apply', 'tx.ts']); runtime.mock_env.set('HOME', '/home/test'); runtime.mock_fs.set('/home/test/.app/config.json', '{}'); await some_function(runtime); assert.strictEqual(runtime.command_calls.length, 1); assert.deepStrictEqual(runtime.exit_calls, [0]);

MockExitError
#

runtime/mock.ts view source

Error thrown when mock runtime.exit() is called.

Tests can catch this to verify exit behavior.

inheritance

extends:
  • Error

code

type number

readonly

constructor

type new (code: number): MockExitError

code
type number

MockRuntime
#

runtime/mock.ts view source

MockRuntime

Mock RuntimeDeps with observable state for assertions.

inheritance

extends:

mock_env

Mock environment variables.

type Map<string, string>

mock_fs

Mock file system (path -> content).

type Map<string, string>

mock_dirs

Mock directories that exist.

type Set<string>

exit_calls

Exit calls recorded (exit codes).

type Array<number>

command_calls

Commands executed.

type Array<{cmd: string; args: Array<string>}>

command_inherit_calls

Commands executed with inherit.

type Array<{cmd: string; args: Array<string>}>

stdout_writes

Stdout writes recorded.

type Array<string>

mock_command_results

Mock command results (cmd -> result).

type Map<string, CommandResult>

stdin_buffer

Stdin buffer for input simulation.

type Uint8Array | null

reset_mock_runtime
#

set_mock_stdin
#