term-transcript

Snapshot testing for CLI / REPL applications, in a fun way

APACHE-2.0 License

Downloads
21.5K
Stars
13
Committers
2

Capturing and Snapshot Testing for CLI / REPL Applications

term-transcript is a Rust library and a CLI app that allow to:

  • Create transcripts of interacting with a terminal, capturing both the output text
    and ANSI-compatible color info.
  • Save these transcripts in the SVG format, so that they can be easily embedded as images
    into HTML / Markdown documents. Rendering logic can be customized via Handlebars template engine;
    thus, other output formats besides SVG (e.g., HTML) are possible.
  • Parse transcripts from SVG.
  • Test that a parsed transcript actually corresponds to the terminal output (either as text
    or text + colors).

The primary use case is easy to create and maintain end-to-end tests for CLI / REPL apps. Such tests can be embedded into a readme file.

Usage

term-transcript comes in two flavors: a Rust library, and a CLI app. The CLI app has slightly less functionality, but does not require Rust knowledge. See their docs and the FAQ for usage guidelines and troubleshooting advice.

Examples

An SVG snapshot of the rainbow example produced by this crate:

A snapshot of the same example with the scrolling animation and window frame:

A snapshot of a similar example rendered to HTML using a custom template is available as a source file and in the rendered form.

See the examples directory for more snapshot examples.

Contributing

All contributions are welcome! See the contributing guide to help you get involved.

License

All code is licensed under either of Apache License, Version 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in term-transcript by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.