Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@oclif/test

oclif677kMIT4.1.8TypeScript support: included

test helpers for oclif components

oclif

readme

@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.

changelog

4.1.8 (2025-01-19)

Bug Fixes

  • deps: bump ansis from 3.8.1 to 3.9.0 (e37e418)

4.1.7 (2025-01-12)

Bug Fixes

  • deps: bump ansis from 3.6.0 to 3.8.1 (92bfe18)

4.1.6 (2025-01-05)

Bug Fixes

  • deps: bump ansis from 3.5.2 to 3.6.0 (777c61b)

4.1.5 (2024-12-29)

Bug Fixes

  • deps: bump ansis from 3.4.0 to 3.5.2 (4a4cf09)

4.1.4 (2024-12-16)

Bug Fixes

  • deps: bump ansis from 3.3.2 to 3.4.0 (1b13bfc)

4.1.3 (2024-12-08)

Bug Fixes

  • deps: bump debug from 4.3.7 to 4.4.0 (83482a8)

4.1.2 (2024-11-18)

Bug Fixes

  • don't destructure error object (2190a61)

4.1.1 (2024-11-17)

Bug Fixes

  • deps: bump cross-spawn from 7.0.3 to 7.0.5 (3ec4e0a)

4.1.0 (2024-10-17)

Features

  • add ability to override NODE_ENV (02a5708)

4.0.10 (2024-10-16)

Bug Fixes

  • optional chaining to prevent type error (cdf8f44)

4.0.9 (2024-08-25)

Bug Fixes

  • deps: bump micromatch from 4.0.7 to 4.0.8 (3a982f4)

4.0.8 (2024-08-04)

Bug Fixes

  • deps: bump ansis from 3.3.1 to 3.3.2 (c839b7a)

4.0.7 (2024-07-29)

Bug Fixes

  • deps: bump debug from 4.3.5 to 4.3.6 (438e6d1)

4.0.6 (2024-07-23)

Bug Fixes

4.0.5 (2024-07-21)

Bug Fixes

  • deps: bump ansis from 3.2.1 to 3.3.1 (a67d317)

4.0.4 (2024-06-13)

Bug Fixes

  • deps: bump braces from 3.0.2 to 3.0.3 (2db9360)

4.0.3 (2024-06-02)

Bug Fixes

  • deps: bump debug from 4.3.4 to 4.3.5 (69b15de)

4.0.2 (2024-05-22)

Bug Fixes

  • preserve quotes in inputs to runCommand (2fad42a)

4.0.1 (2024-05-21)

3.2.15 (2024-05-12)

Bug Fixes

  • deps: bump fancy-test from 3.0.14 to 3.0.15 (8b75374)

3.2.14 (2024-05-12)

Bug Fixes

  • deps: bump @oclif/core from 3.26.5 to 3.26.6 (b0be7fa)

3.2.13 (2024-05-05)

Bug Fixes

  • deps: bump @oclif/core from 3.26.4 to 3.26.5 (16d503a)

3.2.12 (2024-05-02)

3.2.12-dev.0 (2024-04-30)

Bug Fixes

  • use require.cache to resolve root (40387ad)

3.2.11 (2024-04-21)

Bug Fixes

  • deps: bump @oclif/core from 3.26.3 to 3.26.4 (53b6073)

3.2.10 (2024-04-14)

Bug Fixes

  • deps: bump @oclif/core from 3.26.0 to 3.26.3 (174cd88)

3.2.9 (2024-04-10)

Bug Fixes

  • restore support for single command cli test (30cf43f)

3.2.8 (2024-03-25)

Bug Fixes

  • deps: bump fancy-test from 3.0.13 to 3.0.14 (b357da8)

3.2.7 (2024-03-24)

Bug Fixes

  • deps: bump @oclif/core from 3.25.2 to 3.26.0 (65e41f8)

3.2.6 (2024-03-17)

Bug Fixes

  • deps: bump @oclif/core from 3.23.0 to 3.25.2 (4fada36)

