@@ -2,7 +2,7 @@ import path from 'path'
22import execa from 'execa'
33import cac from '..'
44
5- function fixture ( file : string ) {
5+ function example ( file : string ) {
66 return path . relative (
77 process . cwd ( ) ,
88 path . join ( __dirname , '../../examples' , file )
@@ -12,40 +12,39 @@ function fixture(file: string) {
1212function snapshotOutput ( {
1313 title,
1414 file,
15- args
15+ args,
1616} : {
1717 title : string
1818 file : string
1919 args ?: string [ ]
2020} ) {
2121 test ( title , async ( ) => {
22- const { stdout } = await execa ( 'node' , [ fixture ( file ) , ...( args || [ ] ) ] )
22+ const { stdout } = await execa ( 'node' , [ example ( file ) , ...( args || [ ] ) ] )
2323 expect ( stdout ) . toMatchSnapshot ( title )
2424 } )
2525}
2626
27+ async function getOutput ( file : string , args : string [ ] = [ ] ) {
28+ const { stdout } = await execa ( 'node' , [ example ( file ) , ...( args || [ ] ) ] )
29+ return stdout
30+ }
31+
2732snapshotOutput ( {
2833 title : 'basic-usage' ,
2934 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' ] ,
3736} )
3837
3938snapshotOutput ( {
4039 title : 'variadic-arguments' ,
4140 file : 'variadic-arguments.js' ,
42- args : [ '--foo' , 'build' , 'a' , 'b' , 'c' , 'd' ]
41+ args : [ '--foo' , 'build' , 'a' , 'b' , 'c' , 'd' ] ,
4342} )
4443
4544snapshotOutput ( {
4645 title : 'ignore-default-value' ,
4746 file : 'ignore-default-value.js' ,
48- args : [ 'build' ]
47+ args : [ 'build' ] ,
4948} )
5049
5150test ( 'negated option' , ( ) => {
@@ -59,7 +58,7 @@ test('negated option', () => {
5958 expect ( options ) . toEqual ( {
6059 '--' : [ ] ,
6160 foo : 'foo' ,
62- bar : true
61+ bar : true ,
6362 } )
6463} )
6564
@@ -73,7 +72,7 @@ test('double dashes', () => {
7372 'bar' ,
7473 '--' ,
7574 'npm' ,
76- 'test'
75+ 'test' ,
7776 ] )
7877
7978 expect ( args ) . toEqual ( [ 'foo' , 'bar' ] )
@@ -111,7 +110,7 @@ test('array types without transformFunction', () => {
111110 '--externals <external>' ,
112111 'Add externals(can be used for multiple times' ,
113112 {
114- type : [ ]
113+ type : [ ] ,
115114 }
116115 )
117116 . option ( '--scale [level]' , 'Scaling level' )
@@ -139,7 +138,7 @@ test('array types with transformFunction', () => {
139138 cli
140139 . command ( 'build [entry]' , 'Build your app' )
141140 . option ( '--config <configFlie>' , 'Use config file for building' , {
142- type : [ String ]
141+ type : [ String ] ,
143142 } )
144143 . option ( '--scale [level]' , 'Scaling level' )
145144
@@ -163,3 +162,15 @@ test('throw on unknown options', () => {
163162 cli . parse ( `node bin build app.js --fooBar --a-b --xx` . split ( ' ' ) )
164163 } ) . toThrowError ( 'Unknown option `--xx`' )
165164} )
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