mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-28 21:01:43 +03:00
perf(test): speed up Matrix send tests
This commit is contained in:
@@ -2,6 +2,12 @@ import type { PluginRuntime } from "openclaw/plugin-sdk";
|
|||||||
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import { setMatrixRuntime } from "../runtime.js";
|
import { setMatrixRuntime } from "../runtime.js";
|
||||||
|
|
||||||
|
vi.mock("music-metadata", () => ({
|
||||||
|
// `resolveMediaDurationMs` lazily imports `music-metadata`; in tests we don't
|
||||||
|
// need real duration parsing and the real module is expensive to load.
|
||||||
|
parseBuffer: vi.fn().mockResolvedValue({ format: {} }),
|
||||||
|
}));
|
||||||
|
|
||||||
vi.mock("@vector-im/matrix-bot-sdk", () => ({
|
vi.mock("@vector-im/matrix-bot-sdk", () => ({
|
||||||
ConsoleLogger: class {
|
ConsoleLogger: class {
|
||||||
trace = vi.fn();
|
trace = vi.fn();
|
||||||
@@ -65,12 +71,12 @@ const makeClient = () => {
|
|||||||
return { client, sendMessage, uploadContent };
|
return { client, sendMessage, uploadContent };
|
||||||
};
|
};
|
||||||
|
|
||||||
describe("sendMessageMatrix media", () => {
|
beforeAll(async () => {
|
||||||
beforeAll(async () => {
|
setMatrixRuntime(runtimeStub);
|
||||||
setMatrixRuntime(runtimeStub);
|
({ sendMessageMatrix } = await import("./send.js"));
|
||||||
({ sendMessageMatrix } = await import("./send.js"));
|
});
|
||||||
});
|
|
||||||
|
|
||||||
|
describe("sendMessageMatrix media", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.clearAllMocks();
|
vi.clearAllMocks();
|
||||||
mediaKindFromMimeMock.mockReturnValue("image");
|
mediaKindFromMimeMock.mockReturnValue("image");
|
||||||
@@ -200,11 +206,6 @@ describe("sendMessageMatrix media", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("sendMessageMatrix threads", () => {
|
describe("sendMessageMatrix threads", () => {
|
||||||
beforeAll(async () => {
|
|
||||||
setMatrixRuntime(runtimeStub);
|
|
||||||
({ sendMessageMatrix } = await import("./send.js"));
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.clearAllMocks();
|
vi.clearAllMocks();
|
||||||
setMatrixRuntime(runtimeStub);
|
setMatrixRuntime(runtimeStub);
|
||||||
|
|||||||
Reference in New Issue
Block a user