@@ -3,16 +3,20 @@ import { createCLI } from '../../../packages/vitest/src/node/cli/cac.js'
3
3
4
4
const vitestCli = createCLI ( )
5
5
6
- function parseArguments ( commands : string , full = false ) {
6
+ function parseArguments ( commands : string , full = false , includeArgs = false ) {
7
7
const cliArgs = commands . trim ( ) . replace ( / \s + / g, ' ' ) . split ( ' ' )
8
- const { options } = vitestCli . parse ( [ 'node' , '/index.js' , ...cliArgs ] , {
8
+ const { options, args } = vitestCli . parse ( [ 'node' , '/index.js' , ...cliArgs ] , {
9
9
run : false ,
10
10
} )
11
11
// remove -- and color from the options since they are always present
12
12
if ( ! full ) {
13
13
delete options [ '--' ]
14
14
delete options . color
15
15
}
16
+
17
+ if ( includeArgs )
18
+ return { options, args }
19
+
16
20
return options
17
21
}
18
22
@@ -149,11 +153,11 @@ test('array options', () => {
149
153
` )
150
154
151
155
expect ( parseArguments ( `
152
- --reporter json
153
- --reporter=default
154
- --coverage.reporter=json
155
- --coverage.reporter html
156
- --coverage.extension=ts
156
+ --reporter json
157
+ --reporter=default
158
+ --coverage.reporter=json
159
+ --coverage.reporter html
160
+ --coverage.extension=ts
157
161
--coverage.extension=tsx
158
162
` ) ) . toMatchInlineSnapshot ( `
159
163
{
@@ -217,3 +221,28 @@ test('cache is parsed correctly', () => {
217
221
cache : { dir : 'test/cache.json' } ,
218
222
} )
219
223
} )
224
+
225
+ test ( 'browser as implicit boolean' , ( ) => {
226
+ const { options, args } = parseArguments ( '--browser' , false , true )
227
+ expect ( options ) . toEqual ( { browser : { enabled : true } } )
228
+ expect ( args ) . toEqual ( [ ] )
229
+ } )
230
+
231
+ test ( 'browser as explicit boolean' , ( ) => {
232
+ const { options, args } = parseArguments ( '--browser=true' , false , true )
233
+ expect ( options ) . toEqual ( { browser : { enabled : true } } )
234
+ expect ( args ) . toEqual ( [ ] )
235
+ } )
236
+
237
+ test ( 'browser as explicit boolean with space' , ( ) => {
238
+ const { options, args } = parseArguments ( '--browser true' , false , true )
239
+ expect ( options ) . toEqual ( { browser : { enabled : true } } )
240
+ expect ( args ) . toEqual ( [ ] )
241
+ } )
242
+
243
+ test ( 'browser by name' , ( ) => {
244
+ const { options, args } = parseArguments ( '--browser=firefox' , false , true )
245
+
246
+ expect ( args ) . toEqual ( [ ] )
247
+ expect ( options ) . toEqual ( { browser : { enabled : true , name : 'firefox' } } )
248
+ } )
0 commit comments