mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-25 23:47:20 +00:00
test(scripts): add async temp dir helper
This commit is contained in:
@@ -1,24 +1,17 @@
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
createNestedNpmInstallEnv,
|
||||
discoverBundledPluginRuntimeDeps,
|
||||
runBundledPluginPostinstall,
|
||||
} from "../../scripts/postinstall-bundled-plugins.mjs";
|
||||
import { createScriptTestHarness } from "./test-helpers.js";
|
||||
|
||||
const cleanupDirs: string[] = [];
|
||||
|
||||
afterEach(async () => {
|
||||
await Promise.all(
|
||||
cleanupDirs.splice(0).map((dir) => fs.rm(dir, { recursive: true, force: true })),
|
||||
);
|
||||
});
|
||||
const { createTempDirAsync } = createScriptTestHarness();
|
||||
|
||||
async function createExtensionsDir() {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-postinstall-"));
|
||||
cleanupDirs.push(root);
|
||||
const root = await createTempDirAsync("openclaw-postinstall-");
|
||||
const extensionsDir = path.join(root, "dist", "extensions");
|
||||
await fs.mkdir(extensionsDir, { recursive: true });
|
||||
return extensionsDir;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import fs from "node:fs";
|
||||
import fsPromises from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach } from "vitest";
|
||||
@@ -21,6 +22,12 @@ export function createScriptTestHarness() {
|
||||
return dir;
|
||||
}
|
||||
|
||||
async function createTempDirAsync(prefix: string): Promise<string> {
|
||||
const dir = await fsPromises.mkdtemp(path.join(os.tmpdir(), prefix));
|
||||
tempDirs.push(dir);
|
||||
return dir;
|
||||
}
|
||||
|
||||
function trackTempDir(dir: string): string {
|
||||
tempDirs.push(dir);
|
||||
return dir;
|
||||
@@ -28,6 +35,7 @@ export function createScriptTestHarness() {
|
||||
|
||||
return {
|
||||
createTempDir,
|
||||
createTempDirAsync,
|
||||
trackTempDir,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user