mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 14:41:24 +00:00
perf(test): remove resetModules from config/sandbox/message suites
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { ChannelOutboundAdapter, ChannelPlugin } from "../../channels/plugins/types.js";
|
||||
import { setActivePluginRegistry } from "../../plugins/runtime.js";
|
||||
import { createIMessageTestPlugin, createTestRegistry } from "../../test-utils/channel-plugins.js";
|
||||
const loadMessage = async () => await import("./message.js");
|
||||
import { sendMessage, sendPoll } from "./message.js";
|
||||
|
||||
const setRegistry = async (registry: ReturnType<typeof createTestRegistry>) => {
|
||||
const { setActivePluginRegistry } = await import("../../plugins/runtime.js");
|
||||
const setRegistry = (registry: ReturnType<typeof createTestRegistry>) => {
|
||||
setActivePluginRegistry(registry);
|
||||
};
|
||||
|
||||
@@ -15,23 +15,21 @@ vi.mock("../../gateway/call.js", () => ({
|
||||
}));
|
||||
|
||||
describe("sendMessage channel normalization", () => {
|
||||
beforeEach(async () => {
|
||||
beforeEach(() => {
|
||||
callGatewayMock.mockReset();
|
||||
vi.resetModules();
|
||||
await setRegistry(emptyRegistry);
|
||||
setRegistry(emptyRegistry);
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await setRegistry(emptyRegistry);
|
||||
afterEach(() => {
|
||||
setRegistry(emptyRegistry);
|
||||
});
|
||||
|
||||
it("normalizes Teams alias", async () => {
|
||||
const { sendMessage } = await loadMessage();
|
||||
const sendMSTeams = vi.fn(async () => ({
|
||||
messageId: "m1",
|
||||
conversationId: "c1",
|
||||
}));
|
||||
await setRegistry(
|
||||
setRegistry(
|
||||
createTestRegistry([
|
||||
{
|
||||
pluginId: "msteams",
|
||||
@@ -56,9 +54,8 @@ describe("sendMessage channel normalization", () => {
|
||||
});
|
||||
|
||||
it("normalizes iMessage alias", async () => {
|
||||
const { sendMessage } = await loadMessage();
|
||||
const sendIMessage = vi.fn(async () => ({ messageId: "i1" }));
|
||||
await setRegistry(
|
||||
setRegistry(
|
||||
createTestRegistry([
|
||||
{
|
||||
pluginId: "imessage",
|
||||
@@ -81,25 +78,23 @@ describe("sendMessage channel normalization", () => {
|
||||
});
|
||||
|
||||
describe("sendMessage replyToId threading", () => {
|
||||
beforeEach(async () => {
|
||||
beforeEach(() => {
|
||||
callGatewayMock.mockReset();
|
||||
vi.resetModules();
|
||||
await setRegistry(emptyRegistry);
|
||||
setRegistry(emptyRegistry);
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await setRegistry(emptyRegistry);
|
||||
afterEach(() => {
|
||||
setRegistry(emptyRegistry);
|
||||
});
|
||||
|
||||
it("passes replyToId through to the outbound adapter", async () => {
|
||||
const { sendMessage } = await loadMessage();
|
||||
const capturedCtx: Record<string, unknown>[] = [];
|
||||
const plugin = createMattermostLikePlugin({
|
||||
onSendText: (ctx) => {
|
||||
capturedCtx.push(ctx);
|
||||
},
|
||||
});
|
||||
await setRegistry(createTestRegistry([{ pluginId: "mattermost", source: "test", plugin }]));
|
||||
setRegistry(createTestRegistry([{ pluginId: "mattermost", source: "test", plugin }]));
|
||||
|
||||
await sendMessage({
|
||||
cfg: {},
|
||||
@@ -114,14 +109,13 @@ describe("sendMessage replyToId threading", () => {
|
||||
});
|
||||
|
||||
it("passes threadId through to the outbound adapter", async () => {
|
||||
const { sendMessage } = await loadMessage();
|
||||
const capturedCtx: Record<string, unknown>[] = [];
|
||||
const plugin = createMattermostLikePlugin({
|
||||
onSendText: (ctx) => {
|
||||
capturedCtx.push(ctx);
|
||||
},
|
||||
});
|
||||
await setRegistry(createTestRegistry([{ pluginId: "mattermost", source: "test", plugin }]));
|
||||
setRegistry(createTestRegistry([{ pluginId: "mattermost", source: "test", plugin }]));
|
||||
|
||||
await sendMessage({
|
||||
cfg: {},
|
||||
@@ -137,20 +131,18 @@ describe("sendMessage replyToId threading", () => {
|
||||
});
|
||||
|
||||
describe("sendPoll channel normalization", () => {
|
||||
beforeEach(async () => {
|
||||
beforeEach(() => {
|
||||
callGatewayMock.mockReset();
|
||||
vi.resetModules();
|
||||
await setRegistry(emptyRegistry);
|
||||
setRegistry(emptyRegistry);
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await setRegistry(emptyRegistry);
|
||||
afterEach(() => {
|
||||
setRegistry(emptyRegistry);
|
||||
});
|
||||
|
||||
it("normalizes Teams alias for polls", async () => {
|
||||
const { sendPoll } = await loadMessage();
|
||||
callGatewayMock.mockResolvedValueOnce({ messageId: "p1" });
|
||||
await setRegistry(
|
||||
setRegistry(
|
||||
createTestRegistry([
|
||||
{
|
||||
pluginId: "msteams",
|
||||
|
||||
Reference in New Issue
Block a user