mirror of https://github.com/openclaw/openclaw.git
34 lines
688 B
TypeScript
34 lines
688 B
TypeScript
import fs from "node:fs";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { afterEach } from "vitest";
|
|
|
|
export function createScriptTestHarness() {
|
|
const tempDirs: string[] = [];
|
|
|
|
afterEach(() => {
|
|
while (tempDirs.length > 0) {
|
|
const dir = tempDirs.pop();
|
|
if (dir) {
|
|
fs.rmSync(dir, { recursive: true, force: true });
|
|
}
|
|
}
|
|
});
|
|
|
|
function createTempDir(prefix: string): string {
|
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
|
|
tempDirs.push(dir);
|
|
return dir;
|
|
}
|
|
|
|
function trackTempDir(dir: string): string {
|
|
tempDirs.push(dir);
|
|
return dir;
|
|
}
|
|
|
|
return {
|
|
createTempDir,
|
|
trackTempDir,
|
|
};
|
|
}
|