mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-13 10:11:20 +00:00
41 lines
965 B
TypeScript
41 lines
965 B
TypeScript
import { mkdtempSync, type RmOptions } from "node:fs";
|
|
import { mkdtemp, rm } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import path from "node:path";
|
|
import { afterEach } from "vitest";
|
|
|
|
export function createPluginSdkTestHarness(options?: { cleanup?: RmOptions }) {
|
|
const tempDirs: string[] = [];
|
|
|
|
afterEach(async () => {
|
|
while (tempDirs.length > 0) {
|
|
const dir = tempDirs.pop();
|
|
if (!dir) {
|
|
continue;
|
|
}
|
|
await rm(dir, {
|
|
recursive: true,
|
|
force: true,
|
|
...options?.cleanup,
|
|
});
|
|
}
|
|
});
|
|
|
|
async function createTempDir(prefix: string): Promise<string> {
|
|
const dir = await mkdtemp(path.join(tmpdir(), prefix));
|
|
tempDirs.push(dir);
|
|
return dir;
|
|
}
|
|
|
|
function createTempDirSync(prefix: string): string {
|
|
const dir = mkdtempSync(path.join(tmpdir(), prefix));
|
|
tempDirs.push(dir);
|
|
return dir;
|
|
}
|
|
|
|
return {
|
|
createTempDir,
|
|
createTempDirSync,
|
|
};
|
|
}
|