3.2.5 (2024-03-11)

Bug Fixes

3.2.3 (2024-03-10)

Bug Fixes

  • deps: bump fancy-test from 3.0.11 to 3.0.12 (ba75072)

3.2.2 (2024-03-10)

Bug Fixes

  • deps: bump @oclif/core from 3.19.2 to 3.23.0 (1dbcf4e)

3.2.1 (2024-02-25)

Bug Fixes

  • deps: bump fancy-test from 3.0.10 to 3.0.11 (55c6e27)

3.2.0 (2024-02-20)

Features

  • support identifying other root types (2011cc1)

3.1.17 (2024-02-18)

Bug Fixes

  • deps: bump @oclif/core from 3.19.1 to 3.19.2 (799f80d)

3.1.16 (2024-02-11)

Bug Fixes

  • deps: bump @oclif/core from 3.18.2 to 3.19.1 (19e04cd)

3.1.15 (2024-02-11)

Bug Fixes

  • deps: bump fancy-test from 3.0.9 to 3.0.10 (7b63e28)

3.1.14 (2024-02-04)

Bug Fixes

  • deps: bump @oclif/core from 3.18.1 to 3.18.2 (ed894dc)

3.1.13 (2024-01-28)

Bug Fixes

  • deps: bump fancy-test from 3.0.8 to 3.0.9 (3d330ab)

3.1.12 (2024-01-14)

Bug Fixes

  • deps: bump chai from 4.4.0 to 4.4.1 (3f2cf0f)

3.1.11 (2024-01-14)

Bug Fixes

  • deps: bump @oclif/core from 3.16.0 to 3.18.1 (7213f2f)

3.1.10 (2024-01-08)

Bug Fixes

  • deps: bump chai from 4.3.10 to 4.4.0 (3fbea43)

3.1.9 (2024-01-07)

Bug Fixes

  • deps: bump @oclif/core from 3.15.1 to 3.16.0 (015289e)

3.1.8 (2023-12-31)

Bug Fixes

  • deps: bump fancy-test from 3.0.7 to 3.0.8 (1ac190d)

3.1.7 (2023-12-24)

Bug Fixes

  • deps: bump fancy-test from 3.0.4 to 3.0.7 (1540704)

3.1.6 (2023-12-24)

Bug Fixes

  • deps: bump @oclif/core from 3.15.0 to 3.15.1 (af37fd7)

3.1.5 (2023-12-18)

Bug Fixes

  • deps: bump @oclif/core from 3.12.0 to 3.15.0 (2c0f96a)

3.1.4 (2023-12-17)

Bug Fixes

  • deps: bump fancy-test from 3.0.1 to 3.0.4 (d47280d)

3.1.3 (2023-11-27)

Bug Fixes

  • deps: bump @oclif/core from 3.10.8 to 3.12.0 (a87acdd)

3.1.2 (2023-11-12)

Bug Fixes

  • deps: bump @oclif/core from 3.10.1 to 3.10.8 (a45581c)

3.1.1 (2023-11-05)

Bug Fixes

  • deps: bump @oclif/core from 3.9.1 to 3.10.1 (784067a)

3.1.0 (2023-11-01)

Features

3.0.4 (2023-10-29)

Bug Fixes

  • deps: bump @oclif/core from 3.6.0 to 3.9.1 (e86aa62)

3.0.3 (2023-10-24)

Bug Fixes

3.0.2 (2023-10-01)

Bug Fixes

  • deps: bump @oclif/core from 3.0.0-beta.17 to 3.0.0-beta.19 (70e6e0e)

3.0.1 (2023-09-28)

Bug Fixes

3.0.0 (2023-09-28)

BREAKING CHANGES

  • node 18+, fancy-test v3

  • chore: update github workflows

  • chore(release): 2.5.7-beta.0 [skip ci]

  • chore: major version bump

  • chore(release): 3.0.0-beta.1 [skip ci]

  • chore: pass token to automerge

  • chore: bump chai to resolve dependabot vuln

