Skip to content

TestAdapterOptions

Options for creating a test adapter.

All fields are optional — sensible defaults are applied for testing scenarios (empty argv, empty env, noop stdout/stderr, non-TTY, exit throws instead of killing the process).

Signatures

ts
interface TestAdapterOptions {}

Members

Properties

argv

Raw argv (defaults to ['node', 'test']).

ts
argv?: readonly string[];

configDir

Config directory (defaults to '/home/test/.config').

ts
configDir?: string;

cwd

Working directory (defaults to '/test').

ts
cwd?: string;

env

Environment variables (defaults to {}).

ts
env?: Readonly<Record<string, string | undefined>>;

exit

Exit function (defaults to throwing ExitError). The default throw-based exit allows tests to catch the exit code.

ts
exit?: { (code: number): never; };

homedir

Home directory (defaults to '/home/test').

ts
homedir?: string;

isTTY

TTY flag for stdout (defaults to false).

ts
isTTY?: boolean;

readFile

File reader stub (defaults to returning null — all files not found).

Supply a custom function to simulate a virtual filesystem in tests:

ts
createTestAdapter({
  readFile: (path) => Promise.resolve(
    path === '/home/test/.config/myapp/config.json'
      ? '{"region":"eu"}'
      : null
  ),
})
ts
readFile?: { (path: string): Promise<string | null>; };

stderr

Stderr writer (defaults to noop).

ts
stderr?: WriteFn;

stdin

Stdin line reader (defaults to returning null — immediate EOF).

Use a custom ReadFn to simulate user input in tests.

ts
stdin?: ReadFn;

stdinData

Piped stdin data for testing args with .stdin() configured.

When provided and stdinIsTTY is false, readStdin() returns this string once, then null on subsequent reads. When absent, or when stdinIsTTY is true, readStdin() returns null.

ts
stdinData?: string;

stdinIsTTY

TTY flag for stdin (defaults to false).

ts
stdinIsTTY?: boolean;

stdout

Stdout writer (defaults to noop).

ts
stdout?: WriteFn;

See Also

Released under the MIT License.