Crates.io | term-transcript |
lib.rs | term-transcript |
version | 0.4.0-beta.1 |
source | src |
created_at | 2021-06-01 18:40:01.241983 |
updated_at | 2024-03-03 12:05:53.342083 |
description | Snapshotting and snapshot testing for CLI / REPL applications |
homepage | |
repository | https://github.com/slowli/term-transcript |
max_upload_size | |
id | 404861 |
size | 356,906 |
This crate allows to:
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.
Add this to your Crate.toml
:
[dependencies]
term-transcript = "0.4.0-beta.1"
Example of usage:
use term_transcript::{
svg::{Template, TemplateOptions}, ShellOptions, Transcript, UserInput,
};
use std::str;
let transcript = Transcript::from_inputs(
&mut ShellOptions::default(),
vec![UserInput::command(r#"echo "Hello world!""#)],
)?;
let mut writer = vec![];
// ^ Any `std::io::Write` implementation will do, such as a `File`.
Template::new(TemplateOptions::default()).render(&transcript, &mut writer)?;
println!("{}", str::from_utf8(&writer)?);
Ok::<_, anyhow::Error>(())
See more examples in the crate docs and the FAQ for some tips and troubleshooting advice.
Most of the library functionality is packaged into a CLI binary, which allows using the library without Rust knowledge. See the binary docs for the installation and usage guides.
An SVG snapshot of the rainbow
example
produced by this crate:
A snapshot of the same example with the scrolling animation and window frame:
isatty
checks
or getting term size can produce different output than if launched in an actual shell
(no coloring, no line wrapping etc.).portable-pty
crate feature. However, since most escape sequences are dropped, this is still not a good
option to capture complex outputs (e.g., ones moving cursor).insta
is a generic snapshot testing library, which
is amazing in general, but kind of too low-level for E2E CLI testing.rexpect
allows testing CLI / REPL applications
by scripting interactions with them in tests. It works in Unix only.trybuild
snapshot-tests output
of a particular program (the Rust compiler).trycmd
snapshot-tests CLI apps using
a text-based format.termtosvg
and
Asciinema allow recording terminal sessions and save them to SVG.
The output of these tools is inherently dynamic (which, e.g., results in animated SVGs).
This crate intentionally chooses a simpler static format, which makes snapshot testing easier.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.