2.5.6 (2023-09-24)

Bug Fixes

  • deps: bump fancy-test from 2.0.41 to 2.0.42 (744d668)

2.5.5 (2023-09-17)

Bug Fixes

  • deps: bump fancy-test from 2.0.38 to 2.0.41 (135d45a)

2.5.4 (2023-09-10)

Bug Fixes

  • deps: bump fancy-test from 2.0.37 to 2.0.38 (fe004f4)

2.5.3 (2023-09-03)

Bug Fixes

  • deps: bump @oclif/core from 2.11.10 to 2.15.0 (ef1b12b)

2.5.2 (2023-09-03)

Bug Fixes

  • deps: bump fancy-test from 2.0.35 to 2.0.37 (d7658ea)

2.5.1 (2023-08-31)

Reverts

  • Revert "feat: use core v3" (bd267ec)

2.5.0 (2023-08-31)

Features

2.4.8 (2023-08-27)

Bug Fixes

  • deps: bump fancy-test from 2.0.34 to 2.0.35 (17470b7)

2.4.7 (2023-08-23)

Bug Fixes

2.4.6 (2023-08-20)

Bug Fixes

  • deps: bump fancy-test from 2.0.33 to 2.0.34 (11ff53e)

2.4.5 (2023-08-13)

Bug Fixes

  • deps: bump @oclif/core from 2.11.7 to 2.11.8 (43dbecf)

2.4.4 (2023-08-06)

Bug Fixes

  • deps: bump fancy-test from 2.0.32 to 2.0.33 (b01e21c)

2.4.3 (2023-08-06)

Bug Fixes

  • deps: bump @oclif/core from 2.11.1 to 2.11.7 (f0bb8aa)

2.4.2 (2023-07-30)

Bug Fixes

  • deps: bump fancy-test from 2.0.31 to 2.0.32 (1537d72)

2.4.1 (2023-07-30)

Bug Fixes

  • deps: bump @oclif/core from 2.9.4 to 2.11.1 (c16c4fe)

2.4.0 (2023-07-26)

Features

  • remove deprecated module.parent (ca06eef)

2.3.33 (2023-07-23)

Bug Fixes

  • deps: bump @oclif/core from 2.9.3 to 2.9.4 (380e399)

2.3.32 (2023-07-23)

Bug Fixes

  • deps: bump fancy-test from 2.0.29 to 2.0.31 (0788750)

2.3.31 (2023-07-19)

Bug Fixes

  • deps: bump word-wrap from 1.2.3 to 1.2.4 (be67828)

2.3.30 (2023-07-16)

Bug Fixes

  • deps: bump fancy-test from 2.0.28 to 2.0.29 (3c63e31)

2.3.29 (2023-07-16)

Bug Fixes

  • deps: bump @oclif/core from 2.8.11 to 2.9.3 (e7aea4a)

2.3.28 (2023-07-11)

Bug Fixes

  • deps: bump semver from 5.7.1 to 5.7.2 (c6dcf30)

2.3.27 (2023-07-09)

Bug Fixes

  • deps: bump fancy-test from 2.0.27 to 2.0.28 (de706d1)

2.3.26 (2023-07-02)

Bug Fixes

  • deps: bump @oclif/core from 2.8.7 to 2.8.11 (6386563)

2.3.25 (2023-06-25)

Bug Fixes

  • deps: bump fancy-test from 2.0.26 to 2.0.27 (6ac3083)

2.3.24 (2023-06-18)

Bug Fixes

  • deps: bump @oclif/core from 2.8.5 to 2.8.7 (124c602)

2.3.23 (2023-06-18)

Bug Fixes

  • deps: bump fancy-test from 2.0.25 to 2.0.26 (b65750c)

2.3.22 (2023-06-04)

Bug Fixes

  • deps: bump fancy-test from 2.0.23 to 2.0.25 (7c974cf)

2.3.21 (2023-05-21)

Bug Fixes

  • deps: bump fancy-test from 2.0.22 to 2.0.23 (eb80d40)

