# @oclif/test

> test helpers for oclif components

Latest version **5.0.0** (published 2026-08-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install @oclif/test
pnpm add @oclif/test
yarn add @oclif/test
bun add @oclif/test
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 5.0.0 |
| Published | 2026-08-31 |
| First published | 2018-02-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=22.0.0 |
| Dependencies | 2 |
| Unpacked size | 13.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 23 |
| Author | Salesforce |
| Maintainers | anycli-bot, jimjag, salesforce-releases |
| Keywords | oclif |

## Links

- npm: https://www.npmjs.com/package/@oclif/test
- Repository: https://github.com/oclif/test
- Issues: https://github.com/oclif/test/issues
- npm.io page: https://npm.io/package/@oclif/test

## Dependencies (2)

- [ansis](https://npm.io/package/ansis.md) ^3.17.0
- [debug](https://npm.io/package/debug.md) ^4.4.3

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 5.0.0 (latest) — 2026-08-31
- 4.0.1-beta.4 (beta) — 2024-05-17
- 4.0.1-dev.0 (dev) — 2024-05-15
- 4.2.0 — 2026-08-24
- 4.1.22 — 2026-08-09
- 4.1.21 — 2026-07-26
- 4.1.20 — 2026-06-21
- 4.1.19 — 2026-06-13
- 4.1.18 — 2026-04-05
- 4.1.17 — 2026-03-21
- 4.1.16 — 2026-01-22
- 4.1.15 — 2025-11-15
- 4.1.14 — 2025-09-14
- 4.1.13 — 2025-05-18
- 4.1.12 — 2025-03-09
- … 166 more at https://npm.io/package/@oclif/test/versions

## README

# @oclif/test

test helpers for oclif CLIs

[![Version](https://img.shields.io/npm/v/@oclif/test.svg)](https://npmjs.org/package/@oclif/test)
[![Downloads/week](https://img.shields.io/npm/dw/@oclif/test.svg)](https://npmjs.org/package/@oclif/test)
[![License](https://img.shields.io/npm/l/@oclif/test.svg)](https://github.com/oclif/test/blob/main/package.json)

## Migration

See the [V4 Migration Guide](./MIGRATION.md) if you are migrating from v3 or older.

## Usage

`@oclif/test` provides a handful of utilities that make it easy to test your [oclif](https://oclif.io) 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.
>
> - For Jest users, enable [the `verbose` flag](https://jestjs.io/docs/configuration#verbose-boolean) in your Jest config.
> - For Vitest users, enable [the `disableConsoleIntercept` flag](https://vitest.dev/guide/cli.html#disableconsoleintercept) in your Vitest config.

### `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](./test/capture-output.test.ts) 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](./test/run-command.test.ts) 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](./test/run-hook.test.ts) for example usage.

---
_Source: https://npm.io/package/@oclif/test · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
