mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-12 14:51:11 +00:00
test(perf): reuse shared temp root in plugin install tests
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
import { randomUUID } from "node:crypto";
|
|
||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
import os from "node:os";
|
import os from "node:os";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
@@ -18,16 +17,25 @@ vi.mock("../process/exec.js", () => ({
|
|||||||
runCommandWithTimeout: vi.fn(),
|
runCommandWithTimeout: vi.fn(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const tempDirs: string[] = [];
|
|
||||||
let installPluginFromArchive: typeof import("./install.js").installPluginFromArchive;
|
let installPluginFromArchive: typeof import("./install.js").installPluginFromArchive;
|
||||||
let installPluginFromDir: typeof import("./install.js").installPluginFromDir;
|
let installPluginFromDir: typeof import("./install.js").installPluginFromDir;
|
||||||
let installPluginFromNpmSpec: typeof import("./install.js").installPluginFromNpmSpec;
|
let installPluginFromNpmSpec: typeof import("./install.js").installPluginFromNpmSpec;
|
||||||
let runCommandWithTimeout: typeof import("../process/exec.js").runCommandWithTimeout;
|
let runCommandWithTimeout: typeof import("../process/exec.js").runCommandWithTimeout;
|
||||||
|
let suiteTempRoot = "";
|
||||||
|
let tempDirCounter = 0;
|
||||||
|
|
||||||
|
function ensureSuiteTempRoot() {
|
||||||
|
if (suiteTempRoot) {
|
||||||
|
return suiteTempRoot;
|
||||||
|
}
|
||||||
|
suiteTempRoot = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-plugin-install-"));
|
||||||
|
return suiteTempRoot;
|
||||||
|
}
|
||||||
|
|
||||||
function makeTempDir() {
|
function makeTempDir() {
|
||||||
const dir = path.join(os.tmpdir(), `openclaw-plugin-install-${randomUUID()}`);
|
const dir = path.join(ensureSuiteTempRoot(), `case-${String(tempDirCounter)}`);
|
||||||
|
tempDirCounter += 1;
|
||||||
fs.mkdirSync(dir, { recursive: true });
|
fs.mkdirSync(dir, { recursive: true });
|
||||||
tempDirs.push(dir);
|
|
||||||
return dir;
|
return dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -288,12 +296,14 @@ async function installArchivePackageAndReturnResult(params: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
for (const dir of tempDirs.splice(0)) {
|
if (!suiteTempRoot) {
|
||||||
try {
|
return;
|
||||||
fs.rmSync(dir, { recursive: true, force: true });
|
}
|
||||||
} catch {
|
try {
|
||||||
// ignore cleanup failures
|
fs.rmSync(suiteTempRoot, { recursive: true, force: true });
|
||||||
}
|
} finally {
|
||||||
|
suiteTempRoot = "";
|
||||||
|
tempDirCounter = 0;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user