2.3.20 (2023-05-14)

Bug Fixes

  • deps: bump fancy-test from 2.0.21 to 2.0.22 (d5b2b00)

2.3.19 (2023-05-07)

Bug Fixes

  • deps: bump @oclif/core from 2.8.2 to 2.8.5 (885d28b)

2.3.18 (2023-05-07)

Bug Fixes

  • deps: bump fancy-test from 2.0.19 to 2.0.21 (48f19ca)

2.3.17 (2023-04-23)

Bug Fixes

  • deps: bump fancy-test from 2.0.18 to 2.0.19 (ac7c6d8)

2.3.16 (2023-04-16)

Bug Fixes

  • deps: bump @oclif/core from 2.8.0 to 2.8.2 (04e4585)

2.3.15 (2023-04-09)

Bug Fixes

  • deps: bump fancy-test from 2.0.16 to 2.0.18 (6941d98)

2.3.14 (2023-04-02)

Bug Fixes

  • deps: bump @oclif/core from 2.7.1 to 2.8.0 (2ddd74e)

2.3.13 (2023-03-26)

Bug Fixes

  • deps: bump fancy-test from 2.0.13 to 2.0.16 (e645dc3)

2.3.12 (2023-03-26)

Bug Fixes

  • deps: bump @oclif/core from 2.6.4 to 2.7.1 (30dd866)

2.3.11 (2023-03-19)

Bug Fixes

  • deps: bump @oclif/core from 2.6.2 to 2.6.4 (9259dfe)

2.3.10 (2023-03-09)

Bug Fixes

  • bump core to pick up config changes (b124aed)

2.3.9 (2023-03-05)

Bug Fixes

  • deps: bump @oclif/core from 2.3.1 to 2.4.0 (0083a04)

2.3.8 (2023-02-26)

Bug Fixes

  • deps: bump @oclif/core from 2.1.7 to 2.3.1 (afa8139)

2.3.7 (2023-02-19)

Bug Fixes

  • deps: bump @oclif/core from 2.1.2 to 2.1.7 (048d529)

2.3.6 (2023-02-12)

Bug Fixes

  • deps: bump @oclif/core from 2.0.8 to 2.1.2 (d8d2948)

2.3.5 (2023-02-05)

Bug Fixes

  • deps: bump @oclif/core from 2.0.7 to 2.0.8 (e27dc06)

2.3.4 (2023-01-29)

Bug Fixes

  • deps: bump @oclif/core from 2.0.3 to 2.0.7 (4a8e91f)

2.3.3 (2023-01-23)

Bug Fixes

2.3.2 (2023-01-22)

Bug Fixes

  • deps: bump fancy-test from 2.0.11 to 2.0.12 (239ebbb)

2.3.1 (2023-01-22)

Bug Fixes

  • deps: bump @oclif/core from 2.0.2-beta.6 to 2.0.2-beta.10 (b5b4aa4)

2.3.0 (2023-01-18)

Features

2.2.21 (2023-01-15)

Bug Fixes

  • deps: bump @oclif/core from 1.23.1 to 1.24.0 (f4b16e4)

2.2.20 (2023-01-08)

Bug Fixes

  • deps: bump fancy-test from 2.0.10 to 2.0.11 (31c8b88)

2.2.19 (2023-01-01)

Bug Fixes

  • deps: bump json5 from 2.2.0 to 2.2.3 (345eae8)

2.2.18 (2023-01-01)

Bug Fixes

  • deps: bump @oclif/core from 1.22.0 to 1.23.1 (b8132cf)

2.2.17 (2022-12-25)

Bug Fixes

  • deps: bump fancy-test from 2.0.9 to 2.0.10 (4d4ad6b)

2.2.16 (2022-12-18)

Bug Fixes

  • deps: bump @oclif/core from 1.21.0 to 1.22.0 (58e256d)

2.2.15 (2022-12-11)

Bug Fixes

  • deps: bump @oclif/core from 1.20.4 to 1.21.0 (17f54a1)

