Skip to content

Commit

Permalink
fix(cli): parse --browser=<name> correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Feb 12, 2024
1 parent 78156f7 commit 4e6ba96
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/vitest/src/node/cli/cli-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,12 @@ export const cliOptionsConfig: VitestCLIOptions = {
},
browser: {
description: 'Run tests in the browser. Equivalent to --browser.enabled (default: false)',
argument: '', // allow boolean
argument: '<name>',
transform(browser) {
if (typeof browser === 'boolean')
return { enabled: browser }
if (browser === 'true' || browser === 'false')
return { enabled: browser !== 'false' }
if (typeof browser === 'string')
return { enabled: true, name: browser }
return browser
Expand Down
16 changes: 14 additions & 2 deletions test/core/test/cli-test.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,25 @@ test('cache is parsed correctly', () => {
})
})

test('browser as boolean', () => {
test('browser as implicit boolean', () => {
const { options, args } = parseArguments('--browser', false, true)
expect(options).toEqual({ browser: { enabled: true } })
expect(args).toEqual([])
})

test('browser as string', () => {
test('browser as explicit boolean', () => {
const { options, args } = parseArguments('--browser=true', false, true)
expect(options).toEqual({ browser: { enabled: true } })
expect(args).toEqual([])
})

test('browser as explicit boolean with space', () => {
const { options, args } = parseArguments('--browser true', false, true)
expect(options).toEqual({ browser: { enabled: true } })
expect(args).toEqual([])
})

test('browser by name', () => {
const { options, args } = parseArguments('--browser=firefox', false, true)

expect(args).toEqual([])
Expand Down

0 comments on commit 4e6ba96

Please sign in to comment.