Skip to content

Latest commit

History

History
70 lines (52 loc) 路 2.91 KB

introduction.md

File metadata and controls

70 lines (52 loc) 路 2.91 KB

CLI Testing Library

CLI Testing Library implements as-close-as-possible API to DOM Testing Library and React Testing Library, but for E2E CLI tests instead.

npm install --save-dev cli-testing-library

Table of Contents

The problem

You want to write maintainable tests for your CLI applications. As a part of this goal, you want your tests to avoid including implementation details of your CLI and rather focus on making your tests give you the confidence for which they are intended. As part of this, you want your testbase to be maintainable in the long run so refactors of your CLI (changes to implementation but not functionality) don't break your tests and slow you and your team down.

This solution

The CLI Testing Library is a very light-weight solution for testing CLI applications (whether written in NodeJS or not). The main utilities it provides involve querying stdout in a way that's similar to how a user interacts with CLI. In this way, the library helps ensure your tests give you confidence in your UI code. The CLI Testing Library's primary guiding principle is:

The more your tests resemble the way your software is used, the more confidence they can give you.

As part of this goal, the utilities this library provides facilitate querying the CLI in the same way the user would. Finding text output with readable text, as opposed to ansi escapes interrupting (just like a user would focus on), sending keyboard events (like a user would), and more.

This library encourages your applications to be more robust with user input and allows you to get your tests closer to using your command line the way a user will, which allows your tests to give you more confidence that your application will work when a real user uses it.

What this library is not:

  1. A test runner or framework
  2. Specific to a testing framework (though we recommend Jest as our preference, the library works with any framework.)

Further Reading