From ad208cc2911a0b48a6afae8bcae2f67de1393089 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Thu, 1 Oct 2026 18:06:19 +0200 Subject: [PATCH] fix: enable fsModuleCache by default (#11435) --- docs/config/fsmodulecache.md | 4 ++-- docs/guide/cli-generated.md | 2 +- docs/guide/improving-performance.md | 2 +- packages/vitest/src/node/cli/cli-config.ts | 2 +- packages/vitest/src/node/config/resolveConfig.ts | 2 +- packages/vitest/src/node/types/config.ts | 2 +- test/e2e/fixtures/doctor/vitest.config.ts | 1 + 7 files changed, 8 insertions(+), 7 deletions(-) diff --git a/docs/config/fsmodulecache.md b/docs/config/fsmodulecache.md index 214621760..6636da15c 100644 --- a/docs/config/fsmodulecache.md +++ b/docs/config/fsmodulecache.md @@ -6,10 +6,10 @@ outline: deep # fsModuleCache 5.0.0 - **Type:** `boolean` -- **Default:** `false` +- **Default:** `true` - **CLI:** `--fsModuleCache`, `--fsModuleCache=false` -In watch mode, Vitest caches all transformed files in memory, which makes reruns fast. However, this cache is discarded once the test run finishes. Enabling this option allows Vitest to persist the transformed modules on the file system, so they can be reused across reruns and separate Vitest processes. +In watch mode, Vitest caches all transformed files in memory, which makes reruns fast. However, this cache is discarded once the test run finishes. This option allows Vitest to persist the transformed modules on the file system, so they can be reused across reruns and separate Vitest processes. A single cache directory is shared by every project in the workspace. By default it lives in `node_modules` at the workspace root (so it is naturally invalidated when dependencies are reinstalled); use [`fsModuleCachePath`](/config/fsmodulecachepath) to change its location. You can delete the cache by running [`vitest --clearCache`](/guide/cli#clearcache). diff --git a/docs/guide/cli-generated.md b/docs/guide/cli-generated.md index 397f8d8e4..d1e405554 100644 --- a/docs/guide/cli-generated.md +++ b/docs/guide/cli-generated.md @@ -824,7 +824,7 @@ Maximum number of concurrent tests and suites during test file execution (defaul - **CLI:** `--fsModuleCache` - **Config:** [fsModuleCache](/config/fsmodulecache) -Cache transformed modules on the file system and reuse them between reruns (default: `false`) +Cache transformed modules on the file system and reuse them between reruns (default: `true`) ### fsModuleCachePath diff --git a/docs/guide/improving-performance.md b/docs/guide/improving-performance.md index 47cb32260..b0708cd0d 100644 --- a/docs/guide/improving-performance.md +++ b/docs/guide/improving-performance.md @@ -133,7 +133,7 @@ You can limit the working directory when Vitest searches for files using [`test. ## Caching Between Reruns -In watch mode, Vitest caches all transformed files in memory, which makes reruns fast. However, this cache is discarded once the test run finishes. By enabling [`fsModuleCache`](/config/fsmodulecache), Vitest persists this cache to the file system so it can be reused across reruns. +In watch mode, Vitest caches all transformed files in memory, which makes reruns fast. However, this cache is discarded once the test run finishes. With [`fsModuleCache`](/config/fsmodulecache) (enabled by default), Vitest persists this cache to the file system so it can be reused across reruns. This improvement is most noticeable when rerunning a small number of tests that depend on a large module graph. For full test suites, parallelization already mitigates the cost because other tests populate the in-memory cache while earlier tests are still running. For example, running one test file with a huge module graph (>900 modules): diff --git a/packages/vitest/src/node/cli/cli-config.ts b/packages/vitest/src/node/cli/cli-config.ts index d405e21e8..5f4a0c1a9 100644 --- a/packages/vitest/src/node/cli/cli-config.ts +++ b/packages/vitest/src/node/cli/cli-config.ts @@ -764,7 +764,7 @@ export const cliOptionsConfig: VitestCLIOptions = { }, fsModuleCache: { description: - 'Cache transformed modules on the file system and reuse them between reruns (default: `false`)', + 'Cache transformed modules on the file system and reuse them between reruns (default: `true`)', }, fsModuleCachePath: { description: diff --git a/packages/vitest/src/node/config/resolveConfig.ts b/packages/vitest/src/node/config/resolveConfig.ts index bd2016142..29b0ab65e 100644 --- a/packages/vitest/src/node/config/resolveConfig.ts +++ b/packages/vitest/src/node/config/resolveConfig.ts @@ -1073,7 +1073,7 @@ export function resolveTestConfig( resolved.fsModuleCachePath = legacyExperimental.fsModuleCachePath } } - resolved.fsModuleCache ??= false + resolved.fsModuleCache ??= true if (resolved.fsModuleCachePath) { resolved.fsModuleCachePath = resolve(resolved.root, resolved.fsModuleCachePath) } diff --git a/packages/vitest/src/node/types/config.ts b/packages/vitest/src/node/types/config.ts index b369b907f..b6144f839 100644 --- a/packages/vitest/src/node/types/config.ts +++ b/packages/vitest/src/node/types/config.ts @@ -716,7 +716,7 @@ export interface InlineConfig { * Cache transformed modules on the file system and reuse them between reruns * and separate Vitest processes, which can significantly speed up cold starts. * - * @default false + * @default true */ fsModuleCache?: boolean diff --git a/test/e2e/fixtures/doctor/vitest.config.ts b/test/e2e/fixtures/doctor/vitest.config.ts index 2f35653f1..fb044c074 100644 --- a/test/e2e/fixtures/doctor/vitest.config.ts +++ b/test/e2e/fixtures/doctor/vitest.config.ts @@ -3,5 +3,6 @@ import { defineConfig } from 'vitest/config' export default defineConfig({ test: { watch: false, + fsModuleCache: false, }, }) -- 2.51.2