inquirer-test

2.0.1 • Public • Published

inquirer-test

Build Status

Functional testing for inquirer.js

Could be use to test output of commands with regexs or side effects from running a script.

E.g. with project generators you provide a combinations of control keys and text inputs and ensure that files are generated with fs or other modules.

Install

$ npm install inquirer-test --save-dev

Usage

// cli.js
 
const inquirer = require('inquirer');
const outputs = ['TEST-1', 'TEST-2', 'TEST-3'];
 
inquirer.prompt({
  type: 'list',
  name: 'q',
  message: 'hi',
  choices: [ '1', '2', '3' ]
}).then(function(answers) {
  console.log(outputs[+answers.q - 1]);
});
// test.js
 
import test from 'ava';
import run, { UP, DOWN, ENTER } from 'inquirer-test';
 
const cliPath = __dirname + '/cli.js';
 
test('press enter', async t => {
  const result = await run([cliPath], [ENTER]);
  t.regex(result, new RegExp('TEST-1', 'g'));
});
 
test('press down, press enter', async t => {
  const result = await run([cliPath], [DOWN, ENTER]);
  t.regex(result, new RegExp('TEST-2', 'g'));
});
 
test('press up, press enter', async t => {
  const result = await run([cliPath], [UP, ENTER]);
  t.regex(result, new RegExp('TEST-3', 'g'));
});
 
test('press press up, press down, press enter', async t => {
  const result = await run([cliPath], [UP, DOWN, ENTER]);
  t.regex(result, new RegExp('TEST-1', 'g'));
});
 
test('run with data input', async t => {
  const result = await run([cliPath], ['input-1', ENTER, 'input-2', ENTER]);
  t.regex(result, new RegExp("username: 'input-1', password: 'input-2'", 'g'));
});

Changelog

  • v2.0.0
    • change cliPath to child_process arguments array
    • update to inquirer@4

Related

License

MIT © ewnd9

Package Sidebar

Install

npm i inquirer-test

Weekly Downloads

922

Version

2.0.1

License

MIT

Last publish

Collaborators

  • ewnd9