All Projects → saurabhdaware → cli-testing-tool

saurabhdaware / cli-testing-tool

Licence: other
Testing library for cli commands

Programming Languages

javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to cli-testing-tool

testcafe-testing-library
🐂 Simple and complete custom Selectors for Testcafe that encourage good testing practices.
Stars: ✭ 68 (+183.33%)
Mutual labels:  testing-library
clj-concordion
Developer-friendly, simple BDD tests using Clojure and clojure.test, based on Concordion.org
Stars: ✭ 21 (-12.5%)
Mutual labels:  testing-library
Compose
Nice and simple DSL for Espresso Compose UI testing in Kotlin
Stars: ✭ 56 (+133.33%)
Mutual labels:  testing-library
toUUID
Simple integer to UUID generator for unit and integration tests written in Java or Kotlin
Stars: ✭ 12 (-50%)
Mutual labels:  testing-library
Madara
✍️ A way for people to manage their tasks.
Stars: ✭ 17 (-29.17%)
Mutual labels:  testing-library
reactjs-vite-tailwindcss-boilerplate
ReactJS + Vite boilerplate to be used with Tailwindcss.
Stars: ✭ 103 (+329.17%)
Mutual labels:  testing-library
mocat
🐈 Mocat is a mocking toolbar that allows you to interactively develop and test network requests.
Stars: ✭ 27 (+12.5%)
Mutual labels:  testing-library
Truth
Fluent assertions for Java and Android
Stars: ✭ 2,359 (+9729.17%)
Mutual labels:  testing-library
api-test
🌿 A simple bash script to test JSON API from terminal in a structured and organized way.
Stars: ✭ 53 (+120.83%)
Mutual labels:  testing-library
playwright-fluent
Fluent API around playwright
Stars: ✭ 71 (+195.83%)
Mutual labels:  testing-library
eslint-config-welly
😎 ⚙️ ESLint configuration for React projects that I do. Feel free to use this!
Stars: ✭ 21 (-12.5%)
Mutual labels:  testing-library
test-real-styles
(test-)framework agnostic utilities to test real styling of (virtual) dom elements
Stars: ✭ 37 (+54.17%)
Mutual labels:  testing-library
react-atdd-playground
Template to (deliberate) practice your test-driven development skills.
Stars: ✭ 14 (-41.67%)
Mutual labels:  testing-library
scalatest-junit-runner
JUnit 5 runner for Scalatest
Stars: ✭ 30 (+25%)
Mutual labels:  testing-library
React Hooks Testing Library
🐏 Simple and complete React hooks testing utilities that encourage good testing practices.
Stars: ✭ 4,146 (+17175%)
Mutual labels:  testing-library
picolisp-unit
Unit Testing framework for PicoLisp
Stars: ✭ 22 (-8.33%)
Mutual labels:  testing-library
playwright-testing-library
🔍 Find elements in Playwright with queries from Testing Library
Stars: ✭ 160 (+566.67%)
Mutual labels:  testing-library
Jest Dom
🦉 Custom jest matchers to test the state of the DOM
Stars: ✭ 2,908 (+12016.67%)
Mutual labels:  testing-library
Terratest
Terratest is a Go library that makes it easier to write automated tests for your infrastructure code.
Stars: ✭ 5,797 (+24054.17%)
Mutual labels:  testing-library
robotframework-imagehorizonlibrary
Cross-platform Robot Framework library for GUI automation based on image recognition
Stars: ✭ 67 (+179.17%)
Mutual labels:  testing-library

CLI Testing Tool

A testing library that allows you to test input and outputs of your CLI command.

Note: This is WIP but it should be ready enough for most common CLI use-cases I can think of

Installation

With NPM:

npm install --save-dev cli-testing-tool 

With Yarn:

yarn add --dev cli-testing-tool

Examples

Check out Interactive Examples on Stackblitz

Testing Colored Terminal Text

Check out this example of StackBlitz

// colored-greeting.test.js
const { createCommandInterface } = require('cli-testing-tool');

test('should print colored greetings', async () => {
  const commandInterface = createCommandInterface('node ./graphic-print.js', {
    cwd: __dirname, // considering, the test file is in the same directory as the cli file
  });
  await commandInterface.type('Saurabh\n');
  const terminal = await commandInterface.getOutput();

  // ANSI Escape codes are tokenized into readable text token in tokenizedOutput
  // Helpful when libraries like inquirer or prompts add ansi-escape codes.
  expect(terminal.tokenizedOutput).toBe(
    "What's your name?Hi, [BOLD_START][RED_START]Saurabh[COLOR_END][BOLD_END]!"
  );

  // ANSI Escape codes are not tokenized.
  expect(terminal.rawOutput).toBe(
    `What's your name?Hi, \x1B[1m\x1B[31mSaurabh\x1B[39m\x1B[22m!`
  );

  // ANSI Escape codes are removed
  expect(terminal.stringOutput).toBe(`What's your name?Hi, Saurabh!`);
});
Code of the CLI that we're testing in above snippet
// colored-greeting.js
const readline = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

const bold = (str) => `\x1b[1m${str}\x1b[22m`;
const red = (str) => `\x1b[31m${str}\x1b[39m`;

readline.question(`What's your name?`, (name) => {
  console.log(`Hi, ${bold(red('Saurabh'))}!`);
  readline.close();
});

Options

You can pass options as 2nd param to createCommandInterface.

The default options are:

const defaultOptions = {
  typeDelay: 100, // number. delay between each `.type()` call
  logData: false, // boolean. if true, logs the command data on terminal
  logError: true, // boolean. if false, won't add command errors on terminal
  cwd: process.cwd(), // string. working directory from where your simulated command is executed
  env: undefined // object | undefined. environment variables object if there are any
};

Terminal Text Parsing Support Checklist

Refer to Full List of Ansi Escape Codes that need to be handled.

  • Normal text without ansi escape codes
  • Colored text
  • Cursor movement (Basic Support. Not tested)
  • Erase Line/Screen Clear (Basic Support. Not tested)
  • Screen Modes (No Support)
  • Private Modes (No Support)
  • Multiple Arguments (No Support. Difficult to support this)

Big Shoutout to

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].