Your first script
Save this as check.mjs next to the program you want to test:
import { launch, expect } from "testingterm";
const term = launch("node menu.mjs");
await expect(term).toHaveText("Main menu");
await term.press("Down");
await term.press("Enter");
await expect(term).toHaveText("You picked Run tests");
await term.screenshot();Run it:
$ testingterm run check.mjs
✓ check.mjs (142ms)
/tmp/testingterm/run-.../check/node-4v05-01.png
1 passed in 144msimport "testingterm" resolves on its own under testingterm run, even when the package isn't installed in the project.
What happened:
launchstartednode menu.mjsin a 100x30 terminal.expect(term).toHaveText(...)waited until the text appeared. Assertions retry until they pass or time out (5 seconds by default), so there are no sleeps.presssent real key events, encoded the way the program asked for them.screenshotsaved a PNG of exactly what a person would see.
One call, no file
For quick checks, pass code directly. launch, expect and test are already in scope:
$ testingterm run -e 'const t = launch("ls -la"); await expect(t).toHaveText("package.json"); await t.screenshot()'Keep a video
$ testingterm run check.mjs --video onVideos show the mouse pointer, clicks and keys pressed, so a person can follow what the test did. Use --video retain-on-failure to keep videos only for tests that fail.
Next
- Group cases with
test(). - Learn the waits and assertions that keep tests reliable.
- Drive a terminal step by step from the CLI.