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[];

env ​

Environment variables (defaults to {}).

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

cwd ​

Working directory (defaults to '/test').

ts
cwd?: string;

stdout ​

Stdout writer (defaults to noop).

ts
stdout?: WriteFn;

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;

readSecret ​

Hidden reader stub; omitted adapters report unsupported hidden input.

ts
readSecret?: 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;

isTTY ​

TTY flag for stdout (defaults to false).

ts
isTTY?: boolean;

stdinIsTTY ​

TTY flag for stdin (defaults to false).

ts
stdinIsTTY?: boolean;

terminalSize ​

Terminal dimensions returned by getTerminalSize().

ts
terminalSize?: TerminalSize;

onTerminalResize ​

Resize subscription hook returned by onTerminalResize().

ts
onTerminalResize?: { (listener: { (): void; }): { (): void; } | 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; };

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

importConfigModule ​

Optional executable-config loader for a virtual filesystem.

ts
importConfigModule?: RuntimeAdapter["importConfigModule"];

importFreshConfigModule ​

ts
importFreshConfigModule?: RuntimeAdapter["importFreshConfigModule"];

configFileExists ​

ts
configFileExists?: RuntimeAdapter["configFileExists"];

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

mkdir ​

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

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

homedir ​

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

ts
homedir?: string;

configDir ​

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

ts
configDir?: string;

userConfigDirs ​

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

ts
userConfigDirs?: readonly string[];

systemConfigDirs ​

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

ts
systemConfigDirs?: readonly string[];

See Also ​

Released under the MIT License.