cli-testing-patterns
Installation
SKILL.md
CLI Testing Patterns
Comprehensive testing strategies for CLI applications using industry-standard testing frameworks. Covers command execution testing, exit code validation, output verification, interactive prompt testing, and integration testing patterns.
Instructions
When Testing Node.js CLI Tools
-
Use Jest for testing CLI commands
- Import
child_process.execSyncfor command execution - Create helper function to run CLI and capture output
- Test exit codes, stdout, stderr separately
- Handle both success and error cases
- Import
-
Test Structure
- Set up CLI path relative to test location
- Create
runCLI()helper that returns{stdout, stderr, code} - Use try-catch to handle non-zero exit codes
- Test common scenarios: version, help, unknown commands