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

feat(cli): prioritize args over config rebase #716

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/vitest/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const coverageConfigDefaults = Object.freeze({
}) as ResolvedC8Options

export const configDefaults: UserConfig = Object.freeze({
allowOnly: !process.env.CI,
globals: false,
environment: 'node',
threads: true,
Expand All @@ -48,7 +49,7 @@ export const configDefaults: UserConfig = Object.freeze({
isolate: true,
watchIgnore: [/\/node_modules\//, /\/dist\//],
update: false,
watch: true,
watch: !process.env.CI,
reporters: 'default',
silent: false,
api: false,
Expand Down
12 changes: 5 additions & 7 deletions packages/vitest/src/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ cli
.option('-w, --watch', 'watch mode')
.option('-t, --testNamePattern <pattern>', 'run test names with the specified pattern')
.option('--ui', 'enable UI')
.option('--open', 'open UI automatically', { default: true })
.option('--open', 'open UI automatically (default: (default: !process.env.CI))')
.option('--api [api]', 'serve API, available options: --api.port <port>, --api.host [host] and --api.strictPort')
.option('--threads', 'enabled threads', { default: true })
.option('--threads', 'enabled threads (default: true)')
.option('--silent', 'silent console output from tests')
.option('--isolate', 'isolate environment for each test file', { default: true })
.option('--isolate', 'isolate environment for each test file (default: true)')
.option('--reporter <name>', 'reporter')
.option('--outputFile <filename>', 'write test results to a file when the --reporter=json option is also specified')
.option('--coverage', 'use c8 for coverage')
.option('--run', 'do not watch')
.option('--globals', 'inject apis globally')
.option('--global', 'deprecated, use --globals')
.option('--dom', 'mock browser api with happy-dom')
.option('--environment <env>', 'runner environment', { default: 'node' })
.option('--environment <env>', 'runner environment (default: node)')
.option('--passWithNoTests', 'pass when no tests found')
.option('--allowOnly', 'Allow tests and suites that are marked as only', { default: !process.env.CI })
.option('--allowOnly', 'Allow tests and suites that are marked as only (default: !process.env.CI)')
.help()

cli
Expand Down Expand Up @@ -62,8 +62,6 @@ async function runRelated(relatedFiles: string[] | string, argv: UserConfig) {
}

async function dev(cliFilters: string[], argv: UserConfig) {
if (argv.watch == null)
argv.watch = !process.env.CI && !argv.run
await run(cliFilters, argv)
}

Expand Down
9 changes: 8 additions & 1 deletion packages/vitest/src/node/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Plugin as VitePlugin } from 'vite'
import { configDefaults } from '../../constants'
import type { UserConfig } from '../../types'
import { deepMerge, ensurePackageInstalled, notNullish } from '../../utils'
import { resolveApiConfig } from '../config'
Expand Down Expand Up @@ -45,8 +46,14 @@ export async function VitestPlugin(options: UserConfig = {}, ctx = new Vitest())
},
async configResolved(viteConfig) {
// viteConfig.test is final now, merge it for real
options = deepMerge(options, viteConfig.test as any || {})
options = deepMerge(
{},
configDefaults,
(viteConfig.test as any) || {},
options,
)
options.api = resolveApiConfig(options)
options.watch = options.watch && !options.run
},
async configureServer(server) {
if (haveStarted)
Expand Down