Lean promisified wrapper to test NodeJS CLI scripts
npm install cli-tester





Lean promisified wrapper to test NodeJS CLI scripts
Plays nicely with blue-tape
``sh`
npm install --save-dev cli-tester
`js
const test = require('blue-tape');
const tester = require('cli-tester');
test('Successful run', t =>
tester(require.resolve('./cli-that-is-ok'))
.then(({code, stdout, stderr}) => {
t.equal(code, 0, 'should exit with code 0');
t.equal(stdout, 'check expected output');
t.equal(stderr, '', 'should not have any errors');
}));
test('CLI throws', t =>
tester(require.resolve('./cli-that-throws'))
.then(({code, stdout, stderr}) => {
t.equal(code, 1, 'should exit with code 1');
t.equal(stdout, '', 'should not have any output');
t.ok(stderr.match('some error from CLI'));
}));
`
`js`
const tester = require('cli-tester/es5');
`js`
tester(cli, env, ...args)
Returns ES6 Promise, that is always successful
Resolved path to JS CLI, ideally absolute path
`js`
tester(require.resolve('./cli'))
Object with ENV vars
`js`
tester(require.resolve('./cli'), {OMG: 'OMG!'})
List of command line arguments
`js
// With omitted ENV
tester(require.resolve('./cli'), '--hello', 'world')
// With ENV
tester(require.resolve('./cli'), {OMG: 'OMG!'},'--hello', 'world')
`
Currently is being developed and tested with the latest stable Node 7 under OSX and Windows.
`bash`
git clone git@github.com:nkbt/cli-tester.git
cd cli-tester
npm install
`bashto run tests
npm test
MIT