Available on crate feature
test only.Expand description
Snapshot testing tools for Transcripts.
§Examples
Simple scenario in which the tested transcript calls to one or more Cargo binaries / examples by their original names.
use term_transcript::{
ShellOptions, Transcript,
test::{MatchKind, TestConfig, TestOutputConfig},
};
// Test configuration that can be shared across tests.
fn config() -> TestConfig {
let shell_options = ShellOptions::default()
.with_cargo_path_for("my-command");
TestConfig::new(shell_options)
.with_match_kind(MatchKind::Precise)
.with_output(TestOutputConfig::Verbose)
}
// Usage in tests:
#[test]
fn help_command() {
config().test("tests/__snapshots__/help.svg", &["my-command --help"]);
}§Lower-level testing
Use TestConfig::test_transcript() for more complex scenarios or increased control:
use term_transcript::{test::TestConfig, ShellOptions, Transcript, UserInput};
use std::io;
fn read_svg_file() -> anyhow::Result<impl io::BufRead> {
// snipped...
}
let reader = read_svg_file()?;
let transcript = Transcript::from_svg(reader)?;
TestConfig::new(ShellOptions::default()).test_transcript(&transcript);§Testing with custom capture logic
Use TestConfig::test_captured() if you need to customize snapshot capture logic.
use term_transcript::{test::TestConfig, Transcript, UserInput};
#[test]
fn captured_snapshot() {
let mut captured = Transcript::default();
let test_output = "result: [[bold green!]]OK[[/]]".parse().unwrap();
captured.add_interaction(UserInput::command("test").hide(), test_output);
TestConfig::new(())
.test_captured("tests/__snapshots__/test.svg", captured);
}Structs§
- Located
Parse Error ParseErrortogether with its location in the XML input.- Test
Config - Testing configuration.
- Test
Stats - Stats of a single snapshot test output by
TestConfig::test_transcript_for_stats().
Enums§
- Match
Kind - Kind of terminal output matching.
- Parse
Error - Errors that can occur during parsing SVG transcripts.
- Test
Output Config - Configuration of output produced during testing.
- Update
Mode svg - Strategy for saving a new snapshot on a test failure within
TestConfig::test()and related methods.
Traits§
- Test
Command - Command executed during snapshot testing in
TestConfigto reproduce a snapshot.