perf(test): speed up config tests

This commit is contained in:
Peter Steinberger
2026-02-14 14:25:22 +00:00
parent 788ea6e9d1
commit 57f40a5da6
6 changed files with 225 additions and 270 deletions

View File

@@ -0,0 +1,26 @@
export const CONFIG_BACKUP_COUNT = 5;
export async function rotateConfigBackups(
configPath: string,
ioFs: {
unlink: (path: string) => Promise<void>;
rename: (from: string, to: string) => Promise<void>;
},
): Promise<void> {
if (CONFIG_BACKUP_COUNT <= 1) {
return;
}
const backupBase = `${configPath}.bak`;
const maxIndex = CONFIG_BACKUP_COUNT - 1;
await ioFs.unlink(`${backupBase}.${maxIndex}`).catch(() => {
// best-effort
});
for (let index = maxIndex - 1; index >= 1; index -= 1) {
await ioFs.rename(`${backupBase}.${index}`, `${backupBase}.${index + 1}`).catch(() => {
// best-effort
});
}
await ioFs.rename(backupBase, `${backupBase}.1`).catch(() => {
// best-effort
});
}