UNPKG

1.83 kBMarkdownView Raw
1# @oclif/test
2
3test helpers for oclif CLIs
4
5[![Version](https://img.shields.io/npm/v/@oclif/test.svg)](https://npmjs.org/package/@oclif/test)
6[![Downloads/week](https://img.shields.io/npm/dw/@oclif/test.svg)](https://npmjs.org/package/@oclif/test)
7[![License](https://img.shields.io/npm/l/@oclif/test.svg)](https://github.com/oclif/test/blob/main/package.json)
8
9## Migration
10
11See the [V4 Migration Guide](./MIGRATION.md) if you are migrating from v3 or older.
12
13## Usage
14
15`@oclif/test` provides a handful of utilities that make it easy to test your [oclif](https://oclif.io) CLI.
16
17**NOTE for jest users** - in order for these utilities to capture all output to the terminal, you must set `verbose: true` in your jest config to prevent jest from supressing any output. See https://jestjs.io/docs/configuration#verbose-boolean for more
18
19### `captureOutput`
20
21`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.
22
23**Options**
24
25- `print` - Print everything that goes to stdout and stderr.
26- `stripAnsi` - Strip ansi codes from everything that goes to stdout and stderr. Defaults to true.
27- `testNodeEnv` - Sets the `NODE_ENV` value when capturing output. Defaults to `'test'`.
28
29See the [tests](./test/capture-output.test.ts) for example usage.
30
31### `runCommand`
32
33`runCommand` allows you to get the stdout, stderr, return value, and error of a command in your CLI.
34
35See the [tests](./test/run-command.test.ts) for example usage.
36
37### `runHook`
38
39`runHook` allows you to get the stdout, stderr, return value, and error of a hook in your CLI.
40
41See the [tests](./test/run-hook.test.ts) for example usage.