Tests: harden WhatsApp inbound contract cleanup

This commit is contained in:
Vincent Koc
2026-03-16 01:37:38 -07:00
parent a8970963cd
commit 65f05d7c09

View File

@@ -74,13 +74,27 @@ function makeProcessArgs(sessionStorePath: string) {
} as any;
}
async function removeDirEventually(dir: string) {
for (let attempt = 0; attempt < 3; attempt += 1) {
try {
await fs.rm(dir, { recursive: true, force: true });
return;
} catch (error) {
if ((error as NodeJS.ErrnoException).code !== "ENOTEMPTY" || attempt === 2) {
throw error;
}
await new Promise((resolve) => setTimeout(resolve, 25));
}
}
}
describe("whatsapp inbound contract", () => {
let sessionDir = "";
afterEach(async () => {
capture.ctx = undefined;
if (sessionDir) {
await fs.rm(sessionDir, { recursive: true, force: true });
await removeDirEventually(sessionDir);
sessionDir = "";
}
});