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;

mkdir ​

Directory creation stub for flag.path() create checks (defaults to a noop that resolves without creating anything).

ts
mkdir?: { (path: string): Promise<void>; };

onTerminalResize ​

Resize subscription hook returned by onTerminalResize().

ts
onTerminalResize?: { (listener: { (): void; }): { (): void; } | undefined; };

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>; };

stat ​

Filesystem probe stub for flag.path() checks (defaults to returning null — nothing exists).

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

ts
createTestAdapter({
  stat: (path) => Promise.resolve(path === '/data' ? 'directory' : null),
})
ts
stat?: { (path: string): Promise<"file" | "directory" | 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;

systemConfigDirs ​

System-scope config roots for discovery (defaults to []).

ts
systemConfigDirs?: readonly string[];

terminalSize ​

Terminal dimensions returned by getTerminalSize().

ts
terminalSize?: TerminalSize;

userConfigDirs ​

User-scope config roots for discovery (defaults to [configDir]).

ts
userConfigDirs?: readonly string[];

See Also ​

Released under the MIT License.