Skip to content

heroku/heroku-cli-test-utils

@heroku-cli/test-utils

A collection of test utilities for the Heroku CLI, designed to make testing CLI commands easier and more consistent.

Overview

This package provides a set of utilities to help test Heroku CLI commands, including:

  • Command execution helpers
  • Output expectation utilities
  • Output stubbing capabilities
  • Test initialization helpers

Installation

npm install --save-dev @heroku-cli/test-utils

Requirements

  • Node.js >= 20
  • TypeScript >= 5.4.0
  • Testing frameworks: Chai and Sinon

ESLint Configuration

This package includes a pre-configured ESLint setup that extends the OCLIF and TypeScript configurations. To use it in your project:

  1. Install the required peer dependencies:
npm install --save-dev eslint eslint-config-oclif eslint-config-oclif-typescript eslint-plugin-import eslint-plugin-mocha
  1. Create or update your .eslintrc.js:
module.exports = require('@heroku-cli/test-utils/src/eslint-config')

The configuration includes:

  • OCLIF base rules
  • TypeScript support
  • Mocha test framework rules
  • Import plugin rules
  • Custom rules for CLI development

Usage

Running Commands

import { runCommand } from '@heroku-cli/test-utils'

// Run a command and get its output
const { stdout, stderr } = await runCommand('heroku apps:list')

Expecting Output

import { expectOutput } from '@heroku-cli/test-utils'

// Test command output
await expectOutput('heroku apps:list', '=== My Apps')

Stubbing Output

import { stubOutput } from '@heroku-cli/test-utils'

// Stub command output for testing
const { stdout, stderr } = await stubOutput('heroku apps:list', {
  stdout: '=== My Apps\nmy-app-1\nmy-app-2',
  stderr: ''
})

Initializing Tests

import { init } from '@heroku-cli/test-utils'

// Initialize test environment
beforeEach(() => {
  init()
})

Development

Building

npm run build

Linting

npm run lint

Testing

npm test

Contributing

Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.

License

This project is licensed under the ISC License - see the LICENSE file for details.

About

Collection of testing utilities for use with the Heroku CLI

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published