A TypeScript-based testing framework for automating CLI command testing, specifically designed for cloud operations.
- Execute CLI commands with various flags and options
- Verify command output and exit codes
- Clone the repository
- Install dependencies:
npm install
- Create a new test file in the
src/cli_tests
directory - Import the
CliTestHelper
class:
import { CliTestHelper } from '../utils/CliTestHelper';
- Initialize the helper with your CLI executable path:
const cli = new CliTestHelper('./path-to-your-cli');
- Write your tests:
describe('CLI Tests', () => {
it('should execute command successfully', async () => {
const result = await cli.expectCommandSuccess({
command: 'your-command',
args: ['--flag', 'value']
});
expect(result.stdout).toContain('expected output');
});
});
executeCommand(options)
: Execute a command and return the resultexpectCommandSuccess(options)
: Execute a command and expect it to succeedexpectCommandFailure(options, expectedExitCode)
: Execute a command and expect it to failexpectOutputContains(options, expectedOutput)
: Execute a command and expect output to contain textexpectOutputMatches(options, regex)
: Execute a command and expect output to match regex
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
For commands that require user input, you can simulate responses using environment variables:
const result = await cli.expectCommandSuccess({
command: 'configure',
env: {
CLI_INPUT_NAME: 'test-project',
CLI_INPUT_ENV: 'development'
}
});
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a new Pull Request