| Crates.io | ratatui-testlib |
| lib.rs | ratatui-testlib |
| version | 0.1.0 |
| created_at | 2025-12-01 21:50:43.617125+00 |
| updated_at | 2025-12-01 21:50:43.617125+00 |
| description | Integration testing library for terminal user interface applications with Sixel and Bevy support |
| homepage | |
| repository | https://github.com/raibid-labs/ratatui-testlib |
| max_upload_size | |
| id | 1960701 |
| size | 1,078,344 |
A Rust library for integration testing of terminal user interface (TUI) applications with first-class support for Ratatui, Bevy ECS integration, and Sixel graphics protocols.
ratatui-testlib bridges the gap between unit testing with Ratatui's TestBackend and real-world integration testing of TUI applications. It provides a PTY-based test harness that enables testing of features requiring actual terminal escape sequence processing, including Sixel graphics position verification, Bevy ECS integration, bevy_ratatui support, and complex user interaction flows.
Built to enable comprehensive integration testing for the dgx-pixels project - a Bevy-based TUI application with Sixel graphics support.
Current Limitation: Ratatui's TestBackend is great for unit testing widgets and layouts, but it can't test:
Solution: ratatui-testlib runs your TUI application in a real pseudo-terminal (PTY), captures the output using a terminal emulator, and provides an ergonomic API for assertions and snapshot testing.
MVP (v0.1.0):
portable-ptyinstaPost-MVP:
🚧 Research & Design Phase Complete → Implementation Starting
MVP Target: v0.1.0 in 3-4 months (Phases 1-6) Primary Use Case: dgx-pixels integration testing
See ROADMAP.md for detailed implementation plan and DGX_PIXELS_REQUIREMENTS.md for MVP requirements analysis.
use ratatui_testlib::TuiTestHarness;
use std::process::Command;
#[test]
fn test_navigation() -> Result<()> {
let mut harness = TuiTestHarness::new(80, 24)?;
// Spawn your TUI app
harness.spawn(Command::new("./my-tui-app"))?;
// Wait for initial render
harness.wait_for(|state| {
state.contents().contains("Main Menu")
})?;
// Simulate user input
harness.send_key(Key::Down)?;
harness.send_key(Key::Enter)?;
// Verify result
harness.wait_for(|state| {
state.contents().contains("Settings")
})?;
Ok(())
}
use ratatui_testlib::BevyTuiTestHarness;
#[tokio::test]
async fn test_sixel_renders_in_preview_area() -> Result<()> {
let mut test = BevyTuiTestHarness::with_bevy_ratatui()?;
// Load test image and navigate to Gallery
test.load_test_image("tests/fixtures/test-sprite.png")?;
test.press_key(KeyCode::Char('2'))?; // Gallery screen
test.update()?;
test.render_frame()?;
// Get preview area from Bevy component
let preview_panel = test.query::<PreviewPanel>().first().unwrap();
let preview_area = preview_panel.area;
// Assert: Sixel graphics within bounds
test.assert_sixel_within(preview_area)?;
test.assert_no_sixel_outside(preview_area)?;
Ok(())
}
#[tokio::test]
async fn test_sixel_clears_on_screen_change() -> Result<()> {
let mut test = BevyTuiTestHarness::with_bevy_ratatui()?;
// Render image on Gallery screen
test.load_test_image("tests/fixtures/test-sprite.png")?;
test.press_key(KeyCode::Char('2'))?;
test.update()?;
test.render_frame()?;
assert!(test.has_sixel_graphics());
// Navigate away
test.press_key(KeyCode::Char('1'))?; // Generation screen
test.update()?;
test.render_frame()?;
// Assert: Sixel cleared
assert!(!test.has_sixel_graphics());
Ok(())
}
RESEARCH.md - Comprehensive research on existing terminal testing solutions, parsing libraries (VTE, vt100, termwiz), PTY libraries (portable-pty), snapshot testing frameworks (insta, expect-test), and Sixel testing approaches. Essential background for understanding the problem space.
ARCHITECTURE.md - Complete library architecture including:
EXISTING_SOLUTIONS.md - Analysis of existing Ratatui testing approaches:
TESTING_APPROACHES.md - Comprehensive guide to TUI testing methodologies:
ROADMAP.md - Updated for dgx-pixels MVP:
DGX_PIXELS_REQUIREMENTS.md - MVP Requirements Analysis:
| Topic | Document | Key Sections |
|---|---|---|
| MVP Requirements | DGX_PIXELS_REQUIREMENTS.md | Use Cases, Gap Analysis, Roadmap Adjustments |
| Implementation Plan | ROADMAP.md | MVP Phases 1-6, Timeline, dgx-pixels Checklist |
| API Design | ARCHITECTURE.md | Bevy Integration, Sixel Position Tracking |
| Understand the Problem | EXISTING_SOLUTIONS.md | Gap Analysis, Comparison Matrix |
| Testing Strategies | TESTING_APPROACHES.md | Testing Pyramid, Common Patterns |
| Technical Research | RESEARCH.md | VTE vs vt100, PTY Libraries, Sixel Testing |
| Testing Level | Use This | For What |
|---|---|---|
| Unit Tests | Ratatui's TestBackend + insta | Individual widgets, layout calculations |
| Integration Tests | ratatui-testlib | Full app behavior, PTY interaction, graphics |
| CLI Tests | assert_cmd | Binary execution, exit codes |
| Snapshot Tests | insta or expect-test | Both unit and integration levels |
ratatui-testlib is complementary, not competitive - it fills the integration testing gap that TestBackend cannot address.
| Feature | TestBackend | ratatui-testlib |
|---|---|---|
| Speed | Very Fast | Moderate |
| Setup Complexity | Simple | Moderate |
| PTY Testing | ❌ | ✅ |
| Graphics (Sixel) | ❌ | ✅ |
| Widget Unit Tests | ✅ | ✅ |
| Integration Tests | ❌ | ✅ |
| Event Simulation | Limited | Full |
| Async Support | Basic | Full |
| Snapshot Testing | Via insta/expect | Built-in |
Recommendation: Use TestBackend for unit tests, ratatui-testlib for integration tests.
┌─────────────────────────────────────────┐
│ Ratatui Integration Helpers (Layer 5) │ Widget assertions, layout verification
├─────────────────────────────────────────┤
│ Snapshot Testing (Layer 4) │ insta/expect-test integration
├─────────────────────────────────────────┤
│ Test Harness (Layer 3) │ TuiTestHarness, event simulation
├─────────────────────────────────────────┤
│ Terminal Emulation (Layer 2) │ vt100 parser, screen state
├─────────────────────────────────────────┤
│ PTY Management (Layer 1) │ portable-pty wrapper
└─────────────────────────────────────────┘
See ARCHITECTURE.md for complete details.
Target: Enable dgx-pixels integration testing
Success Criteria: dgx-pixels can detect and prevent Sixel positioning/persistence bugs
See ROADMAP.md for the complete implementation plan.
This project is in the design phase. Feedback on the architecture and approach is welcome!
Once implementation begins:
This project builds on excellent work from:
Special thanks to the maintainers of these projects for their well-documented, reusable components.
TBD (likely MIT or MIT/Apache-2.0 dual license)
Status: 🚧 Research & Design Phase Complete → Ready for Phase 1 Implementation MVP Target: v0.1.0 for dgx-pixels in 3-4 months See: ROADMAP.md | DGX_PIXELS_REQUIREMENTS.md