Skip to content

oclif/test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

2d35b53 · Jan 5, 2025
Oct 24, 2023
Jun 11, 2024
Jul 22, 2024
Nov 17, 2024
May 22, 2024
Oct 24, 2023
Jan 26, 2018
Oct 24, 2023
Jan 16, 2018
Jan 16, 2018
Oct 24, 2023
May 21, 2024
Oct 24, 2023
Jan 5, 2025
Feb 15, 2018
Jun 11, 2024
Nov 22, 2024
Jan 5, 2025
Oct 24, 2023
Jan 5, 2025

Repository files navigation

@oclif/test

test helpers for oclif CLIs

Version Downloads/week License

Migration

See the V4 Migration Guide if you are migrating from v3 or older.

Usage

@oclif/test provides a handful of utilities that make it easy to test your oclif CLI.

Note

In order for these utilities to capture all output to the terminal, you must disable any console output interception/suppression features in your test framework.

captureOutput

captureOutput allows you to get the stdout, stderr, return value, and error of the callback you provide it. This makes it possible to assert that certain strings were printed to stdout and stderr or that the callback failed with the expected error or succeeded with the expected result.

Options

  • print - Print everything that goes to stdout and stderr.
  • stripAnsi - Strip ansi codes from everything that goes to stdout and stderr. Defaults to true.
  • testNodeEnv - Sets the NODE_ENV value when capturing output. Defaults to 'test'.

See the tests for example usage.

runCommand

runCommand allows you to get the stdout, stderr, return value, and error of a command in your CLI.

See the tests for example usage.

runHook

runHook allows you to get the stdout, stderr, return value, and error of a hook in your CLI.

See the tests for example usage.