Skip to content

Commit

Permalink
feat(cli): prioritize args over config rebase (#716)
Browse files Browse the repository at this point in the history
  • Loading branch information
DerYeger committed Feb 9, 2022
1 parent af5ca4c commit fc94fc6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
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

0 comments on commit fc94fc6

Please sign in to comment.