test: make vitest config tests platform-aware

This commit is contained in:
Tak Hoffman
2026-03-24 22:22:21 -05:00
parent f3eb620824
commit 93656da672
2 changed files with 43 additions and 43 deletions

View File

@@ -3,7 +3,7 @@ import { loadVitestExperimentalConfig } from "../vitest.performance-config.ts";
describe("loadVitestExperimentalConfig", () => {
it("enables the filesystem module cache by default", () => {
expect(loadVitestExperimentalConfig({})).toEqual({
expect(loadVitestExperimentalConfig({}, "linux")).toEqual({
experimental: {
fsModuleCache: true,
},
@@ -12,9 +12,12 @@ describe("loadVitestExperimentalConfig", () => {
it("enables the filesystem module cache explicitly", () => {
expect(
loadVitestExperimentalConfig({
OPENCLAW_VITEST_FS_MODULE_CACHE: "1",
}),
loadVitestExperimentalConfig(
{
OPENCLAW_VITEST_FS_MODULE_CACHE: "1",
},
"linux",
),
).toEqual({
experimental: {
fsModuleCache: true,
@@ -23,56 +26,44 @@ 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;
}
}
expect(loadVitestExperimentalConfig({}, "win32")).toEqual({});
});
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",
expect(
loadVitestExperimentalConfig(
{
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;
}
}
"win32",
),
).toEqual({
experimental: {
fsModuleCache: true,
},
});
});
it("allows disabling the filesystem module cache explicitly", () => {
expect(
loadVitestExperimentalConfig({
OPENCLAW_VITEST_FS_MODULE_CACHE: "0",
}),
loadVitestExperimentalConfig(
{
OPENCLAW_VITEST_FS_MODULE_CACHE: "0",
},
"linux",
),
).toEqual({});
});
it("enables import timing output and import breakdown reporting", () => {
expect(
loadVitestExperimentalConfig({
OPENCLAW_VITEST_IMPORT_DURATIONS: "true",
OPENCLAW_VITEST_PRINT_IMPORT_BREAKDOWN: "1",
}),
loadVitestExperimentalConfig(
{
OPENCLAW_VITEST_IMPORT_DURATIONS: "true",
OPENCLAW_VITEST_PRINT_IMPORT_BREAKDOWN: "1",
},
"linux",
),
).toEqual({
experimental: {
fsModuleCache: true,
@@ -81,4 +72,8 @@ describe("loadVitestExperimentalConfig", () => {
},
});
});
it("uses RUNNER_OS to detect Windows even when the platform is not win32", () => {
expect(loadVitestExperimentalConfig({ RUNNER_OS: "Windows" }, "linux")).toEqual({});
});
});

View File

@@ -18,19 +18,24 @@ const isWindowsEnv = (env: EnvMap, platform: NodeJS.Platform): boolean => {
return runnerOs === "windows";
};
export function loadVitestExperimentalConfig(env: EnvMap = process.env): {
type VitestExperimentalConfig = {
experimental?: {
fsModuleCache?: true;
importDurations?: { print: true };
printImportBreakdown?: true;
};
} {
};
export function loadVitestExperimentalConfig(
env: EnvMap = process.env,
platform: NodeJS.Platform = process.platform,
): VitestExperimentalConfig {
const experimental: {
fsModuleCache?: true;
importDurations?: { print: true };
printImportBreakdown?: true;
} = {};
const windowsEnv = isWindowsEnv(env, process.platform);
const windowsEnv = isWindowsEnv(env, platform);
if (!windowsEnv && !isDisabled(env.OPENCLAW_VITEST_FS_MODULE_CACHE)) {
experimental.fsModuleCache = true;