Skip to content

Commit

Permalink
Re-enabled unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
coreybutler committed Apr 30, 2020
1 parent 194b86d commit 976ea00
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 175 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@author.io/shell",
"version": "1.3.12",
"version": "1.3.13",
"description": "A micro-framework for creating CLI-like experiences. This supports Node.js and browsers.",
"main": "src/index.js",
"scripts": {
Expand Down
346 changes: 173 additions & 173 deletions test/unit/01-sanity/01-sanity.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,202 +2,202 @@ import 'source-map-support/register.js'
import test from 'tape'
import { Command, Shell, Formatter } from '../../.node/index.js'

// test('Sanity Check - Shell', t => {
// const shell = new Shell({
// name: 'test'
// })

// t.ok(shell instanceof Shell, 'Basic shell instantiates correctly.')

// t.end()
// })

// test('Sanity Check - Command', t => {
// const mirror = new Command({
// name: 'mirror',
// description: 'Search metadoc for all the things.',
// alias: 'search',
// handler: (input, cb) => {
// console.log(`Mirroring input: ${input}`)

// cb && cb()
// }
// })
test('Sanity Check - Shell', t => {
const shell = new Shell({
name: 'test'
})

// t.ok(mirror instanceof Command, 'Command initialized successfully.')
t.ok(shell instanceof Shell, 'Basic shell instantiates correctly.')

// const CLI = new Shell({
// name: 'test',
// description: 'test',
// commands: [
// mirror,
// {
// name: 'test',
// description: 'Test command which has no custom handler.'
// }
// ]
// })
t.end()
})

// t.ok(CLI instanceof Shell, 'Shell initialized with commands successfully.')
test('Sanity Check - Command', t => {
const mirror = new Command({
name: 'mirror',
description: 'Search metadoc for all the things.',
alias: 'search',
handler: (input, cb) => {
console.log(`Mirroring input: ${input}`)

// CLI.exec('test').then(data => {
// t.pass('Default handler fires.')
// t.end()
// }).catch(e => {
// console.log(e)
// t.fail(e.message)
// t.end()
// })
// })
cb && cb()
}
})

// test('Output Formatting', t => {
// const shell = new Shell({
// name: 'test'
// })
t.ok(mirror instanceof Command, 'Command initialized successfully.')

// const cmd = new Command({
// name: 'cmd',
// alias: 'c',
// flags: {
// test: {
// alias: 't',
// description: 'test description'
// },
// more: {
// aliases: ['m', 'mr'],
// description: 'This is a longer description that should break onto more than one line, or perhaps even more than one extra line with especially poor grammar and spellling.'
// },
// none: {
// description: 'Ignore me. I do not exist.'
// }
// }
// })
const CLI = new Shell({
name: 'test',
description: 'test',
commands: [
mirror,
{
name: 'test',
description: 'Test command which has no custom handler.'
}
]
})

// shell.add(cmd)
t.ok(CLI instanceof Shell, 'Shell initialized with commands successfully.')

// const formatter = new Formatter(cmd)
// formatter.width = 80
CLI.exec('test').then(data => {
t.pass('Default handler fires.')
t.end()
}).catch(e => {
console.log(e)
t.fail(e.message)
t.end()
})
})

// t.ok(formatter instanceof Formatter, 'Basic formatter instantiates correctly.')
// console.log(formatter.help)
// t.end()
// })
test('Output Formatting', t => {
const shell = new Shell({
name: 'test'
})

// test('Subcommand Config', t => {
// const cfg = {
// name: 'account',
// description: 'Perform operations on a user account.',
// handler (meta, cb) {
// console.log('TODO: Output account details')
// },
// commands: [
// {
// name: 'create',
// description: 'Create a user account.',
// arguments: '<email>',
// flags: {
// name: {
// alias: 'n',
// description: 'Account display name'
// },
// phone: {
// alias: 'p',
// description: 'Account phone number'
// },
// avatar: {
// alias: 'a',
// description: 'Account avatar image URL'
// }
// },
const cmd = new Command({
name: 'cmd',
alias: 'c',
flags: {
test: {
alias: 't',
description: 'test description'
},
more: {
aliases: ['m', 'mr'],
description: 'This is a longer description that should break onto more than one line, or perhaps even more than one extra line with especially poor grammar and spellling.'
},
none: {
description: 'Ignore me. I do not exist.'
}
}
})

// handler (meta, cb) {
// console.log(meta)
// }
// }
// ]
// }
shell.add(cmd)

// const shell = new Shell({
// name: 'test',
// commands: [cfg]
// })
const formatter = new Formatter(cmd)
formatter.width = 80

// shell.exec('account create')
// t.pass('Configuring subcommands does not throw an error')
// t.end()
// })
t.ok(formatter instanceof Formatter, 'Basic formatter instantiates correctly.')
console.log(formatter.help)
t.end()
})

test('Default command help (regression test)', t => {
const shell = new Shell({
name: 'test',
version: '1.0.0',
disableHelp: true,
// defaultHandler: () => console.log('yo'),
test('Subcommand Config', t => {
const cfg = {
name: 'account',
description: 'Perform operations on a user account.',
handler (meta, cb) {
console.log('TODO: Output account details')
},
commands: [
{
name: 'account',
description: 'Perform operations on a user account.',
handler: (meta, cb) => {
console.log('TODO: Output account details')
},
commands: [
{
name: 'create',
description: 'Create a user account.',
arguments: '<email>',
flags: {
name: {
alias: 'n',
description: 'Account display name'
},
phone: {
alias: 'p',
description: 'Account phone number'
},
avatar: {
alias: 'a',
description: 'Account avatar image URL'
}
}
// handler: (meta, cb) => {
// // console.log(meta);
// }
}
]
},
{
name: 'find',
description: 'Search Metadoc for all the things.',
alias: 'search',
handler: (meta, cb) => {
},
name: 'create',
description: 'Create a user account.',
arguments: '<email>',
flags: {
maxresults: {
type: 'string',
single: true
name: {
alias: 'n',
description: 'Account display name'
},
phone: {
alias: 'p',
description: 'Account phone number'
},
avatar: {
alias: 'a',
description: 'Account avatar image URL'
}
}
},
{
name: 'load',
description: 'Load a metadoc.',
handler: (meta, cb) => {
}
},
{
name: 'logout',
alias: 'signout',
handler: (meta, cb) => {
},

handler (meta, cb) {
console.log(meta)
cb && cb()
}
}
]
}

const shell = new Shell({
name: 'test',
commands: [cfg]
})

shell.exec('account')
// console.log('---------')
// shell.exec('blah')
t.pass('ok')
shell.exec('account create')
t.pass('Configuring subcommands does not throw an error')
t.end()
})

// test('Default command help (regression test)', t => {
// const shell = new Shell({
// name: 'test',
// version: '1.0.0',
// disableHelp: true,
// // defaultHandler: () => console.log('yo'),
// commands: [
// {
// name: 'account',
// description: 'Perform operations on a user account.',
// handler: (meta, cb) => {
// console.log('TODO: Output account details')
// },
// commands: [
// {
// name: 'create',
// description: 'Create a user account.',
// arguments: '<email>',
// flags: {
// name: {
// alias: 'n',
// description: 'Account display name'
// },
// phone: {
// alias: 'p',
// description: 'Account phone number'
// },
// avatar: {
// alias: 'a',
// description: 'Account avatar image URL'
// }
// }
// // handler: (meta, cb) => {
// // // console.log(meta);
// // }
// }
// ]
// },
// {
// name: 'find',
// description: 'Search Metadoc for all the things.',
// alias: 'search',
// handler: (meta, cb) => {
// },
// flags: {
// maxresults: {
// type: 'string',
// single: true
// }
// }
// },
// {
// name: 'load',
// description: 'Load a metadoc.',
// handler: (meta, cb) => {
// }
// },
// {
// name: 'logout',
// alias: 'signout',
// handler: (meta, cb) => {
// console.log(meta)
// cb && cb()
// }
// }
// ]
// })

// shell.exec('account')
// // console.log('---------')
// // shell.exec('blah')
// t.pass('ok')
// t.end()
// })

0 comments on commit 976ea00

Please sign in to comment.