mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-18 16:47:27 +00:00
perf(test): reduce module reload overhead in key suites
This commit is contained in:
@@ -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] });
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user