Skip to content

Commit a7931bb

Browse files
authoredDec 9, 2023
fix(cli): --coverage.all=false resolved incorrectly (#4697)
1 parent 7c19664 commit a7931bb

File tree

5 files changed

+49
-1
lines changed

5 files changed

+49
-1
lines changed
 

‎packages/vitest/src/node/cli.ts

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ cli
2626
.option('--reporter <name>', 'Specify reporters')
2727
.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')
2828
.option('--coverage', 'Enable coverage report')
29+
.option('--coverage.all', 'Whether to include all files, including the untested ones into report', { default: true })
2930
.option('--run', 'Disable watch mode')
3031
.option('--mode <name>', 'Override Vite mode (default: test)')
3132
.option('--globals', 'Inject apis globally')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { test } from 'vitest'
2+
import type { UserConfig } from 'vitest/config'
3+
4+
/* eslint-disable no-console, unused-imports/no-unused-vars */
5+
6+
test('logs resolved configuration', async () => {
7+
// @ts-expect-error -- internal
8+
const { snapshotOptions, ...config }: UserConfig['test'] = globalThis.__vitest_worker__.config
9+
10+
// Log options that are tested
11+
log('coverage.enabled', config.coverage?.enabled)
12+
13+
if(config.coverage?.provider === "istanbul" || config.coverage?.provider === "v8")
14+
log('coverage.all', config.coverage?.all)
15+
})
16+
17+
function log(label: string, value: unknown) {
18+
console.log(label, value, typeof value)
19+
}

‎test/config/test/failures.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ test('coverage.autoUpdate cannot update thresholds when configuration file doesn
9292
},
9393
})
9494

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

9898
test('boolean flag 100 should not crash CLI', async () => {

‎test/config/test/options.test.ts

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { expect, test } from 'vitest'
2+
3+
import * as testUtils from '../../test-utils'
4+
5+
function runVitestCli(...cliArgs: string[]) {
6+
return testUtils.runVitestCli('--root', 'fixtures', 'run', 'test/log-output.test.ts', ...cliArgs)
7+
}
8+
9+
test('--coverage', async () => {
10+
const { stdout } = await runVitestCli('--coverage')
11+
12+
expect(stdout).toMatch('coverage.enabled true boolean')
13+
})
14+
15+
test('--coverage.all=false', async () => {
16+
const { stdout } = await runVitestCli('--coverage.enabled', '--coverage.all=false')
17+
18+
expect(stdout).toMatch('coverage.all false boolean')
19+
})
20+
21+
test('--coverage.all', async () => {
22+
const { stdout } = await runVitestCli('--coverage.enabled', '--coverage.all')
23+
24+
expect(stdout).toMatch('coverage.all true boolean')
25+
})

‎test/config/vitest.config.ts

+3
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@ export default defineConfig({
99
chaiConfig: {
1010
truncateThreshold: 999,
1111
},
12+
coverage: {
13+
reporter: [],
14+
},
1215
},
1316
})

0 commit comments

Comments
 (0)
Please sign in to comment.