From a7e09939e4a9792d38d80e9e54c44623179a85db Mon Sep 17 00:00:00 2001 From: Marcelo Botega Fontana Date: Wed, 13 Sep 2023 15:28:45 +0200 Subject: [PATCH] feat(coverage): add `coverage['100']` to istanbul provider (#4109) --- docs/config/index.md | 4 ++-- packages/coverage-istanbul/src/provider.ts | 4 ++++ packages/vitest/src/types/coverage.ts | 16 ++++++++-------- .../test/configuration-options.test-d.ts | 13 ++----------- 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/docs/config/index.md b/docs/config/index.md index 57d9b1e631aa..035979eb28d6 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -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 diff --git a/packages/coverage-istanbul/src/provider.ts b/packages/coverage-istanbul/src/provider.ts index 0ec38581e7ec..52013e0820e4 100644 --- a/packages/coverage-istanbul/src/provider.ts +++ b/packages/coverage-istanbul/src/provider.ts @@ -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({ diff --git a/packages/vitest/src/types/coverage.ts b/packages/vitest/src/types/coverage.ts index e5caf29cd2f9..50b9daebb549 100644 --- a/packages/vitest/src/types/coverage.ts +++ b/packages/vitest/src/types/coverage.ts @@ -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 { @@ -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 { /** Name of the module or path to a file to load the custom provider from */ diff --git a/test/coverage-test/test/configuration-options.test-d.ts b/test/coverage-test/test/configuration-options.test-d.ts index a0f42c0d4c62..68a88248a415 100644 --- a/test/coverage-test/test/configuration-options.test-d.ts +++ b/test/coverage-test/test/configuration-options.test-d.ts @@ -30,6 +30,7 @@ test('provider options, generic', () => { functions: [80, 95], lines: [80, 95], }, + 100: true, }) assertType({ @@ -39,15 +40,11 @@ test('provider options, generic', () => { watermarks: { statements: [80, 95], }, + 100: true, }) }) test('provider specific options, v8', () => { - assertType({ - provider: 'v8', - 100: true, - }) - assertType({ provider: 'v8', // @ts-expect-error -- Istanbul-only option is not allowed @@ -60,12 +57,6 @@ test('provider specific options, istanbul', () => { provider: 'istanbul', ignoreClassMethods: ['string'], }) - - assertType({ - provider: 'istanbul', - // @ts-expect-error -- V8-only option is not allowed - 100: true, - }) }) test('provider specific options, custom', () => {