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

fix: remove undefined values in options #2281

Merged
merged 5 commits into from Nov 7, 2022
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
9 changes: 7 additions & 2 deletions packages/vitest/src/node/plugins/index.ts
Expand Up @@ -2,7 +2,7 @@ import type { UserConfig as ViteConfig, Plugin as VitePlugin } from 'vite'
import { relative } from 'pathe'
import { configDefaults } from '../../defaults'
import type { ResolvedConfig, UserConfig } from '../../types'
import { deepMerge, ensurePackageInstalled, notNullish } from '../../utils'
import { deepMerge, ensurePackageInstalled, notNullish, removeUndefinedValues } from '../../utils'
import { resolveApiConfig } from '../config'
import { Vitest } from '../core'
import { generateScopedClassName } from '../../integrations/css/css-modules'
Expand Down Expand Up @@ -36,7 +36,12 @@ export async function VitestPlugin(options: UserConfig = {}, ctx = new Vitest('t
// preliminary merge of options to be able to create server options for vite
// however to allow vitest plugins to modify vitest config values
// this is repeated in configResolved where the config is final
const preOptions = deepMerge({}, configDefaults, options, viteConfig.test ?? {})
const preOptions = deepMerge(
{},
configDefaults,
options,
removeUndefinedValues(viteConfig.test ?? {}),
)
preOptions.api = resolveApiConfig(preOptions)

if (viteConfig.define) {
Expand Down
8 changes: 8 additions & 0 deletions packages/vitest/src/utils/index.ts
Expand Up @@ -66,6 +66,14 @@ export function getFullName(task: Task) {
return getNames(task).join(c.dim(' > '))
}

export function removeUndefinedValues<T extends Record<string, any>>(obj: T): T {
for (const key in Object.keys(obj)) {
if (obj[key] === undefined)
delete obj[key]
}
return obj
}

export async function ensurePackageInstalled(
dependency: string,
root: string,
Expand Down