Skip to content

Commit

Permalink
chore: rename to parseCLI
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Feb 20, 2024
1 parent 5ea3f3b commit 7e4db9e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions docs/advanced/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ const vitest = await createVitest('test', {
})
```
## normalizeCLI
## parseCLI
To correctly parse CLI arguments, you can use this method. It accepts a string (where arguments are split by a single space) or a strings array of CLI arguments in the same format that Vitest CLI uses. It returns a filter and `options` that you can later pass down to `createVitest` or `startVitest` methods.
You can use this method to parse CLI arguments. It accepts a string (where arguments are split by a single space) or a strings array of CLI arguments in the same format that Vitest CLI uses. It returns a filter and `options` that you can later pass down to `createVitest` or `startVitest` methods.
```ts
import { normalizeCLI } from 'vitest/node'
import { parseCLI } from 'vitest/node'

normalizeCLI('vitest ./files.ts --coverage --browser=chrome')
parseCLI('vitest ./files.ts --coverage --browser=chrome')
```
## Vitest
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/cli/cac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export function createCLI(options: CLIOptions = {}) {
return cli
}

export function normalizeCLI(argv: string | string[], config: CLIOptions = {}): {
export function parseCLI(argv: string | string[], config: CLIOptions = {}): {
filter: string[]
options: CliOptions
} {
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export type { WorkspaceProject } from './workspace'
export { createVitest } from './create'
export { VitestPlugin } from './plugins'
export { startVitest } from './cli/cli-api'
export { normalizeCLI } from './cli/cac'
export { parseCLI } from './cli/cac'
export { registerConsoleShortcuts } from './stdin'
export type { GlobalSetupContext } from './globalSetup'
export type { WorkspaceSpec, ProcessPool } from './pool'
Expand Down
20 changes: 10 additions & 10 deletions test/core/test/cli-test.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from 'vitest'
import { createCLI, normalizeCLI } from '../../../packages/vitest/src/node/cli/cac.js'
import { createCLI, parseCLI } from '../../../packages/vitest/src/node/cli/cac.js'

const vitestCli = createCLI()

Expand Down Expand Up @@ -254,32 +254,32 @@ test('browser by name', () => {
expect(options).toEqual({ browser: { enabled: true, name: 'firefox' } })
})

test('public normalizeCLI works correctly', () => {
expect(normalizeCLI('vitest dev')).toEqual({
test('public parseCLI works correctly', () => {
expect(parseCLI('vitest dev')).toEqual({
filter: [],
options: {
'watch': true,
'--': [],
'color': true,
},
})
expect(normalizeCLI('vitest watch')).toEqual({
expect(parseCLI('vitest watch')).toEqual({
filter: [],
options: {
'watch': true,
'--': [],
'color': true,
},
})
expect(normalizeCLI('vitest run')).toEqual({
expect(parseCLI('vitest run')).toEqual({
filter: [],
options: {
'run': true,
'--': [],
'color': true,
},
})
expect(normalizeCLI('vitest related ./some-files.js')).toEqual({
expect(parseCLI('vitest related ./some-files.js')).toEqual({
filter: [],
options: {
'passWithNoTests': true,
Expand All @@ -289,7 +289,7 @@ test('public normalizeCLI works correctly', () => {
},
})

expect(normalizeCLI('vitest --coverage --browser=chrome')).toEqual({
expect(parseCLI('vitest --coverage --browser=chrome')).toEqual({
filter: [],
options: {
'coverage': { enabled: true },
Expand All @@ -299,7 +299,7 @@ test('public normalizeCLI works correctly', () => {
},
})

expect(normalizeCLI('vitest ./tests.js --coverage')).toEqual({
expect(parseCLI('vitest ./tests.js --coverage')).toEqual({
filter: ['./tests.js'],
options: {
'coverage': { enabled: true },
Expand All @@ -308,7 +308,7 @@ test('public normalizeCLI works correctly', () => {
},
})

expect(normalizeCLI('vitest ./tests.js --coverage --custom-options', { allowUnknownOptions: true })).toEqual({
expect(parseCLI('vitest ./tests.js --coverage --custom-options', { allowUnknownOptions: true })).toEqual({
filter: ['./tests.js'],
options: {
'coverage': { enabled: true },
Expand All @@ -319,6 +319,6 @@ test('public normalizeCLI works correctly', () => {
})

expect(() => {
normalizeCLI('node --test --coverage --browser --typecheck')
parseCLI('node --test --coverage --browser --typecheck')
}).toThrowError(`Expected "vitest" as the first argument, received "node"`)
})

0 comments on commit 7e4db9e

Please sign in to comment.