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 (fix #710) #715

Closed
Closed
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
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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will remove (default: true) text from vitest --help output. We can add this to option description.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add them

.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')
.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')
.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')
.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')
.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
17 changes: 16 additions & 1 deletion packages/vitest/src/node/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ import { Vitest } from '../core'
import { GlobalSetupPlugin } from './globalSetup'
import { MocksPlugin } from './mock'

function createDefaultConfig(options: UserConfig): Partial<UserConfig> {
return {
allowOnly: !process.env.CI,
environment: 'node',
isolate: true,
open: true,
threads: true,
watch: !process.env.CI && !options.run,
}
}

export async function VitestPlugin(options: UserConfig = {}, ctx = new Vitest()): Promise<VitePlugin[]> {
let haveStarted = false

Expand Down Expand Up @@ -45,7 +56,11 @@ 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(
createDefaultConfig(options),
(viteConfig.test as any) || {},
options,
)
options.api = resolveApiConfig(options)
},
async configureServer(server) {
Expand Down