Skip to content

Commit

Permalink
fix(cli): --coverage.all=false resolved incorrectly (#4697)
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio authored Dec 9, 2023
1 parent 7c19664 commit a7931bb
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 1 deletion.
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: [],
},
},
})

0 comments on commit a7931bb

Please sign in to comment.