forked from openclaw/openclaw
-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathvitest.performance-config.ts
More file actions
59 lines (52 loc) · 1.83 KB
/
vitest.performance-config.ts
File metadata and controls
59 lines (52 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
type EnvMap = Record<string, string | undefined>;
const isEnabled = (value: string | undefined): boolean => {
const normalized = value?.trim().toLowerCase();
return normalized === "1" || normalized === "true";
};
const isDisabled = (value: string | undefined): boolean => {
const normalized = value?.trim().toLowerCase();
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";
};
type VitestExperimentalConfig = {
experimental?: {
fsModuleCache?: true;
fsModuleCachePath?: string;
importDurations?: { print: true };
printImportBreakdown?: true;
};
};
export function loadVitestExperimentalConfig(
env: EnvMap = process.env,
platform: NodeJS.Platform = process.platform,
): VitestExperimentalConfig {
const experimental: {
fsModuleCache?: true;
fsModuleCachePath?: string;
importDurations?: { print: true };
printImportBreakdown?: true;
} = {};
const windowsEnv = isWindowsEnv(env, platform);
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 (experimental.fsModuleCache && env.OPENCLAW_VITEST_FS_MODULE_CACHE_PATH?.trim()) {
experimental.fsModuleCachePath = env.OPENCLAW_VITEST_FS_MODULE_CACHE_PATH.trim();
}
if (isEnabled(env.OPENCLAW_VITEST_IMPORT_DURATIONS)) {
experimental.importDurations = { print: true };
}
if (isEnabled(env.OPENCLAW_VITEST_PRINT_IMPORT_BREAKDOWN)) {
experimental.printImportBreakdown = true;
}
return Object.keys(experimental).length > 0 ? { experimental } : {};
}