perf(test): reduce module reload overhead in key suites

This commit is contained in:
Peter Steinberger
2026-02-13 15:45:08 +00:00
parent 4337fa2096
commit 41f2f359a5
12 changed files with 114 additions and 116 deletions

View File

@@ -3,6 +3,7 @@ import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { afterEach, describe, expect, it, vi } from "vitest";
import { discoverOpenClawPlugins } from "./discovery.js";
const tempDirs: string[] = [];
@@ -18,7 +19,6 @@ async function withStateDir<T>(stateDir: string, fn: () => Promise<T>) {
const prevBundled = process.env.OPENCLAW_BUNDLED_PLUGINS_DIR;
process.env.OPENCLAW_STATE_DIR = stateDir;
process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = "/nonexistent/bundled/plugins";
vi.resetModules();
try {
return await fn();
} finally {
@@ -32,7 +32,6 @@ async function withStateDir<T>(stateDir: string, fn: () => Promise<T>) {
} else {
process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = prevBundled;
}
vi.resetModules();
}
}
@@ -60,7 +59,6 @@ describe("discoverOpenClawPlugins", () => {
fs.writeFileSync(path.join(workspaceExt, "beta.ts"), "export default function () {}", "utf-8");
const { candidates } = await withStateDir(stateDir, async () => {
const { discoverOpenClawPlugins } = await import("./discovery.js");
return discoverOpenClawPlugins({ workspaceDir });
});
@@ -94,7 +92,6 @@ describe("discoverOpenClawPlugins", () => {
);
const { candidates } = await withStateDir(stateDir, async () => {
const { discoverOpenClawPlugins } = await import("./discovery.js");
return discoverOpenClawPlugins({});
});
@@ -123,7 +120,6 @@ describe("discoverOpenClawPlugins", () => {
);
const { candidates } = await withStateDir(stateDir, async () => {
const { discoverOpenClawPlugins } = await import("./discovery.js");
return discoverOpenClawPlugins({});
});
@@ -147,7 +143,6 @@ describe("discoverOpenClawPlugins", () => {
fs.writeFileSync(path.join(packDir, "index.js"), "module.exports = {}", "utf-8");
const { candidates } = await withStateDir(stateDir, async () => {
const { discoverOpenClawPlugins } = await import("./discovery.js");
return discoverOpenClawPlugins({ extraPaths: [packDir] });
});