File size: 813 Bytes
fc93158 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
export function createFixtureSuite(rootPrefix: string) {
let fixtureRoot = "";
let fixtureCount = 0;
return {
async setup(): Promise<void> {
fixtureRoot = await fs.mkdtemp(path.join(os.tmpdir(), rootPrefix));
},
async cleanup(): Promise<void> {
if (!fixtureRoot) {
return;
}
await fs.rm(fixtureRoot, { recursive: true, force: true });
fixtureRoot = "";
},
async createCaseDir(prefix: string): Promise<string> {
if (!fixtureRoot) {
throw new Error("Fixture suite not initialized");
}
const dir = path.join(fixtureRoot, `${prefix}-${fixtureCount++}`);
await fs.mkdir(dir, { recursive: true });
return dir;
},
};
}
|