import { launch, expect, test, Terminal, Locator, ghosttyThemes, rexThemes, capabilityPresets } from "testingterm";Every method has a doc comment in the package's type definitions, so editors show it inline.
launch
launch(command?: string | string[] | LaunchOptions, options?: LaunchOptions): Terminal| Option | Default | Description |
|---|---|---|
command |
your shell | String (runs through sh -c) or argv array |
cwd |
current directory | Working directory |
env |
Extra variables; undefined removes one |
|
cols, rows |
100, 30 |
Grid size |
fontSize |
13 |
Points |
scale |
2 |
Pixel density of screenshots and video |
padding |
8 |
Points around the grid |
theme |
"dark" |
Name, "ghostty", "rex", or colors; see themes |
capabilities |
"full" |
Preset or features; see capabilities |
timeout |
5000 |
Default for waits, locators and assertions |
isolate |
false |
Empty HOME and XDG folders |
record |
false |
true or a path: record a video from launch |
fps |
30 |
Video frame rate |
overlay |
true |
Draw pointer, clicks and keys in video |
profile |
false |
true or a path: record a profile from launch |
artifacts |
run folder | Where files go |
name |
program name | Used in file names and testingterm ls |
cursor |
true |
Draw the cursor in screenshots |
headed |
false |
Show a window (headed mode) |
slowMo |
0 |
Milliseconds to wait after each action |
Terminal
Reading
| Method | Returns |
|---|---|
screen() |
{ text, lines, cols, rows, cursor, title, altScreen, mouseTracking, bracketedPaste, kittyKeyboard, exited, exitCode, signal } |
text() |
The visible screen as text |
scrollback() |
Everything printed, including lines scrolled away |
styles() |
Rows of spans: { text, col, fg, bg, bold, italic, faint, underline, overline, strikethrough, inverse } |
find(text) |
Every match: { text, row, col, width, x, y, w, h, center } |
info() |
Engine and program process ids, sizes, recording state |
Input
| Method | Notes |
|---|---|
type(text, { delay }) |
\n presses Enter |
press(keys, { count }) |
"Enter", "ctrl+c", or an array |
paste(text) |
Bracketed paste when enabled |
click(point, { button, count, modifiers }) |
Point is { x, y } pixels or { col, row }; returns { sent } |
dblclick(point), move(point), down(point), up(point) |
|
drag(from, to, { steps }) |
|
wheel(lines, at?) |
Positive scrolls down |
resize(cols, rows), signal(name), focus(bool), scroll(lines) |
|
setTheme(theme) |
Switch theme live |
Waiting
waitForText(text | RegExp, { timeout, scrollback }), waitForGone(text), waitForIdle(ms), waitForStable(ms), waitForTitle(text), waitForExit(). See waiting and assertions.
Artifacts and lifecycle
| Method | Notes |
|---|---|
screenshot({ path, name, cursor }) |
{ path, width, height } |
startRecording({ path, fps }), stopRecording() |
{ path, durationMs } |
startProfile({ path }), stopProfile() |
Path of the trace |
verify(statement, options) |
Experimental |
close() |
Stops the program; returns { video, profile } |
Properties: id, name, command, artifacts, timeout, capabilities, socket.
Locator
terminal.getByText(text | RegExp, { exact }) returns a locator with first(), last(), nth(i), all(), count(), isVisible(), box(), waitFor({ state }), click(), dblclick(), hover(). Actions wait for the text and fail if it matches more than one place.
expect
| Target | Matchers |
|---|---|
expect(terminal) |
toHaveText, toHaveScreen, toHaveTitle, toHaveCursorAt, toHaveExited |
expect(locator) |
toBeVisible, toHaveCount |
expect(value) |
toBe, toEqual, toBeTruthy, toContain, toMatch, toBeGreaterThan, toBeLessThan |
All support .not. Terminal and locator matchers retry until they pass or time out.
test
test(name: string, fn: (context: { launch, name, artifacts }) => unknown, options?: { timeout?: number; retries?: number }): void
test.only(...)
test.skip(...)Errors
Failures throw errors with a readable message and, where it helps, a screen property with the screen text: AssertionError, LocatorError, EngineError, and VerifyError from verify.