Skip to content

Commit

Permalink
refactor: use hidden cliExclude to filter CLI args
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Dec 19, 2023
1 parent 29f8ff0 commit f6da69f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
5 changes: 5 additions & 0 deletions packages/vitest/src/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ function normalizeCliOptions(argv: CliOptions): CliOptions {
else
delete argv.dir

if (argv.exclude) {
argv.cliExclude = toArray(argv.exclude)
delete argv.exclude
}

if (argv.coverage) {
const coverage = argv.coverage
if (coverage.exclude)
Expand Down
7 changes: 2 additions & 5 deletions packages/vitest/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ export function resolveConfig(
options.environment = 'happy-dom'
}

const cliExcludes = options.exclude
delete options.exclude

const resolved = {
...configDefaults,
...options,
Expand Down Expand Up @@ -195,8 +192,8 @@ export function resolveConfig(
resolved.server.deps![option] = resolved.deps[option] as any
})

if (cliExcludes)
resolved.exclude.push(...cliExcludes)
if (resolved.cliExclude)
resolved.exclude.push(...resolved.cliExclude)

// vitenode will try to import such file with native node,
// but then our mocker will not work properly
Expand Down
8 changes: 7 additions & 1 deletion packages/vitest/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -752,9 +752,14 @@ export interface UserConfig extends InlineConfig {
* Name of the project or projects to run.
*/
project?: string | string[]

/**
* Additional exclude patterns
*/
cliExclude?: string[]
}

export interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'browser' | 'coverage' | 'testNamePattern' | 'related' | 'api' | 'reporters' | 'resolveSnapshotPath' | 'benchmark' | 'shard' | 'cache' | 'sequence' | 'typecheck' | 'runner' | 'poolOptions' | 'pool'> {
export interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'browser' | 'coverage' | 'testNamePattern' | 'related' | 'api' | 'reporters' | 'resolveSnapshotPath' | 'benchmark' | 'shard' | 'cache' | 'sequence' | 'typecheck' | 'runner' | 'poolOptions' | 'pool' | 'cliExclude'> {
mode: VitestRunMode

base?: string
Expand All @@ -776,6 +781,7 @@ export interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'f
defines: Record<string, any>

api?: ApiConfig
cliExclude?: string[]

benchmark?: Required<Omit<BenchmarkUserOptions, 'outputFile'>> & Pick<BenchmarkUserOptions, 'outputFile'>
shard?: {
Expand Down
3 changes: 1 addition & 2 deletions test/cli/fixtures/exclude/vitest.exclude.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { defineConfig } from 'vite'
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
include: ['fixtures/exclude/*.test.ts'],
exclude: ['fixtures/exclude/string.test.ts'],
},
})
1 change: 1 addition & 0 deletions test/cli/test/exclude.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ test('should still test math.test.ts', async () => {
)

expect(stdout).toContain(`✓ fixtures/exclude/math.test.ts`)
expect(stdout).not.toContain(`string.test.ts`)
expect(stderr).toBe('')
})

0 comments on commit f6da69f

Please sign in to comment.