Skip to content

Commit

Permalink
feat: add coverage.watermarks to CLI options
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Feb 10, 2024
1 parent 6319737 commit 92983c4
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,7 @@ See [istanbul documentation](https://github.com/istanbuljs/nyc#ignoring-methods)
```

- **Available for providers:** `'v8' | 'istanbul'`
- **CLI:** `--coverage.watermarks.statements=50,80`, `--coverage.watermarks.branches=50,80`

Watermarks for statements, lines, branches and functions. See [istanbul documentation](https://github.com/istanbuljs/nyc#high-and-low-watermarks) for more information.

Expand Down
35 changes: 32 additions & 3 deletions packages/vitest/src/node/cli/cli-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ const poolForksCommands: CLIOptions<ForksOptions & WorkerContextOptions> = {
execArgv: null,
}

function watermarkTransform(value: unknown) {
if (typeof value === 'string')
return value.split(',').map(Number)
return value
}

function transformNestedBoolean(value: unknown) {
if (typeof value === 'boolean')
return { enabled: value }
Expand Down Expand Up @@ -249,9 +255,32 @@ export const cliOptionsConfig: VitestCLIOptions = {
argument: '<path>',
normalize: true,
},
// TODO: suport watermarks via a special command?
// CAC requires --watermarks.statements=50 --watermarks.statements=80 for "statements:[50,80]" which looks rediculous
watermarks: null,
watermarks: {
description: null,
argument: '', // no displayed
subcommands: {
statements: {
description: 'High and low watermarks for statements in the format of <high>,<low>',
argument: '<watermarks>',
transform: watermarkTransform,
},
lines: {
description: 'High and low watermarks for lines in the format of <high>,<low>',
argument: '<watermarks>',
transform: watermarkTransform,
},
branches: {
description: 'High and low watermarks for branches in the format of <high>,<low>',
argument: '<watermarks>',
transform: watermarkTransform,
},
functions: {
description: 'High and low watermarks for functions in the format of <high>,<low>',
argument: '<watermarks>',
transform: watermarkTransform,
},
},
},
},
},
mode: {
Expand Down
11 changes: 11 additions & 0 deletions test/core/test/cli-test.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ test('nested coverage options have correct types', async () => {
--coverage.thresholds.lines 100
--coverage.thresholds.functions 30
--coverage.thresholds.branches 25
--coverage.watermarks.statements 50,80
--coverage.watermarks.lines=30,40
--coverage.watermarks.branches=70,80
--coverage.watermarks.functions 20,60
`).coverage).toEqual({
enabled: true,
reporter: ['text'],
Expand All @@ -85,6 +90,12 @@ test('nested coverage options have correct types', async () => {
autoUpdate: true,
100: true,
},
watermarks: {
statements: [50, 80],
lines: [30, 40],
branches: [70, 80],
functions: [20, 60],
},
})
})

Expand Down

0 comments on commit 92983c4

Please sign in to comment.