@@ -3,16 +3,20 @@ import { createCLI } from '../../../packages/vitest/src/node/cli/cac.js'
33
44const vitestCli = createCLI ( )
55
6- function parseArguments ( commands : string , full = false ) {
6+ function parseArguments ( commands : string , full = false , includeArgs = false ) {
77 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 ] , {
99 run : false ,
1010 } )
1111 // remove -- and color from the options since they are always present
1212 if ( ! full ) {
1313 delete options [ '--' ]
1414 delete options . color
1515 }
16+
17+ if ( includeArgs )
18+ return { options, args }
19+
1620 return options
1721}
1822
@@ -149,11 +153,11 @@ test('array options', () => {
149153 ` )
150154
151155 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
157161 --coverage.extension=tsx
158162 ` ) ) . toMatchInlineSnapshot ( `
159163 {
@@ -217,3 +221,28 @@ test('cache is parsed correctly', () => {
217221 cache : { dir : 'test/cache.json' } ,
218222 } )
219223} )
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