mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-27 09:21:35 +07:00
test: make vitest config tests platform-aware
This commit is contained in:
@@ -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({});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user