@@ -3,6 +3,8 @@ import { toDashCase } from '@utils';
3
3
import { LogLevel } from '../../declarations' ;
4
4
import {
5
5
BOOLEAN_CLI_FLAGS ,
6
+ BOOLEAN_STRING_CLI_FLAGS ,
7
+ BooleanStringCLIFlag ,
6
8
ConfigFlags ,
7
9
NUMBER_CLI_FLAGS ,
8
10
STRING_ARRAY_CLI_FLAGS ,
@@ -132,36 +134,42 @@ describe('parseFlags', () => {
132
134
expect ( flags . config ) . toBe ( '/config-2.js' ) ;
133
135
} ) ;
134
136
135
- describe ( 'boolean-string flag' , ( ) => {
137
+ describe . each ( BOOLEAN_STRING_CLI_FLAGS ) ( 'boolean-string flag - %s ' , ( cliArg : BooleanStringCLIFlag ) => {
136
138
it ( 'parses a boolean-string flag as a boolean with no arg' , ( ) => {
137
- const args = [ '--headless' ] ;
139
+ const args = [ `-- ${ cliArg } ` ] ;
138
140
const flags = parseFlags ( args ) ;
139
141
expect ( flags . headless ) . toBe ( true ) ;
140
- expect ( flags . knownArgs ) . toEqual ( [ '--headless' ] ) ;
142
+ expect ( flags . knownArgs ) . toEqual ( [ `-- ${ cliArg } ` ] ) ;
141
143
} ) ;
142
144
143
- it . each ( [ [ '--noHeadless' ] , [ '--no-headless' ] ] ) (
144
- 'parses a boolean-string flag as a falsy boolean with "no" arg - \'%s\'' ,
145
- ( noVariant ) => {
146
- const args = [ noVariant ] ;
147
- const flags = parseFlags ( args ) ;
148
- expect ( flags . headless ) . toBe ( false ) ;
149
- expect ( flags . knownArgs ) . toEqual ( [ noVariant ] ) ;
150
- }
151
- ) ;
145
+ it ( `parses a boolean-string flag as a falsy boolean with "no" arg - --no-${ cliArg } ` , ( ) => {
146
+ const args = [ `--no-${ cliArg } ` ] ;
147
+ const flags = parseFlags ( args ) ;
148
+ expect ( flags . headless ) . toBe ( false ) ;
149
+ expect ( flags . knownArgs ) . toEqual ( [ `--no-${ cliArg } ` ] ) ;
150
+ } ) ;
152
151
153
- it ( "parses a boolean-string flag as a string with 'new' arg" , ( ) => {
154
- const args = [ '--headless' , 'new' ] ;
152
+ it ( `parses a boolean-string flag as a falsy boolean with "no" arg - --no${
153
+ cliArg . charAt ( 0 ) . toUpperCase ( ) + cliArg . slice ( 1 )
154
+ } `, ( ) => {
155
+ const negativeFlag = '--no' + cliArg . charAt ( 0 ) . toUpperCase ( ) + cliArg . slice ( 1 ) ;
156
+ const flags = parseFlags ( [ negativeFlag ] ) ;
157
+ expect ( flags . headless ) . toBe ( false ) ;
158
+ expect ( flags . knownArgs ) . toEqual ( [ negativeFlag ] ) ;
159
+ } ) ;
160
+
161
+ it ( 'parses a boolean-string flag as a string with a string arg' , ( ) => {
162
+ const args = [ `--${ cliArg } ` , 'new' ] ;
155
163
const flags = parseFlags ( args ) ;
156
164
expect ( flags . headless ) . toBe ( 'new' ) ;
157
165
expect ( flags . knownArgs ) . toEqual ( [ '--headless' , 'new' ] ) ;
158
166
} ) ;
159
167
160
- it ( " parses a boolean-string flag as a string with 'new' arg using equality" , ( ) => {
161
- const args = [ '--headless =new' ] ;
168
+ it ( ' parses a boolean-string flag as a string with a string arg using equality' , ( ) => {
169
+ const args = [ `-- ${ cliArg } =new` ] ;
162
170
const flags = parseFlags ( args ) ;
163
171
expect ( flags . headless ) . toBe ( 'new' ) ;
164
- expect ( flags . knownArgs ) . toEqual ( [ '--headless' , 'new' ] ) ;
172
+ expect ( flags . knownArgs ) . toEqual ( [ `-- ${ cliArg } ` , 'new' ] ) ;
165
173
} ) ;
166
174
} ) ;
167
175
0 commit comments