2.2.14 (2022-12-11)

Bug Fixes

  • deps: bump fancy-test from 2.0.7 to 2.0.9 (291336b)

2.2.13 (2022-12-04)

Bug Fixes

  • deps: bump minimatch from 3.0.4 to 3.1.2 (05f5417)

2.2.12 (2022-11-20)

Bug Fixes

  • deps: bump fancy-test from 2.0.6 to 2.0.7 (839c532)

2.2.11 (2022-11-20)

Bug Fixes

  • deps: bump @oclif/core from 1.20.3 to 1.20.4 (b033347)

2.2.10 (2022-11-06)

Bug Fixes

  • deps: bump @oclif/core from 1.20.0 to 1.20.3 (3686a0a)

2.2.9 (2022-11-06)

Bug Fixes

  • deps: bump fancy-test from 2.0.5 to 2.0.6 (d9bcd90)

2.2.8 (2022-10-30)

Bug Fixes

  • deps: bump @oclif/core from 1.19.1 to 1.20.0 (94591ce)

2.2.7 (2022-10-30)

Bug Fixes

  • deps: bump minimist from 1.2.5 to 1.2.7 (cf359e1)

2.2.6 (2022-10-23)

Bug Fixes

  • deps: bump @oclif/core from 1.18.0 to 1.19.1 (d8376ce)

2.2.5 (2022-10-23)

Bug Fixes

  • deps: bump fancy-test from 2.0.4 to 2.0.5 (25af47e)

2.2.4 (2022-10-16)

Bug Fixes

  • deps: bump @oclif/core from 1.16.5 to 1.18.0 (a2688d6)

2.2.3 (2022-10-09)

Bug Fixes

  • deps: bump @oclif/core from 1.16.4 to 1.16.5 (c56beb0)

2.2.2 (2022-10-02)

Bug Fixes

  • deps: bump fancy-test from 2.0.2 to 2.0.4 (443a9dd)

2.2.1 (2022-10-01)

Bug Fixes

  • deps: bump fancy-test from 2.0.0 to 2.0.2 (9ad498f)

2.2.0 (2022-09-27)

Features

  • add return value to hooks and commands (86a6490)

2.1.2 (2022-09-27)

Bug Fixes

  • deps: bump @oclif/core from 1.6.4 to 1.16.4 (5eef49d)

2.1.1 (2022-08-09)

Bug Fixes

2.1.0 (2022-02-10)

Features

  • support commands with spaces (531f8e0)

2.0.3 (2021-12-08)

Bug Fixes

2.0.2 (2021-12-02)

Bug Fixes

  • update package to v2 minimums (52115cf)

2.0.1 (2021-10-04)

Bug Fixes

1.2.8 (2020-12-02)

