11import { expect , test as base } from '@oclif/test'
2- import stripAnsi = require( 'strip-ansi' )
32
4- import { Command as Base , Flags as flags , Interfaces , toCached } from '../../src'
5- import { Help , CommandHelp } from '../../src/ help'
3+ import { Command as Base , Flags as flags } from '../../src'
4+ import { commandHelp , TestHelpWithOptions as TestHelp } from './ help-test-utils '
65
76const g : any = global
87g . oclif . columns = 80
@@ -15,47 +14,10 @@ class Command extends Base {
1514 }
1615}
1716
18- // Allow overriding section headers
19- class TestCommandHelp extends CommandHelp {
20- protected sections ( ) {
21- const sections = super . sections ( )
22- const flagSection = sections . find ( section => section . header === 'FLAGS' )
23- if ( flagSection ) flagSection . header = 'OPTIONS'
24- return sections
25- }
26- }
27-
28- // extensions to expose method as public for testing
29- class TestHelp extends Help {
30- CommandHelpClass = TestCommandHelp
31-
32- constructor ( config : Interfaces . Config , opts : Partial < Interfaces . HelpOptions > = { } ) {
33- super ( config , opts )
34- this . opts . showFlagNameInTitle = true
35- this . opts . showFlagOptionsInTitle = true
36- this . opts . hideCommandSummaryInDescription = true
37- }
38-
39- public formatCommand ( command : Interfaces . Command ) {
40- return super . formatCommand ( command )
41- }
42- }
43-
4417const test = base
4518. loadConfig ( )
4619. add ( 'help' , ctx => new TestHelp ( ctx . config as any ) )
47- . register ( 'commandHelp' , ( command ?: any ) => ( {
48- async run ( ctx : { help : TestHelp ; commandHelp : string ; expectation : string } ) {
49- const cached = await toCached ( command ! , { } as any )
50- const help = ctx . help . formatCommand ( cached )
51- if ( process . env . TEST_OUTPUT === '1' ) {
52- console . log ( help )
53- }
54-
55- ctx . commandHelp = stripAnsi ( help ) . split ( '\n' ) . map ( s => s . trimEnd ( ) ) . join ( '\n' )
56- ctx . expectation = 'has commandHelp'
57- } ,
58- } ) )
20+ . register ( 'commandHelp' , commandHelp )
5921
6022describe ( 'formatCommand' , ( ) => {
6123 test
0 commit comments