perf(test): speed up archive suite

This commit is contained in:
Peter Steinberger
2026-02-14 22:01:17 +00:00
parent b3c3ec4231
commit 221fe499db

View File

@@ -3,25 +3,24 @@ import fs from "node:fs/promises";
import os from "node:os"; import os from "node:os";
import path from "node:path"; import path from "node:path";
import * as tar from "tar"; import * as tar from "tar";
import { afterEach, describe, expect, it } from "vitest"; import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { extractArchive, resolveArchiveKind, resolvePackedRootDir } from "./archive.js"; import { extractArchive, resolveArchiveKind, resolvePackedRootDir } from "./archive.js";
const tempDirs: string[] = []; let fixtureRoot = "";
let fixtureCount = 0;
async function makeTempDir() { async function makeTempDir(prefix = "case") {
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-archive-")); const dir = path.join(fixtureRoot, `${prefix}-${fixtureCount++}`);
tempDirs.push(dir); await fs.mkdir(dir, { recursive: true });
return dir; return dir;
} }
afterEach(async () => { beforeAll(async () => {
for (const dir of tempDirs.splice(0)) { fixtureRoot = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-archive-"));
try { });
await fs.rm(dir, { recursive: true, force: true });
} catch { afterAll(async () => {
// ignore cleanup failures await fs.rm(fixtureRoot, { recursive: true, force: true });
}
}
}); });
describe("archive utils", () => { describe("archive utils", () => {