diff --git a/packages/vitest/src/node/cache/index.ts b/packages/vitest/src/node/cache/index.ts index 209722e78862..994b4d78ff8e 100644 --- a/packages/vitest/src/node/cache/index.ts +++ b/packages/vitest/src/node/cache/index.ts @@ -1,10 +1,5 @@ -import fs from 'node:fs' import crypto from 'node:crypto' -import { findUp } from 'find-up' import { resolve } from 'pathe' -import { loadConfigFromFile } from 'vite' -import { configFiles } from '../../constants' -import type { CliOptions } from '../cli/cli-api' import { slash } from '../../utils' import { FilesStatsCache } from './files' import { ResultsCache } from './results' @@ -27,34 +22,4 @@ export class VitestCache { ? resolve(root, baseDir, crypto.createHash('md5').update(projectName, 'utf-8').digest('hex')) : resolve(root, baseDir) } - - static async clearCache(options: CliOptions) { - const root = resolve(options.root || process.cwd()) - - const configPath = options.config === false - ? false - : options.config - ? resolve(root, options.config) - : await findUp(configFiles, { cwd: root } as any) - - const config = configPath - ? (await loadConfigFromFile({ command: 'serve', mode: 'test' }, configPath))?.config - : undefined - - const cache = config?.test?.cache - const projectName = config?.test?.name - - if (cache === false) - throw new Error('Cache is disabled') - - const cachePath = VitestCache.resolveCacheDir(root, cache?.dir, projectName) - - let cleared = false - - if (fs.existsSync(cachePath)) { - fs.rmSync(cachePath, { recursive: true, force: true }) - cleared = true - } - return { dir: cachePath, cleared } - } } diff --git a/test/cache/.gitignore b/test/cache/.gitignore deleted file mode 100644 index f8a91fd2ba6b..000000000000 --- a/test/cache/.gitignore +++ /dev/null @@ -1 +0,0 @@ -cache/* \ No newline at end of file diff --git a/test/cache/package.json b/test/cache/package.json deleted file mode 100644 index 7460dd246ae2..000000000000 --- a/test/cache/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "@vitest/test-cache", - "type": "module", - "private": true, - "scripts": { - "test": "vitest", - "coverage": "vitest run --coverage" - }, - "devDependencies": { - "vitest": "workspace:*" - } -} diff --git a/test/cache/test/clear-cache.test.ts b/test/cache/test/clear-cache.test.ts deleted file mode 100644 index 323461c43a66..000000000000 --- a/test/cache/test/clear-cache.test.ts +++ /dev/null @@ -1,26 +0,0 @@ -import fs, { promises as fsp } from 'node:fs' -import { resolve } from 'pathe' -import { describe, expect, test } from 'vitest' -import { VitestCache } from '../../../packages/vitest/src/node/cache/index' - -const root = resolve(__dirname, '..') - -const pathBase = resolve(root, 'cache/.vitest-base') -const pathCustom = resolve(root, 'cache/.vitest-custom') - -describe('vitest cache', async () => { - await fsp.mkdir(pathBase, { recursive: true }) - await fsp.mkdir(pathCustom, { recursive: true }) - - test('clears cache without specifying config path', async () => { - await VitestCache.clearCache({}) - - expect(fs.existsSync(pathBase)).toBe(false) - }) - - test('clears cache with specified config path', async () => { - await VitestCache.clearCache({ config: 'vitest-custom.config.ts' }) - - expect(fs.existsSync(pathCustom)).toBe(false) - }) -}) diff --git a/test/cache/vitest-custom.config.ts b/test/cache/vitest-custom.config.ts deleted file mode 100644 index 6087616010f8..000000000000 --- a/test/cache/vitest-custom.config.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { defineConfig } from 'vite' - -export default defineConfig({ - test: { - cache: { - dir: 'cache/.vitest-custom', - }, - }, -}) diff --git a/test/cache/vitest.config.ts b/test/cache/vitest.config.ts deleted file mode 100644 index 6461c042ead9..000000000000 --- a/test/cache/vitest.config.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { defineConfig } from 'vite' - -export default defineConfig({ - test: { - pool: 'forks', - cache: { - dir: 'cache/.vitest-base', - }, - }, -})