npm

Bring the best of OSS JavaScript development to your projects with npm Orgs - private packages & team management tools.Learn more »

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

install

npm i inquirer-test

Downloadsweekly downloads

88

version

2.0.1

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability