Skip to content

Commit

Permalink
feat(coverage): add coverage['100'] to istanbul provider (#4109)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelobotega authored Sep 13, 2023
1 parent b75f91d commit a7e0993
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
4 changes: 2 additions & 2 deletions docs/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1078,10 +1078,10 @@ See [istanbul documentation](https://github.com/istanbuljs/nyc#coverage-threshol

- **Type:** `boolean`
- **Default:** `false`
- **Available for providers:** `'v8'`
- **Available for providers:** `'v8' | 'istanbul'`
- **CLI:** `--coverage.100`, `--coverage.100=false`

Shortcut for `--check-coverage --lines 100 --functions 100 --branches 100 --statements 100`.
Shortcut for `--coverage.lines 100 --coverage.functions 100 --coverage.branches 100 --coverage.statements 100`.

#### coverage.ignoreClassMethods

Expand Down
4 changes: 4 additions & 0 deletions packages/coverage-istanbul/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ export class IstanbulCoverageProvider extends BaseCoverageProvider implements Co
provider: 'istanbul',
reportsDirectory: resolve(ctx.config.root, config.reportsDirectory || coverageConfigDefaults.reportsDirectory),
reporter: this.resolveReporters(config.reporter || coverageConfigDefaults.reporter),
lines: config['100'] ? 100 : config.lines,
functions: config['100'] ? 100 : config.functions,
branches: config['100'] ? 100 : config.branches,
statements: config['100'] ? 100 : config.statements,
}

this.instrumenter = createInstrumenter({
Expand Down
16 changes: 8 additions & 8 deletions packages/vitest/src/types/coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,13 @@ export interface BaseCoverageOptions {
* @default false
*/
allowExternal?: boolean

/**
* Shortcut for `{ lines: 100, functions: 100, branches: 100, statements: 100 }`
*
* @default false
*/
100?: boolean
}

export interface CoverageIstanbulOptions extends BaseCoverageOptions {
Expand All @@ -235,14 +242,7 @@ export interface CoverageIstanbulOptions extends BaseCoverageOptions {
ignoreClassMethods?: string[]
}

export interface CoverageV8Options extends BaseCoverageOptions {
/**
* Shortcut for `--check-coverage --lines 100 --functions 100 --branches 100 --statements 100`
*
* @default false
*/
100?: boolean
}
export interface CoverageV8Options extends BaseCoverageOptions {}

export interface CustomProviderOptions extends Pick<BaseCoverageOptions, FieldsWithDefaultValues> {
/** Name of the module or path to a file to load the custom provider from */
Expand Down
13 changes: 2 additions & 11 deletions test/coverage-test/test/configuration-options.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ test('provider options, generic', () => {
functions: [80, 95],
lines: [80, 95],
},
100: true,
})

assertType<Coverage>({
Expand All @@ -39,15 +40,11 @@ test('provider options, generic', () => {
watermarks: {
statements: [80, 95],
},
100: true,
})
})

test('provider specific options, v8', () => {
assertType<Coverage>({
provider: 'v8',
100: true,
})

assertType<Coverage>({
provider: 'v8',
// @ts-expect-error -- Istanbul-only option is not allowed
Expand All @@ -60,12 +57,6 @@ test('provider specific options, istanbul', () => {
provider: 'istanbul',
ignoreClassMethods: ['string'],
})

assertType<Coverage>({
provider: 'istanbul',
// @ts-expect-error -- V8-only option is not allowed
100: true,
})
})

test('provider specific options, custom', () => {
Expand Down

0 comments on commit a7e0993

Please sign in to comment.