test(tooling): reuse temp dir helpers in script tests

This commit is contained in:
Vincent Koc 2026-04-06 05:45:36 +01:00
parent 2cffbc4854
commit 859c8133c0
3 changed files with 9 additions and 15 deletions

View File

@ -1,8 +1,8 @@
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import { copyA2uiAssets } from "../../scripts/canvas-a2ui-copy.js";
import { withTempDir } from "../test-utils/temp-dir.js";
const ORIGINAL_SKIP_MISSING = process.env.OPENCLAW_A2UI_SKIP_MISSING;
const ORIGINAL_SPARSE_PROFILE = process.env.OPENCLAW_SPARSE_PROFILE;
@ -23,12 +23,7 @@ describe("canvas a2ui copy", () => {
});
async function withA2uiFixture(run: (dir: string) => Promise<void>) {
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-a2ui-"));
try {
await run(dir);
} finally {
await fs.rm(dir, { recursive: true, force: true });
}
await withTempDir("openclaw-a2ui-", run);
}
it("throws a helpful error when assets are missing", async () => {

View File

@ -2,6 +2,7 @@ import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { describe, expect, it } from "vitest";
import { cleanupTempDirs, makeTempDir } from "../../test/helpers/temp-dir.js";
const {
normalizeRoute,
@ -95,7 +96,8 @@ describe("docs-link-audit", () => {
});
it("builds an English-only docs tree for anchor audits", () => {
const fixtureRoot = fs.mkdtempSync(path.join(os.tmpdir(), "docs-link-audit-fixture-"));
const tempDirs: string[] = [];
const fixtureRoot = makeTempDir(tempDirs, "docs-link-audit-fixture-");
const docsRoot = path.join(fixtureRoot, "docs");
fs.mkdirSync(path.join(docsRoot, "help"), { recursive: true });
fs.mkdirSync(path.join(docsRoot, "zh-CN", "help"), { recursive: true });
@ -140,7 +142,7 @@ describe("docs-link-audit", () => {
});
} finally {
fs.rmSync(anchorDocsDir, { recursive: true, force: true });
fs.rmSync(fixtureRoot, { recursive: true, force: true });
cleanupTempDirs(tempDirs);
}
});

View File

@ -1,8 +1,8 @@
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import { syncPluginVersions } from "../../scripts/sync-plugin-versions.js";
import { cleanupTempDirs, makeTempDir } from "../../test/helpers/temp-dir.js";
const tempDirs: string[] = [];
@ -13,14 +13,11 @@ function writeJson(filePath: string, value: unknown) {
describe("syncPluginVersions", () => {
afterEach(() => {
for (const dir of tempDirs.splice(0)) {
fs.rmSync(dir, { recursive: true, force: true });
}
cleanupTempDirs(tempDirs);
});
it("preserves workspace openclaw devDependencies while bumping plugin host constraints", () => {
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-sync-plugin-versions-"));
tempDirs.push(rootDir);
const rootDir = makeTempDir(tempDirs, "openclaw-sync-plugin-versions-");
writeJson(path.join(rootDir, "package.json"), {
name: "openclaw",