Skip to content

Commit

Permalink
Add unit tests for shell-completion
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndrsn committed Jun 5, 2017
1 parent 019a21f commit 49c2e80
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/bin/shell-completion.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const assert = require('chai').assert;

describe('shell-completion', () => {

it('should supply --XXX options if initial dash is provided', () => {

// expect
return assertShellComplete('-',
'--help',
'--shell-completion',
'--supported-actions',
'--version');

});

it('should supply http... option if entering second word', () => {

// expect
return assertShellComplete(['some-project', ''],
'http\\://',
'https\\://');
});

});

const execSync = require('child_process').execSync;

function assertShellComplete(cliArgs, ...expectedResponses) {
if(!Array.isArray(cliArgs)) cliArgs = [ cliArgs ];

return execPromise('bin/shell-completion.js', cliArgs.length, ...cliArgs)
.then(res => res.split(/\s/))
.then(res => res.filter(s => s.trim()))
.then(res => assert.deepEqual(res, expectedResponses));
}

function execPromise(...args) {
try {
var buf = execSync(args.join(' '));
return Promise.resolve(buf.toString());
} catch(e) {
return Promise.reject(e);
}
}

0 comments on commit 49c2e80

Please sign in to comment.