cli-testing-patterns_skill

This skill standardizes CLI testing patterns for Node.js and Python, enabling reliable exit code checks and output validation.
  • Python

0

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill vanman2024/cli-builder --skill cli-testing-patterns

  • SKILL.md5.5 KB

Overview

This skill packages battle-tested CLI testing strategies for Node.js (Jest) and Python (pytest + Click.testing.CliRunner). It focuses on command execution, exit-code validation, output and error verification, interactive prompt simulation, and integration testing patterns for professional CLI tooling.

How this skill works

The skill describes concrete test structures and helper patterns: a runCLI helper using child_process.execSync for Jest, and a pytest fixture that yields CliRunner for Click-based CLIs. It explains how to invoke commands, capture stdout/stderr, assert exit codes, and simulate interactive input. It also includes templates, test utilities, and scripts to scaffold test suites and CI-friendly execution.

When to use it

  • Writing or reviewing tests for Node.js CLIs (Jest) or Python Click/Typer CLIs (pytest + CliRunner)
  • Validating command execution, exit codes, and CLI output formats
  • Implementing interactive prompt tests or providing mocked stdin
  • Building integration test suites that exercise multi-command workflows
  • Enforcing consistent CLI testing patterns across a team or CI pipeline

Best practices

  • Test both success (0) and failure (non-zero) exit codes, and verify specific codes for error classes
  • Isolate tests: use fixtures and mocks to avoid real network calls or file-system side effects
  • Use helper functions (runCLI, runner fixtures) to keep tests concise and consistent
  • Assert output flexibly (substring checks) and precisely for structured formats (JSON/YAML)
  • Keep CLI tests fast; reserve slow end-to-end integration tests for separate suites

Example use cases

  • Unit tests asserting --version and --help return exit code 0 and expected text
  • Jest suites that capture stdout/stderr and verify error messages and exit codes for invalid args
  • pytest tests using CliRunner.invoke to simulate user input for interactive prompts
  • Integration tests that run multi-command workflows and validate state transitions and outputs
  • CI pipelines that run run-cli-tests.sh and fail on coverage regressions

FAQ

Prefer flexible matching for general content (substring or JSON parse) and exact assertions only for critical, stable outputs.

How do I simulate interactive prompts in tests?

In Jest, pipe input into the child process or mock stdin; in pytest use CliRunner.invoke(..., input='responses\n').

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational