mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
test: isolate vitest home
This commit is contained in:
@@ -68,6 +68,7 @@
|
|||||||
### Tests
|
### Tests
|
||||||
- Coverage added for models config merging, WhatsApp reply context, QR login flows, auto-reply behavior, and gateway SIGTERM timeouts.
|
- Coverage added for models config merging, WhatsApp reply context, QR login flows, auto-reply behavior, and gateway SIGTERM timeouts.
|
||||||
- Added gateway webhook coverage (auth, validation, and summary posting).
|
- Added gateway webhook coverage (auth, validation, and summary posting).
|
||||||
|
- Vitest now isolates HOME/XDG config roots so tests never touch a real `~/.clawdis` install.
|
||||||
|
|
||||||
## 2.0.0-beta2 — 2025-12-21
|
## 2.0.0-beta2 — 2025-12-21
|
||||||
|
|
||||||
|
|||||||
40
test/setup.ts
Normal file
40
test/setup.ts
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import fs from "node:fs";
|
||||||
|
import os from "node:os";
|
||||||
|
import path from "node:path";
|
||||||
|
|
||||||
|
const originalHome = process.env.HOME;
|
||||||
|
const originalUserProfile = process.env.USERPROFILE;
|
||||||
|
const originalXdgConfigHome = process.env.XDG_CONFIG_HOME;
|
||||||
|
const originalXdgDataHome = process.env.XDG_DATA_HOME;
|
||||||
|
const originalXdgStateHome = process.env.XDG_STATE_HOME;
|
||||||
|
const originalXdgCacheHome = process.env.XDG_CACHE_HOME;
|
||||||
|
const originalTestHome = process.env.CLAWDIS_TEST_HOME;
|
||||||
|
|
||||||
|
const tempHome = fs.mkdtempSync(path.join(os.tmpdir(), "clawdis-test-home-"));
|
||||||
|
process.env.HOME = tempHome;
|
||||||
|
process.env.USERPROFILE = tempHome;
|
||||||
|
process.env.CLAWDIS_TEST_HOME = tempHome;
|
||||||
|
process.env.XDG_CONFIG_HOME = path.join(tempHome, ".config");
|
||||||
|
process.env.XDG_DATA_HOME = path.join(tempHome, ".local", "share");
|
||||||
|
process.env.XDG_STATE_HOME = path.join(tempHome, ".local", "state");
|
||||||
|
process.env.XDG_CACHE_HOME = path.join(tempHome, ".cache");
|
||||||
|
|
||||||
|
const restoreEnv = (key: string, value: string | undefined) => {
|
||||||
|
if (value === undefined) delete process.env[key];
|
||||||
|
else process.env[key] = value;
|
||||||
|
};
|
||||||
|
|
||||||
|
process.on("exit", () => {
|
||||||
|
restoreEnv("HOME", originalHome);
|
||||||
|
restoreEnv("USERPROFILE", originalUserProfile);
|
||||||
|
restoreEnv("XDG_CONFIG_HOME", originalXdgConfigHome);
|
||||||
|
restoreEnv("XDG_DATA_HOME", originalXdgDataHome);
|
||||||
|
restoreEnv("XDG_STATE_HOME", originalXdgStateHome);
|
||||||
|
restoreEnv("XDG_CACHE_HOME", originalXdgCacheHome);
|
||||||
|
restoreEnv("CLAWDIS_TEST_HOME", originalTestHome);
|
||||||
|
try {
|
||||||
|
fs.rmSync(tempHome, { recursive: true, force: true });
|
||||||
|
} catch {
|
||||||
|
// ignore cleanup errors
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -3,6 +3,7 @@ import { defineConfig } from "vitest/config";
|
|||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
test: {
|
test: {
|
||||||
include: ["src/**/*.test.ts", "test/format-error.test.ts"],
|
include: ["src/**/*.test.ts", "test/format-error.test.ts"],
|
||||||
|
setupFiles: ["test/setup.ts"],
|
||||||
exclude: [
|
exclude: [
|
||||||
"dist/**",
|
"dist/**",
|
||||||
"apps/macos/**",
|
"apps/macos/**",
|
||||||
|
|||||||
Reference in New Issue
Block a user