@@ -2,7 +2,7 @@ import path from 'path'
2
2
import execa from 'execa'
3
3
import cac from '..'
4
4
5
- function fixture ( file : string ) {
5
+ function example ( file : string ) {
6
6
return path . relative (
7
7
process . cwd ( ) ,
8
8
path . join ( __dirname , '../../examples' , file )
@@ -12,40 +12,39 @@ function fixture(file: string) {
12
12
function snapshotOutput ( {
13
13
title,
14
14
file,
15
- args
15
+ args,
16
16
} : {
17
17
title : string
18
18
file : string
19
19
args ?: string [ ]
20
20
} ) {
21
21
test ( title , async ( ) => {
22
- const { stdout } = await execa ( 'node' , [ fixture ( file ) , ...( args || [ ] ) ] )
22
+ const { stdout } = await execa ( 'node' , [ example ( file ) , ...( args || [ ] ) ] )
23
23
expect ( stdout ) . toMatchSnapshot ( title )
24
24
} )
25
25
}
26
26
27
+ async function getOutput ( file : string , args : string [ ] = [ ] ) {
28
+ const { stdout } = await execa ( 'node' , [ example ( file ) , ...( args || [ ] ) ] )
29
+ return stdout
30
+ }
31
+
27
32
snapshotOutput ( {
28
33
title : 'basic-usage' ,
29
34
file : 'basic-usage.js' ,
30
- args : [ 'foo' , 'bar' , '--type' , 'ok' , 'command' ]
31
- } )
32
-
33
- snapshotOutput ( {
34
- title : 'help' ,
35
- file : 'help.js' ,
36
- args : [ '--help' ]
35
+ args : [ 'foo' , 'bar' , '--type' , 'ok' , 'command' ] ,
37
36
} )
38
37
39
38
snapshotOutput ( {
40
39
title : 'variadic-arguments' ,
41
40
file : 'variadic-arguments.js' ,
42
- args : [ '--foo' , 'build' , 'a' , 'b' , 'c' , 'd' ]
41
+ args : [ '--foo' , 'build' , 'a' , 'b' , 'c' , 'd' ] ,
43
42
} )
44
43
45
44
snapshotOutput ( {
46
45
title : 'ignore-default-value' ,
47
46
file : 'ignore-default-value.js' ,
48
- args : [ 'build' ]
47
+ args : [ 'build' ] ,
49
48
} )
50
49
51
50
test ( 'negated option' , ( ) => {
@@ -59,7 +58,7 @@ test('negated option', () => {
59
58
expect ( options ) . toEqual ( {
60
59
'--' : [ ] ,
61
60
foo : 'foo' ,
62
- bar : true
61
+ bar : true ,
63
62
} )
64
63
} )
65
64
@@ -73,7 +72,7 @@ test('double dashes', () => {
73
72
'bar' ,
74
73
'--' ,
75
74
'npm' ,
76
- 'test'
75
+ 'test' ,
77
76
] )
78
77
79
78
expect ( args ) . toEqual ( [ 'foo' , 'bar' ] )
@@ -111,7 +110,7 @@ test('array types without transformFunction', () => {
111
110
'--externals <external>' ,
112
111
'Add externals(can be used for multiple times' ,
113
112
{
114
- type : [ ]
113
+ type : [ ] ,
115
114
}
116
115
)
117
116
. option ( '--scale [level]' , 'Scaling level' )
@@ -139,7 +138,7 @@ test('array types with transformFunction', () => {
139
138
cli
140
139
. command ( 'build [entry]' , 'Build your app' )
141
140
. option ( '--config <configFlie>' , 'Use config file for building' , {
142
- type : [ String ]
141
+ type : [ String ] ,
143
142
} )
144
143
. option ( '--scale [level]' , 'Scaling level' )
145
144
@@ -163,3 +162,15 @@ test('throw on unknown options', () => {
163
162
cli . parse ( `node bin build app.js --fooBar --a-b --xx` . split ( ' ' ) )
164
163
} ) . toThrowError ( 'Unknown option `--xx`' )
165
164
} )
165
+
166
+ describe ( '--version in help message' , ( ) => {
167
+ test ( 'sub command' , async ( ) => {
168
+ const output = await getOutput ( 'help.js' , [ 'lint' , '--help' ] )
169
+ expect ( output ) . not . toContain ( `--version` )
170
+ } )
171
+
172
+ test ( 'default command' , async ( ) => {
173
+ const output = await getOutput ( 'help.js' , [ '--help' ] )
174
+ expect ( output ) . toContain ( `--version` )
175
+ } )
176
+ } )
0 commit comments