Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/vitest/src/node/config/resolveConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ export function resolveConfig(
if (resolved.cache !== false) {
let cacheDir = VitestCache.resolveCacheDir(
'',
resolve(viteConfig.cacheDir, 'vitest'),
viteConfig.cacheDir,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

vitest suffix is to avoid collision of node_modules/.vite/deps directory, so using it for results.json is not technically necessary.

resolved.name,
)

Expand Down
2 changes: 2 additions & 0 deletions packages/vitest/src/node/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ export async function VitestPlugin(
?? viteConfig.test?.isolate,
},
},
root: testConfig.root ?? viteConfig.test?.root,
deps: testConfig.deps ?? viteConfig.test?.deps,
Comment on lines +145 to +146
Copy link
Contributor Author

@hi-ogawa hi-ogawa Nov 15, 2024

Choose a reason for hiding this comment

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

I added these here to so that root and deps from inline test config can be referenced from VitestOptimizer plugin.

},
}

Expand Down
2 changes: 2 additions & 0 deletions packages/vitest/src/node/plugins/optimizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ export function VitestOptimizer(): Plugin {
testConfig.deps?.optimizer?.web,
viteConfig.optimizeDeps,
testConfig,
viteConfig.cacheDir,
)
const ssrOptimizer = resolveOptimizerConfig(
testConfig.deps?.optimizer?.ssr,
viteConfig.ssr?.optimizeDeps,
testConfig,
viteConfig.cacheDir,
)

viteConfig.cacheDir
Expand Down
6 changes: 2 additions & 4 deletions packages/vitest/src/node/plugins/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export function resolveOptimizerConfig(
_testOptions: DepsOptimizationOptions | undefined,
viteOptions: DepOptimizationOptions | undefined,
testConfig: InlineConfig,
viteCacheDir: string | undefined,
) {
const testOptions = _testOptions || {}
const newConfig: { cacheDir?: string; optimizeDeps: DepOptimizationOptions }
Expand Down Expand Up @@ -41,8 +42,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',
Expand All @@ -60,8 +59,7 @@ export function resolveOptimizerConfig(
(n: string) => !exclude.includes(n),
)

newConfig.cacheDir
= cacheDir ?? VitestCache.resolveCacheDir(root, cacheDir, testConfig.name)
newConfig.cacheDir = (testConfig.cache !== false && testConfig.cache?.dir) || VitestCache.resolveCacheDir(root, viteCacheDir, testConfig.name)
newConfig.optimizeDeps = {
...viteOptions,
...testOptions,
Expand Down
8 changes: 4 additions & 4 deletions test/config/test/cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test('default', async () => {
expect(stderr).toBe('')

const cachePath = ctx!.cache.results.getCachePath()
const path = resolve(project, 'node_modules/.vite/vitest/results.json')
const path = resolve(project, 'node_modules/.vite/results.json')
expect(cachePath).toMatch(path)
})

Expand Down Expand Up @@ -53,7 +53,7 @@ test('use cacheDir', async () => {
expect(stderr).toBe('')

const cachePath = ctx!.cache.results.getCachePath()
const path = resolve(root, 'node_modules/.vite-custom/vitest/results.json')
const path = resolve(root, 'node_modules/.vite-custom/results.json')
expect(cachePath).toMatch(path)
})

Expand All @@ -77,7 +77,7 @@ describe('with optimizer enabled', () => {
expect(stderr).toBe('')

const cachePath = ctx!.cache.results.getCachePath()
const path = resolve(project, 'node_modules/.vite/vitest/results.json')
const path = resolve(root, 'node_modules/.vite/vitest/results.json')
expect(cachePath).toBe(path)
})

Expand Down Expand Up @@ -117,7 +117,7 @@ describe('with optimizer enabled', () => {
expect(stderr).toBe('')

const cachePath = ctx!.cache.results.getCachePath()
const path = resolve(root, 'node_modules/.vite-custom/vitest/results.json')
const path = resolve(root, 'node_modules/.vite-custom/results.json')
expect(cachePath).toBe(path)
})
})