Skip to content

Commit

Permalink
test: use content event to get content instead of monkeypatching console
Browse files Browse the repository at this point in the history
  • Loading branch information
esatterwhite committed Dec 26, 2017
1 parent 66e5e33 commit 8ee6f0e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
6 changes: 3 additions & 3 deletions lib/commands/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ var os = require('os')
*/
var Help = new Command({
description:"displays information about available commands"
,interactive:false
,alias:['hlep']
,run: async function(cmd, data){
, interactive:false
, alias:['hlep']
, run: async function(cmd, data){
var commands
, cls
, instance
Expand Down
8 changes: 4 additions & 4 deletions test/command.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ test('command', function(t){
" <...>: input type | *: repeatable flags | [...]: default values"
].join(os.EOL );

ttt.equal(out.trim(), strip( UsageCommand.usage ).trim() );
ttt.equal(strip( UsageCommand.usage ).trim(), out.trim() );

commands.register('usage', UsageCommand)
Help.removeAllListeners()
Expand All @@ -123,13 +123,13 @@ test('command', function(t){
var UsageCommand = new Command({
usage:[
"usage -a 'fake' --verbose",
"usage -b 'tesk' --no-verbose",
"usage -b 'test' --no-verbose",
]
});

var out = [
"usage -a 'fake' --verbose",
"usage -b 'tesk' --no-verbose",
"usage -b 'test' --no-verbose",
"",
"Options:",
"",
Expand All @@ -138,7 +138,7 @@ test('command', function(t){
" ",
" <...>: input type | *: repeatable flags | [...]: default values"
].join(os.EOL );
ttt.equal( out, strip( UsageCommand.usage ) );
ttt.equal(strip( UsageCommand.usage ), out);
ttt.end()
});
tt.end()
Expand Down
15 changes: 2 additions & 13 deletions test/seeli.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ test('cli', function(t){

t.test('#run', function(tt) {
const help = cli.commands.help;
const log = console.log;
console.log = (str) => {
const data = String(str);
help.once('content', (data) => {
if (/usage/i.test(data)) {
const expected = [
'Usage: runner <command> [options]'
Expand All @@ -97,22 +95,13 @@ test('cli', function(t){
].join(os.EOL);
tt.equal(data, expected);
tt.end();
} else {
log(str);
}
}
tt.on('end', () => {
help.reset();
console.log = log;
});

help.setOptions({
args: ['--no-color']
});

help.on('content', (content) => {
tt.pass('help called');
});

cli.set({
exitOnContent: false
, name: 'runner'
Expand Down

0 comments on commit 8ee6f0e

Please sign in to comment.