Testing
Test helpers for Crust CLIs with captured output and fake interactive terminals
@crustjs/testing adds helpers for raw execute() capture and fake interactive terminals. For ordinary typed action tests, use Core's app.run(), which already captures output and returns the action result; see Testing.
Install
npm install -D @crustjs/testing@crustjs/core is a required peer. @crustjs/prompts is an optional peer needed only by the @crustjs/testing/interactive entry point; the root entry point works without it. TypeScript is an optional peer.
captureExecute(app, argv)
const captured = await captureExecute(app, ["unknown"]);
console.log(captured.exitCode); // 1
console.log(captured.stderr); // Error: Unknown command "unknown".captureExecute() drives raw argv through execute() in-process and returns stdout, stderr, and exitCode. It restores the previous process exit state after capture. Use it for parser errors, rendered failures, and Extension onError output. app is anything with Crust's execute({ argv, io }) method (ExecutableApp).
Prop
Type
runInteractive(app, path, input?)
Import from @crustjs/testing/interactive; this entry point requires @crustjs/prompts. path and input are typed like app.run(), so a definition must be added to the application before it can be addressed.
const run = runInteractive(app, ["greet"]);
await run.waitFor(/Name/);
run.type("Ada");
run.keys("return");
await run.done;
console.log(run.screen()); // ✓ Name? AdawaitFor() polls the ANSI-stripped screen and defaults to a 5000 ms timeout. It fails as soon as the invocation fails or completes without a match, rather than waiting for the timeout. Call type() or keys() after the expected prompt appears, then await done.
done rejects with the error from a failed outcome. One ambient withTerminalIO scope sends prompts, progress, and stderr() output to the fake screen.
stdout() output is not included, so use run() for stdout assertions.
Prop
Type
Custom prompts
@crustjs/testing does not re-export prompt-author helpers. Test custom prompts with renderPrompt() from @crustjs/prompts/testing.