test(scripts): add async temp dir helper

This commit is contained in:
Vincent Koc
2026-04-06 05:37:38 +01:00
parent 2272eb9ffa
commit 319217a30d
2 changed files with 12 additions and 11 deletions

View File

@@ -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;

View File

@@ -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,
};
}