Skip to content

Commit

Permalink
fix(forks): wrap defines to support undefined values
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Feb 23, 2024
1 parent d7c319e commit 83efd63
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/vitest/src/utils/config-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,20 @@ export function getOutputFile(config: PotentialConfig | undefined, reporter: Bui
*/
export function wrapSerializableConfig(config: ResolvedConfig) {
let testNamePattern = config.testNamePattern
let defines = config.defines

// v8 serialize does not support regex
if (testNamePattern && typeof testNamePattern !== 'string')
testNamePattern = `${REGEXP_WRAP_PREFIX}${testNamePattern.toString()}` as unknown as RegExp

// v8 serialize drops properties with undefined value
if (defines)
defines = wrapDefines(defines)

return {
...config,
testNamePattern,
defines,
} as ResolvedConfig
}

Expand All @@ -45,5 +51,20 @@ export function unwrapSerializableConfig(config: ResolvedConfig) {
config.testNamePattern = parseRegexp(testNamePattern.slice(REGEXP_WRAP_PREFIX.length))
}

if (config.defines && Array.isArray(config.defines.keys)) {
const { keys, original } = config.defines as ReturnType<typeof wrapDefines>
const defines: ResolvedConfig['defines'] = {}

// Apply all keys from the original. Entries which had undefined value are missing from original now
for (const key of keys)
defines[key] = original[key]

config.defines = defines
}

return config
}

function wrapDefines(input: Record<string, unknown>) {
return { keys: Object.keys(input), original: input }
}

0 comments on commit 83efd63

Please sign in to comment.