Bug Fixes

  • deps: bump fancy-test from 1.4.9 to 1.4.10 (#126) (132c914)

1.2.7 (2020-09-01)

Bug Fixes

  • deps-dev: bump eslint from 7.7.0 to 7.8.0 (#111) (2d81e06)

1.2.6 (2020-05-15)

1.2.5 (2019-08-02)

1.2.4 (2019-02-11)

1.2.3 (2019-02-11)

Bug Fixes

1.2.2 (2018-10-13)

Bug Fixes

  • remove greenkeeper badge (35730ff)

1.2.1 (2018-09-14)

Bug Fixes

  • require arguments to hook and command (38982b5)

1.2.0 (2018-08-17)

Features

1.1.0 (2018-06-14)

Features

1.0.9 (2018-06-01)

Bug Fixes

1.0.8 (2018-06-01)

Bug Fixes

1.0.7 (2018-06-01)

Bug Fixes

1.0.6 (2018-05-01)

Bug Fixes

1.0.5 (2018-04-18)

Bug Fixes

1.0.4 (2018-04-06)

Bug Fixes

1.0.3 (2018-04-06)

Bug Fixes

1.0.2 (2018-04-06)

Bug Fixes

1.0.1 (2018-02-13)

Bug Fixes

1.0.0 (2018-02-13)

Bug Fixes

0.10.16 (2018-02-13)

Bug Fixes

0.10.15 (2018-02-07)

Bug Fixes

0.10.14 (2018-02-07)

Bug Fixes

0.10.13 (2018-02-07)

Bug Fixes

0.10.12 (2018-02-07)

Bug Fixes

0.10.11 (2018-02-05)

Bug Fixes

  • updated with config/command changes (e807e19)

0.10.10 (2018-02-05)

Bug Fixes

0.10.9 (2018-02-03)

Bug Fixes

  • put reset flag on loadConfig (6979084)

0.10.8 (2018-02-03)

Bug Fixes

0.10.7 (2018-02-03)

Bug Fixes

0.10.6 (2018-02-03)

Bug Fixes

  • fixed loadConfig with hooks (54303a0)

0.10.5 (2018-02-03)

Bug Fixes

  • updated to work with new config/command (fa184da)

0.10.4 (2018-02-02)

Bug Fixes

0.10.3 (2018-02-02)

Bug Fixes

0.10.2 (2018-02-01)

Bug Fixes

0.10.1 (2018-02-01)

Bug Fixes

0.10.0 (2018-01-31)

Features

0.9.20 (2018-01-31)

Bug Fixes

0.9.19 (2018-01-29)

Bug Fixes

0.9.18 (2018-01-28)

Bug Fixes

0.9.17 (2018-01-28)

Bug Fixes

0.9.16 (2018-01-28)

Bug Fixes

0.9.15 (2018-01-28)

Bug Fixes

0.9.14 (2018-01-28)

Bug Fixes

0.9.13 (2018-01-28)

Bug Fixes

Features

0.9.12 (2018-01-27)

Bug Fixes

0.9.11 (2018-01-27)

Bug Fixes

  • move everything to devDependencies to use @dxcli/dev instead (d800eb1)

0.9.10 (2018-01-27)

Bug Fixes

0.9.9 (2018-01-27)

Bug Fixes

0.9.8 (2018-01-26)

Bug Fixes

0.9.7 (2018-01-26)

Bug Fixes

0.9.6 (2018-01-26)

Bug Fixes

0.9.5 (2018-01-26)

Bug Fixes

0.9.4 (2018-01-26)

Bug Fixes

0.9.3 (2018-01-26)

Bug Fixes

0.9.2 (2018-01-25)

Bug Fixes

0.9.1 (2018-01-25)

Bug Fixes

0.9.0 (2018-01-25)

Features

0.8.0 (2018-01-21)

Features

0.7.0 (2018-01-20)

Features

  • added error to hook callback (036ec31)

0.6.1 (2018-01-20)

Bug Fixes

  • better exit error handling (5b214ad)

0.6.0 (2018-01-20)

Features

  • added testHook callback (e5f9a87)

0.5.2 (2018-01-20)

Bug Fixes

0.5.1 (2018-01-20)

Bug Fixes

0.5.0 (2018-01-20)

Features

  • added testCommand callback (016ca5e)

0.4.4 (2018-01-20)

Bug Fixes

0.4.3 (2018-01-20)

Bug Fixes

0.4.2 (2018-01-20)

Bug Fixes

0.4.1 (2018-01-20)

Bug Fixes

0.4.0 (2018-01-20)

Features

0.3.0 (2018-01-20)

Features

0.2.2 (2018-01-19)

Bug Fixes

0.2.1 (2018-01-16)

Bug Fixes

  • flush stdmock after tests (6384b05)

0.2.0 (2018-01-16)

Features

0.1.2 (2018-01-16)

Bug Fixes

  • fixed it before/after filters (98bf3a1)

0.1.1 (2018-01-16)

Bug Fixes

0.1.0 (2018-01-15)

Features

  • added mock and improved std mocking (d0c1e97)

0.0.1 (2018-01-13)

Bug Fixes

  • add @dxcli/dev-nyc-config (1994d4b)
  • add mocha-junit-reporter (1055f1b)