mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 04:47:39 +00:00
chore: migrate to oxlint and oxfmt
Co-authored-by: Christoph Nakazawa <christoph.pojer@gmail.com>
This commit is contained in:
@@ -24,8 +24,7 @@ if (!(globalThis as Record<symbol, unknown>)[CONFIG_KEY]) {
|
||||
}
|
||||
|
||||
export function setLoadConfigMock(fn: unknown) {
|
||||
(globalThis as Record<symbol, unknown>)[CONFIG_KEY] =
|
||||
typeof fn === "function" ? fn : () => fn;
|
||||
(globalThis as Record<symbol, unknown>)[CONFIG_KEY] = typeof fn === "function" ? fn : () => fn;
|
||||
}
|
||||
|
||||
export function resetLoadConfigMock() {
|
||||
@@ -45,21 +44,18 @@ vi.mock("../config/config.js", async (importOriginal) => {
|
||||
});
|
||||
|
||||
vi.mock("../media/store.js", () => ({
|
||||
saveMediaBuffer: vi
|
||||
.fn()
|
||||
.mockImplementation(async (_buf: Buffer, contentType?: string) => ({
|
||||
id: "mid",
|
||||
path: "/tmp/mid",
|
||||
size: _buf.length,
|
||||
contentType,
|
||||
})),
|
||||
saveMediaBuffer: vi.fn().mockImplementation(async (_buf: Buffer, contentType?: string) => ({
|
||||
id: "mid",
|
||||
path: "/tmp/mid",
|
||||
size: _buf.length,
|
||||
contentType,
|
||||
})),
|
||||
}));
|
||||
|
||||
vi.mock("@whiskeysockets/baileys", () => {
|
||||
const created = createMockBaileys();
|
||||
(globalThis as Record<PropertyKey, unknown>)[
|
||||
Symbol.for("clawdbot:lastSocket")
|
||||
] = created.lastSocket;
|
||||
(globalThis as Record<PropertyKey, unknown>)[Symbol.for("clawdbot:lastSocket")] =
|
||||
created.lastSocket;
|
||||
return created.mod;
|
||||
});
|
||||
|
||||
@@ -68,38 +64,27 @@ vi.mock("qrcode-terminal", () => ({
|
||||
generate: vi.fn(),
|
||||
}));
|
||||
|
||||
export const baileys = (await import(
|
||||
"@whiskeysockets/baileys"
|
||||
)) as unknown as typeof import("@whiskeysockets/baileys") & {
|
||||
makeWASocket: ReturnType<typeof vi.fn>;
|
||||
useMultiFileAuthState: ReturnType<typeof vi.fn>;
|
||||
fetchLatestBaileysVersion: ReturnType<typeof vi.fn>;
|
||||
makeCacheableSignalKeyStore: ReturnType<typeof vi.fn>;
|
||||
};
|
||||
export const baileys =
|
||||
(await import("@whiskeysockets/baileys")) as unknown as typeof import("@whiskeysockets/baileys") & {
|
||||
makeWASocket: ReturnType<typeof vi.fn>;
|
||||
useMultiFileAuthState: ReturnType<typeof vi.fn>;
|
||||
fetchLatestBaileysVersion: ReturnType<typeof vi.fn>;
|
||||
makeCacheableSignalKeyStore: ReturnType<typeof vi.fn>;
|
||||
};
|
||||
|
||||
export function resetBaileysMocks() {
|
||||
const recreated = createMockBaileys();
|
||||
(globalThis as Record<PropertyKey, unknown>)[
|
||||
Symbol.for("clawdbot:lastSocket")
|
||||
] = recreated.lastSocket;
|
||||
(globalThis as Record<PropertyKey, unknown>)[Symbol.for("clawdbot:lastSocket")] =
|
||||
recreated.lastSocket;
|
||||
baileys.makeWASocket.mockImplementation(recreated.mod.makeWASocket);
|
||||
baileys.useMultiFileAuthState.mockImplementation(
|
||||
recreated.mod.useMultiFileAuthState,
|
||||
);
|
||||
baileys.fetchLatestBaileysVersion.mockImplementation(
|
||||
recreated.mod.fetchLatestBaileysVersion,
|
||||
);
|
||||
baileys.makeCacheableSignalKeyStore.mockImplementation(
|
||||
recreated.mod.makeCacheableSignalKeyStore,
|
||||
);
|
||||
baileys.useMultiFileAuthState.mockImplementation(recreated.mod.useMultiFileAuthState);
|
||||
baileys.fetchLatestBaileysVersion.mockImplementation(recreated.mod.fetchLatestBaileysVersion);
|
||||
baileys.makeCacheableSignalKeyStore.mockImplementation(recreated.mod.makeCacheableSignalKeyStore);
|
||||
}
|
||||
|
||||
export function getLastSocket(): MockBaileysSocket {
|
||||
const getter = (globalThis as Record<PropertyKey, unknown>)[
|
||||
Symbol.for("clawdbot:lastSocket")
|
||||
];
|
||||
if (typeof getter === "function")
|
||||
return (getter as () => MockBaileysSocket)();
|
||||
const getter = (globalThis as Record<PropertyKey, unknown>)[Symbol.for("clawdbot:lastSocket")];
|
||||
if (typeof getter === "function") return (getter as () => MockBaileysSocket)();
|
||||
if (!getter) throw new Error("Baileys mock not initialized");
|
||||
throw new Error("Invalid Baileys socket getter");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user