1 | # @oclif/test
|
2 |
|
3 | test 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 |
|
11 | See 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 | ### `captureOutput`
|
18 |
|
19 | `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.
|
20 |
|
21 | **Options**
|
22 |
|
23 | - `print` - Print everything that goes to stdout and stderr.
|
24 | - `stripAnsi` - Strip ansi codes from everything that goes to stdout and stderr. Defaults to true.
|
25 |
|
26 | See the [tests](./test/capture-output.test.ts) for example usage.
|
27 |
|
28 | ### `runCommand`
|
29 |
|
30 | `runCommand` allows you to get the stdout, stderr, return value, and error of a command in your CLI.
|
31 |
|
32 | See the [tests](./test/run-command.test.ts) for example usage.
|
33 |
|
34 | ### `runHook`
|
35 |
|
36 | `runHook` allows you to get the stdout, stderr, return value, and error of a hook in your CLI.
|
37 |
|
38 | See the [tests](./test/run-hook.test.ts) for example usage.
|