This repository has been archived by the owner on Aug 22, 2023. It is now read-only.
/
main.test.ts
116 lines (97 loc) · 3.22 KB
/
main.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import {expect, fancy} from 'fancy-test'
import {Main} from '../src/main'
import * as OclifHelp from '@oclif/help'
import * as Config from '@oclif/config'
import {TestHelpClassConfig} from './helpers/test-help-in-src/src/test-help-plugin'
const pjson = require('../package.json')
const version = `@oclif/command/${pjson.version} ${process.platform}-${process.arch} node-${process.version}`
const originalgetHelpClass = OclifHelp.getHelpClass
describe('main', () => {
fancy
.stdout()
.do(() => Main.run(['plugins']))
.do(output => expect(output.stdout).to.equal('no plugins installed\n'))
.it('runs plugins')
fancy
.stdout()
.do(() => Main.run(['-v']))
.catch('EEXIT: 0')
.do(output => expect(output.stdout).to.equal(version + '\n'))
.it('runs -v')
fancy
.stdout()
.do(() => Main.run(['-h']))
.catch('EEXIT: 0')
.do(output => expect(output.stdout).to.equal(`oclif base command
VERSION
${version}
USAGE
$ @oclif/command [COMMAND]
TOPICS
plugins list installed plugins
COMMANDS
plugins list installed plugins
`))
.it('runs -h')
describe('with an alternative help class', async () => {
const getMainWithHelpClass = async () => {
const config: TestHelpClassConfig = await Config.load()
config.pjson.oclif.helpClass = './lib/test-help-plugin'
class MainWithHelpClass extends Main {
config = config
}
return MainWithHelpClass
}
fancy
.stdout()
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
.stub(OclifHelp, 'getHelpClass', function (config: Config.IConfig) {
const patchedConfig = {
...config,
root: `${__dirname}/helpers/test-help-in-src/`,
}
return originalgetHelpClass(patchedConfig)
})
.do(async () => (await getMainWithHelpClass()).run(['-h']))
.catch('EEXIT: 0')
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
.do(output => expect(output.stdout).to.equal('hello showHelp\n'))
.it('works with -h')
fancy
.stdout()
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
.stub(OclifHelp, 'getHelpClass', function (config: Config.IConfig) {
const patchedConfig = {
...config,
root: `${__dirname}/helpers/test-help-in-src/`,
}
return originalgetHelpClass(patchedConfig)
})
.do(async () => (await getMainWithHelpClass()).run(['--help']))
.catch('EEXIT: 0')
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
.do(output => expect(output.stdout).to.equal('hello showHelp\n'))
.it('works with --help')
fancy
.stdout()
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
.stub(OclifHelp, 'getHelpClass', function (config: Config.IConfig) {
const patchedConfig = {
...config,
root: `${__dirname}/helpers/test-help-in-src/`,
}
return originalgetHelpClass(patchedConfig)
})
.do(async () => (await getMainWithHelpClass()).run(['help']))
.catch('EEXIT: 0')
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
.do(output => expect(output.stdout).to.equal('hello showHelp\n'))
.it('works with help')
})
})