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 fa65648
Show file tree
Hide file tree
Showing 2 changed files with 24 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
23 changes: 21 additions & 2 deletions test/core/test/cli-test.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,34 @@ 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([])
expect(options).toEqual({ browser: { enabled: true, name: 'firefox' } })
})

test('browser as boolean with file filter', () => {
const { options, args } = parseArguments('--browser some-file.test.ts', false, true)

expect(args).toEqual(['some-file.test.ts'])

Check failure on line 253 in test/core/test/cli-test.test.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 18)

test/cli-test.test.ts > browser as boolean with file filter

AssertionError: expected [] to deeply equal [ 'some-file.test.ts' ] - Expected + Received - Array [ - "some-file.test.ts", - ] + Array [] ❯ test/cli-test.test.ts:253:16

Check failure on line 253 in test/core/test/cli-test.test.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 20)

test/cli-test.test.ts > browser as boolean with file filter

AssertionError: expected [] to deeply equal [ 'some-file.test.ts' ] - Expected + Received - Array [ - "some-file.test.ts", - ] + Array [] ❯ test/cli-test.test.ts:253:16

Check failure on line 253 in test/core/test/cli-test.test.ts

View workflow job for this annotation

GitHub Actions / test (macos-latest, 20)

test/cli-test.test.ts > browser as boolean with file filter

AssertionError: expected [] to deeply equal [ 'some-file.test.ts' ] - Expected + Received - Array [ - "some-file.test.ts", - ] + Array [] ❯ test/cli-test.test.ts:253:16

Check failure on line 253 in test/core/test/cli-test.test.ts

View workflow job for this annotation

GitHub Actions / test (windows-latest, 20)

test/cli-test.test.ts > browser as boolean with file filter

AssertionError: expected [] to deeply equal [ 'some-file.test.ts' ] - Expected + Received - Array [ - "some-file.test.ts", - ] + Array [] ❯ test/cli-test.test.ts:253:16
expect(options).toEqual({ browser: { enabled: true } })
})

0 comments on commit fa65648

Please sign in to comment.