mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-28 17:43:05 +00:00
test(plugins): share suite temp root helper in install path tests
This commit is contained in:
@@ -50,3 +50,43 @@ export async function cleanupTrackedTempDirsAsync(trackedDirs: string[]) {
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function createSuiteTempRootTracker(prefix: string) {
|
||||
let suiteTempRoot = "";
|
||||
let tempDirCounter = 0;
|
||||
|
||||
function ensureSuiteTempRoot() {
|
||||
if (suiteTempRoot) {
|
||||
return suiteTempRoot;
|
||||
}
|
||||
const bundleTempRoot = path.join(process.cwd(), ".tmp");
|
||||
fs.mkdirSync(bundleTempRoot, { recursive: true });
|
||||
suiteTempRoot = fs.mkdtempSync(path.join(bundleTempRoot, String(prefix) + "-"));
|
||||
return suiteTempRoot;
|
||||
}
|
||||
|
||||
function makeTempDir() {
|
||||
const dir = path.join(ensureSuiteTempRoot(), `case-${String(tempDirCounter)}`);
|
||||
tempDirCounter += 1;
|
||||
fs.mkdirSync(dir);
|
||||
return dir;
|
||||
}
|
||||
|
||||
function cleanup() {
|
||||
if (!suiteTempRoot) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
fs.rmSync(suiteTempRoot, { recursive: true, force: true });
|
||||
} finally {
|
||||
suiteTempRoot = "";
|
||||
tempDirCounter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
cleanup,
|
||||
ensureSuiteTempRoot,
|
||||
makeTempDir,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user