CLI testing strategies and patterns for Node.js (Jest) and Python (pytest, Click.testing.CliRunner). Use when writing tests for CLI tools, testing command execution, validating exit codes, testing output, implementing CLI test suites, or when user mentions CLI testing, Jest CLI tests, pytest CLI, Click.testing.CliRunner, command testing, or exit code validation.
/plugin marketplace add vanman2024/cli-builder/plugin install cli-builder@cli-builderThis skill is limited to using the following tools:
examples/exit-code-testing/README.mdexamples/integration-testing/README.mdexamples/jest-advanced/README.mdexamples/jest-basic/README.mdexamples/pytest-click/README.mdscripts/run-cli-tests.shscripts/setup-jest-testing.shscripts/setup-pytest-testing.shscripts/validate-test-coverage.shtemplates/jest-cli-test.tstemplates/jest-config-test.tstemplates/jest-integration-test.tstemplates/pytest-click-test.pytemplates/pytest-fixtures.pytemplates/pytest-integration-test.pytemplates/test-helpers.pytemplates/test-helpers.tsComprehensive 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.
Use Jest for testing CLI commands
child_process.execSync for command executionTest Structure
runCLI() helper that returns {stdout, stderr, code}What to Test
Use pytest with Click.testing.CliRunner
CliRunner from click.testingrunner.invoke(cli, ['args'])result.exit_code and result.outputTest Structure
runner.invoke() to execute CLI commandsresult objectinput='responses\n'What to Test
Standard Exit Codes:
0 - Success1 - General error2 - Misuse of command (invalid arguments)126 - Command cannot execute127 - Command not found128+N - Fatal error signal NTesting Strategy:
Content Testing:
Best Practices:
.toContain() for flexible matching (Jest)in result.output for Python testsUse these templates for CLI testing:
templates/jest-cli-test.ts - Complete Jest test suite with execSynctemplates/jest-config-test.ts - Configuration file testingtemplates/jest-integration-test.ts - Multi-command integration teststemplates/pytest-click-test.py - Click.testing.CliRunner teststemplates/pytest-fixtures.py - Reusable pytest fixturestemplates/pytest-integration-test.py - Integration test patternstemplates/test-helpers.ts - Node.js test helper functionstemplates/test-helpers.py - Python test helper functionsUse these scripts for test setup and execution:
scripts/setup-jest-testing.sh - Install Jest and configure for CLI testingscripts/setup-pytest-testing.sh - Install pytest and Click testing dependenciesscripts/run-cli-tests.sh - Execute all CLI tests with coveragescripts/validate-test-coverage.sh - Check test coverage thresholdsSee complete examples in the examples/ directory:
examples/jest-basic/ - Basic Jest CLI testing setupexamples/jest-advanced/ - Advanced Jest patterns with mockingexamples/pytest-click/ - Click.testing.CliRunner examplesexamples/integration-testing/ - Full integration test suitesexamples/exit-code-testing/ - Exit code validation patternsNode.js Testing:
Python Testing:
Both:
Purpose: Standardize CLI testing across Node.js and Python projects Load when: Writing tests for CLI tools, validating command execution, testing exit codes
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.