mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 09:11:37 +00:00
perf(test): speed up suites and reduce fs churn
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import {
|
||||
clearInternalHooks,
|
||||
@@ -12,13 +12,19 @@ import {
|
||||
import { loadInternalHooks } from "./loader.js";
|
||||
|
||||
describe("loader", () => {
|
||||
let fixtureRoot = "";
|
||||
let caseId = 0;
|
||||
let tmpDir: string;
|
||||
let originalBundledDir: string | undefined;
|
||||
|
||||
beforeAll(async () => {
|
||||
fixtureRoot = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-hooks-loader-"));
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
clearInternalHooks();
|
||||
// Create a temp directory for test modules
|
||||
tmpDir = path.join(os.tmpdir(), `openclaw-test-${Date.now()}`);
|
||||
tmpDir = path.join(fixtureRoot, `case-${caseId++}`);
|
||||
await fs.mkdir(tmpDir, { recursive: true });
|
||||
|
||||
// Disable bundled hooks during tests by setting env var to non-existent directory
|
||||
@@ -34,12 +40,13 @@ describe("loader", () => {
|
||||
} else {
|
||||
process.env.OPENCLAW_BUNDLED_HOOKS_DIR = originalBundledDir;
|
||||
}
|
||||
// Clean up temp directory
|
||||
try {
|
||||
await fs.rm(tmpDir, { recursive: true, force: true });
|
||||
} catch {
|
||||
// Ignore cleanup errors
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
if (!fixtureRoot) {
|
||||
return;
|
||||
}
|
||||
await fs.rm(fixtureRoot, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
describe("loadInternalHooks", () => {
|
||||
|
||||
Reference in New Issue
Block a user