test: disable Vitest fs cache on Windows

This commit is contained in:
Tak Hoffman
2026-03-24 21:46:29 -05:00
parent 3c46e0307a
commit 64432f8e46
2 changed files with 50 additions and 1 deletions

View File

@@ -22,6 +22,43 @@ describe("loadVitestExperimentalConfig", () => {
});
});
it("disables the filesystem module cache by default on Windows", () => {
const originalRunnerOs = process.env.RUNNER_OS;
process.env.RUNNER_OS = "Windows";
try {
expect(loadVitestExperimentalConfig({ RUNNER_OS: "Windows" })).toEqual({});
} finally {
if (originalRunnerOs === undefined) {
delete process.env.RUNNER_OS;
} else {
process.env.RUNNER_OS = originalRunnerOs;
}
}
});
it("still allows enabling the filesystem module cache explicitly on Windows", () => {
const originalRunnerOs = process.env.RUNNER_OS;
process.env.RUNNER_OS = "Windows";
try {
expect(
loadVitestExperimentalConfig({
RUNNER_OS: "Windows",
OPENCLAW_VITEST_FS_MODULE_CACHE: "1",
}),
).toEqual({
experimental: {
fsModuleCache: true,
},
});
} finally {
if (originalRunnerOs === undefined) {
delete process.env.RUNNER_OS;
} else {
process.env.RUNNER_OS = originalRunnerOs;
}
}
});
it("allows disabling the filesystem module cache explicitly", () => {
expect(
loadVitestExperimentalConfig({

View File

@@ -10,6 +10,14 @@ const isDisabled = (value: string | undefined): boolean => {
return normalized === "0" || normalized === "false";
};
const isWindowsEnv = (env: EnvMap, platform: NodeJS.Platform): boolean => {
if (platform === "win32") {
return true;
}
const runnerOs = env.RUNNER_OS?.trim().toLowerCase();
return runnerOs === "windows";
};
export function loadVitestExperimentalConfig(env: EnvMap = process.env): {
experimental?: {
fsModuleCache?: true;
@@ -22,8 +30,12 @@ export function loadVitestExperimentalConfig(env: EnvMap = process.env): {
importDurations?: { print: true };
printImportBreakdown?: true;
} = {};
const windowsEnv = isWindowsEnv(env, process.platform);
if (!isDisabled(env.OPENCLAW_VITEST_FS_MODULE_CACHE)) {
if (!windowsEnv && !isDisabled(env.OPENCLAW_VITEST_FS_MODULE_CACHE)) {
experimental.fsModuleCache = true;
}
if (windowsEnv && isEnabled(env.OPENCLAW_VITEST_FS_MODULE_CACHE)) {
experimental.fsModuleCache = true;
}
if (isEnabled(env.OPENCLAW_VITEST_IMPORT_DURATIONS)) {