test(plugins): share suite temp root helper in install path tests

This commit is contained in:
Vincent Koc
2026-04-06 05:53:53 +01:00
parent 17d7483404
commit c75cdf6b0b
3 changed files with 60 additions and 70 deletions

View File

@@ -50,3 +50,43 @@ export async function cleanupTrackedTempDirsAsync(trackedDirs: string[]) {
}),
);
}
export function createSuiteTempRootTracker(prefix: string) {
let suiteTempRoot = "";
let tempDirCounter = 0;
function ensureSuiteTempRoot() {
if (suiteTempRoot) {
return suiteTempRoot;
}
const bundleTempRoot = path.join(process.cwd(), ".tmp");
fs.mkdirSync(bundleTempRoot, { recursive: true });
suiteTempRoot = fs.mkdtempSync(path.join(bundleTempRoot, String(prefix) + "-"));
return suiteTempRoot;
}
function makeTempDir() {
const dir = path.join(ensureSuiteTempRoot(), `case-${String(tempDirCounter)}`);
tempDirCounter += 1;
fs.mkdirSync(dir);
return dir;
}
function cleanup() {
if (!suiteTempRoot) {
return;
}
try {
fs.rmSync(suiteTempRoot, { recursive: true, force: true });
} finally {
suiteTempRoot = "";
tempDirCounter = 0;
}
}
return {
cleanup,
ensureSuiteTempRoot,
makeTempDir,
};
}