Skip to content
// EFFECT DAYS 2026

TestTerminal unstable

Provides scripted terminal input and captures displayed text for tests.

Tests queue keys and text before or while a program reads terminal input, then inspect the displayed text with output. Input is finite by default: if a prompt still needs input when the script runs out, Prompt.run fails with Terminal.QuitError. Pass open: true to keep input open until endInput.

8 exports Since v4.1.8 Source

Constructors

make

unstable
Since v4.1.8

Creates a TestTerminal with fixed dimensions and an empty script.

Details

readLine returns the text up to the next enter or return. When input ends first, it returns the partial line, or fails with Terminal.QuitError when no text was typed. Escape, Ctrl+C and Ctrl+D fail with Terminal.QuitError, even after partial input.

See

  • layer for providing the terminal as the Terminal service

Signature

declare function make(options?: Options): Effect<TestTerminal>

Layers

layer

unstable
Since v4.1.8

Creates a Layer that provides a fresh TestTerminal as the Terminal service.

See

Signature

declare function layer(options?: Options): Layer<Terminal>

Example Feeding input to a running prompt

import { Effect, Fiber } from "effect"
import { Prompt } from "effect/cli"
import { TestTerminal } from "effect/testing"
const program = Effect.gen(function*() {
const fiber = yield* Effect.forkChild(Prompt.run(Prompt.String({ message: "Name" })))
yield* Effect.yieldNow
yield* TestTerminal.inputText("Ada\n")
return yield* Fiber.join(fiber)
}).pipe(Effect.provide(TestTerminal.layer({ open: true })))
await Effect.runPromise(program) // => "Ada"

Models

TestTerminal

interface unstable
Since v4.1.8

A Terminal that reads scripted input and records displayed text.

Details

Each reader takes the scripted input that is still unread. Input it leaves unread returns to the script when its scope closes, so one script can feed several Prompt.run calls in a row. Escape, Ctrl+C and Ctrl+D are delivered and then end input for the current reader, as NodeTerminal does.

See

  • layer for providing a TestTerminal to an effect

Signature

interface TestTerminal extends Terminal {
readonly endInput: Effect<void>;
readonly inputKey: (name: string, modifiers?: Modifiers) => Effect<void>;
readonly inputText: (text: string) => Effect<void>;
readonly output: Effect<readonly Array<string>>;
}

Example Scripting a select prompt

import { Effect } from "effect"
import { Prompt } from "effect/cli"
import { TestTerminal } from "effect/testing"
const program = Effect.gen(function*() {
yield* TestTerminal.inputKey("down")
yield* TestTerminal.inputKey("enter")
return yield* Prompt.run(Prompt.Select({
message: "Pick",
choices: [{ title: "Alpha", value: "alpha" }, { title: "Beta", value: "beta" }]
}))
}).pipe(Effect.provide(TestTerminal.layer()))
await Effect.runPromise(program) // => "beta"

Other

Since v4.1.8

Types used to configure a TestTerminal.

Testing

endInput

unstable
Since v4.1.8

Ends input on a TestTerminal created with open: true once the queued script has been read.

Signature

declare const endInput: Effect.Effect<void, never, Terminal.Terminal>

inputKey

unstable
Since v4.1.8

Queues one key event on the provided TestTerminal.

Details

Only single-character names carry input. Escape, Ctrl+C and Ctrl+D end input for the reader that receives them.

See

Signature

declare function inputKey(name: string, modifiers?: Modifiers): Effect<void, never, Terminal>

inputText

unstable
Since v4.1.8

Queues one key event per character of text on the provided TestTerminal, with \n as enter and \r as return.

See

Signature

declare function inputText(text: string): Effect<void, never, Terminal>

output

unstable
Since v4.1.8

Returns every chunk displayed on the provided TestTerminal, in order.

Signature

declare const output: Effect.Effect<ReadonlyArray<string>, never, Terminal.Terminal>