Skip to content

This repository has framework that allows us to test cli tools like stackgen and cloud2code.

Notifications You must be signed in to change notification settings

appcd-dev/cli-tools-testing

Repository files navigation

CLI Testing Framework

A TypeScript-based testing framework for automating CLI command testing, specifically designed for cloud operations.

Features

  • Execute CLI commands with various flags and options
  • Verify command output and exit codes

Installation

  1. Clone the repository
  2. Install dependencies:
npm install

Usage

  1. Create a new test file in the src/cli_tests directory
  2. Import the CliTestHelper class:
import { CliTestHelper } from '../utils/CliTestHelper';
  1. Initialize the helper with your CLI executable path:
const cli = new CliTestHelper('./path-to-your-cli');
  1. 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');
  });
});

Available Methods

  • executeCommand(options): Execute a command and return the result
  • expectCommandSuccess(options): Execute a command and expect it to succeed
  • expectCommandFailure(options, expectedExitCode): Execute a command and expect it to fail
  • expectOutputContains(options, expectedOutput): Execute a command and expect output to contain text
  • expectOutputMatches(options, regex): Execute a command and expect output to match regex

Running Tests

# Run all tests
npm test

# Run tests in watch mode
npm run test:watch

Handling Interactive Prompts

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'
  }
});

Contributing

  1. Fork the repository
  2. Create your feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a new Pull Request

About

This repository has framework that allows us to test cli tools like stackgen and cloud2code.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published