Skip to content

Commit

Permalink
fix: remove undefined values in options (#2281)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
Resolves #2153
  • Loading branch information
g4rry420 committed Nov 7, 2022
1 parent 1592dcf commit c9f9df9
Show file tree
Hide file tree
Showing 3 changed files with 302 additions and 181 deletions.
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

0 comments on commit c9f9df9

Please sign in to comment.