-
Notifications
You must be signed in to change notification settings - Fork 69
/
format-commands.test.ts
61 lines (50 loc) · 1.8 KB
/
format-commands.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import {Command, Interfaces} from '../../src'
import {expect, test as base} from '@oclif/test'
import stripAnsi = require('strip-ansi')
const g: any = global
g.oclif.columns = 80
import {Help} from '../../src/help'
import {AppsDestroy, AppsCreate} from './fixtures/fixtures'
// extensions to expose method as public for testing
class TestHelp extends Help {
public formatCommands(commands: Interfaces.Command[]) {
return super.formatCommands(commands)
}
}
const formatCommands = (commands: Interfaces.Command[]) => ({
run(ctx: {help: TestHelp; output: string}) {
const help = ctx.help.formatCommands(commands)
if (process.env.TEST_OUTPUT === '1') {
console.log(help)
}
ctx.output = stripAnsi(help).split('\n').map(s => s.trimEnd()).join('\n')
},
})
const test = base
.loadConfig()
.add('help', ctx => new TestHelp(ctx.config as any))
.register('formatCommands', formatCommands)
describe('formatCommand', () => {
test
.formatCommands([])
.it('outputs an empty string when no commands are given', (ctx: any) => expect(ctx.output).to.equal(''))
test
// @ts-ignore
.formatCommands([AppsDestroy, AppsCreate])
.it('shows a list of the provided commands', (ctx: any) => expect(ctx.output).to.equal(`COMMANDS
apps:destroy Destroy an app
apps:create Create an app`))
test
// @ts-ignore
.formatCommands([class extends Command {
static id = 'hello:world'
static description = 'This is a very long command description that should wrap after too many characters have been entered'
static args = []
async run() {
'run'
}
}])
.it('handles wraps long descriptions', (ctx: any) => expect(ctx.output).to.equal(`COMMANDS
hello:world This is a very long command description that should wrap after
too many characters have been entered`))
})