mirror of https://github.com/openclaw/openclaw.git
test: speed up slack and telegram suites
This commit is contained in:
parent
b11f4835e2
commit
4518f6e820
|
|
@ -180,31 +180,22 @@ vi.mock("./slash-commands.runtime.js", () => {
|
|||
});
|
||||
|
||||
type RegisterFn = (params: { ctx: unknown; account: unknown }) => Promise<void>;
|
||||
let registerSlackMonitorSlashCommandsPromise: Promise<RegisterFn> | undefined;
|
||||
|
||||
async function loadRegisterSlackMonitorSlashCommands(): Promise<RegisterFn> {
|
||||
registerSlackMonitorSlashCommandsPromise ??= import("./slash.js").then((module) => {
|
||||
const typed = module as unknown as {
|
||||
registerSlackMonitorSlashCommands: RegisterFn;
|
||||
};
|
||||
return typed.registerSlackMonitorSlashCommands;
|
||||
});
|
||||
return await registerSlackMonitorSlashCommandsPromise;
|
||||
}
|
||||
let registerSlackMonitorSlashCommands: RegisterFn;
|
||||
|
||||
const { dispatchMock } = getSlackSlashMocks();
|
||||
|
||||
beforeAll(() => {
|
||||
beforeAll(async () => {
|
||||
vi.resetModules();
|
||||
({ registerSlackMonitorSlashCommands } = (await import("./slash.js")) as {
|
||||
registerSlackMonitorSlashCommands: RegisterFn;
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
registerSlackMonitorSlashCommandsPromise = undefined;
|
||||
beforeEach(() => {
|
||||
resetSlackSlashMocks();
|
||||
});
|
||||
|
||||
async function registerCommands(ctx: unknown, account: unknown) {
|
||||
const registerSlackMonitorSlashCommands = await loadRegisterSlackMonitorSlashCommands();
|
||||
await registerSlackMonitorSlashCommands({ ctx: ctx as never, account: account as never });
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { createHash } from "node:crypto";
|
|||
import { once } from "node:events";
|
||||
import { request, type IncomingMessage } from "node:http";
|
||||
import { setTimeout as sleep } from "node:timers/promises";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const handlerSpy = vi.hoisted(() => vi.fn((..._args: unknown[]): unknown => undefined));
|
||||
const setWebhookSpy = vi.hoisted(() => vi.fn());
|
||||
|
|
@ -98,11 +98,35 @@ vi.mock("./bot.js", () => ({
|
|||
|
||||
let startTelegramWebhook: typeof import("./webhook.js").startTelegramWebhook;
|
||||
|
||||
beforeEach(async () => {
|
||||
function resetTelegramWebhookMocks(): void {
|
||||
handlerSpy.mockReset();
|
||||
handlerSpy.mockImplementation((..._args: unknown[]): unknown => undefined);
|
||||
|
||||
setWebhookSpy.mockReset();
|
||||
deleteWebhookSpy.mockReset();
|
||||
deleteWebhookSpy.mockImplementation(async () => true);
|
||||
initSpy.mockReset();
|
||||
initSpy.mockImplementation(async () => undefined);
|
||||
stopSpy.mockReset();
|
||||
webhookCallbackSpy.mockReset();
|
||||
webhookCallbackSpy.mockImplementation(() => handlerSpy);
|
||||
createTelegramBotSpy.mockReset();
|
||||
createTelegramBotSpy.mockImplementation(() => ({
|
||||
init: initSpy,
|
||||
api: { setWebhook: setWebhookSpy, deleteWebhook: deleteWebhookSpy },
|
||||
stop: stopSpy,
|
||||
}));
|
||||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
vi.resetModules();
|
||||
({ startTelegramWebhook } = await import("./webhook.js"));
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
resetTelegramWebhookMocks();
|
||||
});
|
||||
|
||||
async function fetchWithTimeout(
|
||||
input: string,
|
||||
init: Omit<RequestInit, "signal">,
|
||||
|
|
|
|||
Loading…
Reference in New Issue