Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): --coverage.all=false resolved incorrectly #4697

Merged
merged 1 commit into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/vitest/src/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ cli
.option('--reporter <name>', 'Specify reporters')
.option('--outputFile <filename/-s>', 'Write test results to a file when supporter reporter is also specified, use cac\'s dot notation for individual outputs of multiple reporters')
.option('--coverage', 'Enable coverage report')
.option('--coverage.all', 'Whether to include all files, including the untested ones into report', { default: true })
.option('--run', 'Disable watch mode')
.option('--mode <name>', 'Override Vite mode (default: test)')
.option('--globals', 'Inject apis globally')
Expand Down
19 changes: 19 additions & 0 deletions test/config/fixtures/test/log-output.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { test } from 'vitest'
import type { UserConfig } from 'vitest/config'

/* eslint-disable no-console, unused-imports/no-unused-vars */

test('logs resolved configuration', async () => {
// @ts-expect-error -- internal
const { snapshotOptions, ...config }: UserConfig['test'] = globalThis.__vitest_worker__.config

// Log options that are tested
log('coverage.enabled', config.coverage?.enabled)

if(config.coverage?.provider === "istanbul" || config.coverage?.provider === "v8")
log('coverage.all', config.coverage?.all)
})

function log(label: string, value: unknown) {
console.log(label, value, typeof value)
}
2 changes: 1 addition & 1 deletion test/config/test/failures.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ test('coverage.autoUpdate cannot update thresholds when configuration file doesn
},
})

expect(stderr).toMatch('Error: Unable to parse thresholds from configuration file: Cannot read properties of undefined')
expect(stderr).toMatch('Error: Unable to parse thresholds from configuration file: Expected config.test.coverage.thresholds to be an object')
})

test('boolean flag 100 should not crash CLI', async () => {
Expand Down
25 changes: 25 additions & 0 deletions test/config/test/options.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { expect, test } from 'vitest'

import * as testUtils from '../../test-utils'

function runVitestCli(...cliArgs: string[]) {
return testUtils.runVitestCli('--root', 'fixtures', 'run', 'test/log-output.test.ts', ...cliArgs)
}

test('--coverage', async () => {
const { stdout } = await runVitestCli('--coverage')

expect(stdout).toMatch('coverage.enabled true boolean')
})

test('--coverage.all=false', async () => {
const { stdout } = await runVitestCli('--coverage.enabled', '--coverage.all=false')

expect(stdout).toMatch('coverage.all false boolean')
})

test('--coverage.all', async () => {
const { stdout } = await runVitestCli('--coverage.enabled', '--coverage.all')

expect(stdout).toMatch('coverage.all true boolean')
})
3 changes: 3 additions & 0 deletions test/config/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ export default defineConfig({
chaiConfig: {
truncateThreshold: 999,
},
coverage: {
reporter: [],
},
},
})
Loading