tui-snapshot-tester
БесплатноБез исполняемых скриптовНе проверенUse when a terminal UI (TUI) app needs tests that catch layout regressions. Captures rendered terminal frames as SVG or text snapshots and diffs them on each…
от testland★ 18 звёзд на GitHubОб этом скилле
tui-snapshot-tester
Overview
Per textual-testing:
"Snapshot testing is the process of recording the output of a test, and comparing it against the output from previous runs." Textual's
pytest-textual-snapshotplugin does this by saving an SVG screenshot of the running app to disk.
A TUI snapshot test:
- Renders the TUI to a deterministic frame (SVG / text).
- Compares the new frame to a stored baseline.
- Fails on diff; produces an HTML diff report so the human reviews the change.
- Updates the baseline only when the human says so.
This catches layout regressions (clipped text, wrong column widths, broken borders) that exit-code / output assertions miss.
When to use
- The unit-under-test is a TUI (Textual / Ratatui / Bubble Tea / Ink / curses).
- The TUI's value is its visual layout - assertions on individual cells are brittle and miss "the box border now looks broken."
- The team needs PR-time review of layout changes (vs catching them in user feedback).
For headless CLIs that emit text only, prefer
bats-testing +
cli-output-conventions;
TUI snapshots are only needed for layout-rich UIs.
Step 1 - Install (Python / Textual)
Per txt:
pip install pytest-textual-snapshot
This pulls Textual + the snap_compare pytest fixture.
Step 2 - First snapshot test
Per txt (verbatim):
def test_calculator(snap_compare):
assert snap_compare("path/to/calculator.py")
First run fails (no baseline). Per txt:
"Only ever run pytest with
--snapshot-updateif you're happy with how the output looks on the left hand side of the snapshot report."
Workflow:
- Run
pytest. It fails; emits an HTML report atsnapshot_report.html. - Open the report. The "left hand side" shows the new render; the "right hand side" shows the saved baseline.
- If the new render is correct, run
pytest --snapshot-updateto accept it. - Commit the updated
__snapshots__/directory.
Step 3 - Drive interactions before capture
Per txt:
# Press keys before snapshotting
assert snap_compare("path/to/calculator.py", press=["1", "2", "3"])
# Custom terminal dimensions
assert snap_compare("path/to/calculator.py", terminal_size=(50, 100))
# Run setup code (mouse hover, etc.)
async def run_before(pilot) -> None:
await pilot.hover("#number-5")
assert snap_compare("path/to/calculator.py", run_before=run_before)
The Pilot API per txt:
async def test_keys():
app = RGBApp()
async with app.run_test() as pilot:
await pilot.press("r")
assert app.screen.styles.background == Color.parse("red")
pilot.press() / pilot.click() / pilot.pause() simulate user
input.
Step 4 - CI integration (Textual)
Per txt:
"work well in CI on all supported operating systems, and the snapshot report is just an HTML file which can be exported as a build artifact."
jobs:
tui-snapshot:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/setup-python@v5
with: { python-version: '3.13' }
- run: pip install pytest-textual-snapshot
- name: Run snapshot tests
run: pytest tests/ui/
- uses: actions/upload-artifact@v4
if: failure()
with: { name: snapshot-report, path: snapshot_report.html }
Reviewer downloads snapshot_report.html from the failed CI
artifact, opens it locally, and decides accept / reject.
Step 5 - Equivalent for Rust / Ratatui
Use insta for snapshot testing:
# Cargo.toml
[dev-dependencies]
insta = "1"
ratatui = { version = "0.29", features = ["test-buffer"] }
#[test]
fn renders_main_view() {
let mut terminal = Terminal::new(TestBackend::new(80, 24)).unwrap();
terminal.draw(|f| draw_main(f, &app_state())).unwrap();
insta::assert_snapshot!(terminal.backend().to_string());
}
Update with cargo insta accept (or cargo insta review for
interactive triage). Snapshots stored in tests/snapshots/.
Step 6 - Equivalent for Go / Bubble Tea
Use teatest:
func TestApp(t *testing.T) {
tm := teatest.NewTestModel(t, NewModel(), teatest.WithInitialTermSize(80, 24))
tm.Send(tea.KeyMsg{Type: tea.KeyEnter})
teatest.RequireEqualOutput(t, tm.FinalOutput(t,
teatest.WithFinalTimeout(2*time.Second)))
}
teatest.RequireEqualOutput writes / compares against
testdata/<test-name>.golden. Update with -update:
go test -update ./...
Step 7 - Equivalent for Node / Ink
Use ink-testing-library:
import { render } from 'ink-testing-library';
import App from './app';
test('renders welcome screen', () => {
const { lastFrame } = render(<App />);
expect(lastFrame()).toMatchSnapshot();
});
Jest's built-in toMatchSnapshot writes to
__snapshots__/. Update with jest -u.
Step 8 - Determinism
Установить tui-snapshot-tester в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл tui-snapshot-tester?
Use when a terminal UI (TUI) app needs tests that catch layout regressions. Captures rendered terminal frames as SVG or text snapshots and diffs them on each run: pytest-textual-snapshot for Textual, insta for Ratatui, teatest for Bubble Tea, ink-testing-library for Ink.
Как установить скилл tui-snapshot-tester?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл tui-snapshot-tester запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
frontend-design
Guidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making…
от Anthropicwebapp-testing
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing…
от Anthropicbrand-guidelines
Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand…
от Anthropicweb-artifacts-builder
Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn/ui). Use…
от Anthropic