diff --git a/src/utils.test.ts b/src/utils.test.ts index def788d198a..d958e0a26ec 100644 --- a/src/utils.test.ts +++ b/src/utils.test.ts @@ -18,10 +18,13 @@ import { toWhatsappJid, } from "./utils.js"; -function withTempDirSync(prefix: string, run: (dir: string) => T): T { +async function withTempDir( + prefix: string, + run: (dir: string) => T | Promise, +): Promise> { const dir = fs.mkdtempSync(path.join(os.tmpdir(), prefix)); try { - return run(dir); + return await run(dir); } finally { fs.rmSync(dir, { recursive: true, force: true }); } @@ -29,7 +32,7 @@ function withTempDirSync(prefix: string, run: (dir: string) => T): T { describe("ensureDir", () => { it("creates nested directory", async () => { - await withTempDirSync("openclaw-test-", async (tmp) => { + await withTempDir("openclaw-test-", async (tmp) => { const target = path.join(tmp, "nested", "dir"); await ensureDir(target); expect(fs.existsSync(target)).toBe(true); @@ -84,16 +87,16 @@ describe("jidToE164", () => { spy.mockRestore(); }); - it("maps @lid from authDir mapping files", () => { - withTempDirSync("openclaw-auth-", (authDir) => { + it("maps @lid from authDir mapping files", async () => { + await withTempDir("openclaw-auth-", (authDir) => { const mappingPath = path.join(authDir, "lid-mapping-456_reverse.json"); fs.writeFileSync(mappingPath, JSON.stringify("5559876")); expect(jidToE164("456@lid", { authDir })).toBe("+5559876"); }); }); - it("maps @hosted.lid from authDir mapping files", () => { - withTempDirSync("openclaw-auth-", (authDir) => { + it("maps @hosted.lid from authDir mapping files", async () => { + await withTempDir("openclaw-auth-", (authDir) => { const mappingPath = path.join(authDir, "lid-mapping-789_reverse.json"); fs.writeFileSync(mappingPath, JSON.stringify(4440001)); expect(jidToE164("789@hosted.lid", { authDir })).toBe("+4440001"); @@ -104,9 +107,9 @@ describe("jidToE164", () => { expect(jidToE164("1555000:2@hosted")).toBe("+1555000"); }); - it("falls back through lidMappingDirs in order", () => { - withTempDirSync("openclaw-lid-a-", (first) => { - withTempDirSync("openclaw-lid-b-", (second) => { + it("falls back through lidMappingDirs in order", async () => { + await withTempDir("openclaw-lid-a-", async (first) => { + await withTempDir("openclaw-lid-b-", (second) => { const mappingPath = path.join(second, "lid-mapping-321_reverse.json"); fs.writeFileSync(mappingPath, JSON.stringify("123321")); expect(jidToE164("321@lid", { lidMappingDirs: [first, second] })).toBe("+123321");