From 52edf25c700c5fb6ea0d43894e323a1e7cd4528c Mon Sep 17 00:00:00 2001 From: Jacob Erdman Date: Wed, 13 Nov 2024 15:36:42 -0800 Subject: [PATCH 1/3] fix(vitest): prioritize the cacheDir option from viteConfig over the resolved ones from optimizer config generation --- packages/vitest/src/node/plugins/optimizer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vitest/src/node/plugins/optimizer.ts b/packages/vitest/src/node/plugins/optimizer.ts index f75153887d88..494629b20ede 100644 --- a/packages/vitest/src/node/plugins/optimizer.ts +++ b/packages/vitest/src/node/plugins/optimizer.ts @@ -20,7 +20,7 @@ export function VitestOptimizer(): Plugin { ) viteConfig.cacheDir - = webOptimizer.cacheDir || ssrOptimizer.cacheDir || viteConfig.cacheDir + = viteConfig.cacheDir || webOptimizer.cacheDir || ssrOptimizer.cacheDir viteConfig.optimizeDeps = webOptimizer.optimizeDeps viteConfig.ssr ??= {} viteConfig.ssr.optimizeDeps = ssrOptimizer.optimizeDeps From 25fd7255ab38a7965ce7ea2b6eb2431402602f88 Mon Sep 17 00:00:00 2001 From: Jacob Erdman Date: Wed, 13 Nov 2024 15:37:50 -0800 Subject: [PATCH 2/3] fix(dev): properly pass test options through when using createVitest --- packages/vitest/src/node/create.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/vitest/src/node/create.ts b/packages/vitest/src/node/create.ts index cf64cfaedd52..5019a08505ad 100644 --- a/packages/vitest/src/node/create.ts +++ b/packages/vitest/src/node/create.ts @@ -36,6 +36,7 @@ export async function createVitest( // this will make "mode": "test" | "benchmark" inside defineConfig mode: options.mode || mode, plugins: await VitestPlugin(options, ctx), + test: options, } const server = await createViteServer( From 9f7c89dae6447ec57448256ea89b487fafc32428 Mon Sep 17 00:00:00 2001 From: Jacob Erdman Date: Wed, 13 Nov 2024 15:39:04 -0800 Subject: [PATCH 3/3] fix(vitest): remove viteConfig cacheDir override within the VitestOptimizer plugin --- packages/vitest/src/node/plugins/optimizer.ts | 4 ---- packages/vitest/src/node/plugins/utils.ts | 12 ++---------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/packages/vitest/src/node/plugins/optimizer.ts b/packages/vitest/src/node/plugins/optimizer.ts index 494629b20ede..6706c79d7ab9 100644 --- a/packages/vitest/src/node/plugins/optimizer.ts +++ b/packages/vitest/src/node/plugins/optimizer.ts @@ -11,16 +11,12 @@ export function VitestOptimizer(): Plugin { const webOptimizer = resolveOptimizerConfig( testConfig.deps?.optimizer?.web, viteConfig.optimizeDeps, - testConfig, ) const ssrOptimizer = resolveOptimizerConfig( testConfig.deps?.optimizer?.ssr, viteConfig.ssr?.optimizeDeps, - testConfig, ) - viteConfig.cacheDir - = viteConfig.cacheDir || webOptimizer.cacheDir || ssrOptimizer.cacheDir viteConfig.optimizeDeps = webOptimizer.optimizeDeps viteConfig.ssr ??= {} viteConfig.ssr.optimizeDeps = ssrOptimizer.optimizeDeps diff --git a/packages/vitest/src/node/plugins/utils.ts b/packages/vitest/src/node/plugins/utils.ts index a17458c6b64b..4fffed0d6a64 100644 --- a/packages/vitest/src/node/plugins/utils.ts +++ b/packages/vitest/src/node/plugins/utils.ts @@ -3,19 +3,17 @@ import type { ResolvedConfig, UserConfig as ViteConfig, } from 'vite' -import type { DepsOptimizationOptions, InlineConfig } from '../types/config' +import type { DepsOptimizationOptions } from '../types/config' import { dirname } from 'pathe' import { searchForWorkspaceRoot, version as viteVersion } from 'vite' import { rootDir } from '../../paths' -import { VitestCache } from '../cache' export function resolveOptimizerConfig( _testOptions: DepsOptimizationOptions | undefined, viteOptions: DepOptimizationOptions | undefined, - testConfig: InlineConfig, ) { const testOptions = _testOptions || {} - const newConfig: { cacheDir?: string; optimizeDeps: DepOptimizationOptions } + const newConfig: { optimizeDeps: DepOptimizationOptions } = {} as any const [major, minor, fix] = viteVersion.split('.').map(Number) const allowed @@ -32,7 +30,6 @@ export function resolveOptimizerConfig( testOptions.enabled ??= false } if (!allowed || testOptions?.enabled !== true) { - newConfig.cacheDir = undefined newConfig.optimizeDeps = { // experimental in Vite >2.9.2, entries remains to help with older versions disabled: true, @@ -40,9 +37,6 @@ export function resolveOptimizerConfig( } } else { - const root = testConfig.root ?? process.cwd() - const cacheDir - = testConfig.cache !== false ? testConfig.cache?.dir : undefined const currentInclude = testOptions.include || viteOptions?.include || [] const exclude = [ 'vitest', @@ -60,8 +54,6 @@ export function resolveOptimizerConfig( (n: string) => !exclude.includes(n), ) - newConfig.cacheDir - = cacheDir ?? VitestCache.resolveCacheDir(root, cacheDir, testConfig.name) newConfig.optimizeDeps = { ...viteOptions, ...testOptions,