mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-24 23:21:30 +00:00
test: speed up cli and command suites
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const readFileSyncMock = vi.hoisted(() => vi.fn());
|
||||
|
||||
@@ -19,13 +19,16 @@ vi.mock("../channels/registry.js", () => ({
|
||||
CHAT_CHANNEL_ORDER: ["telegram", "discord"],
|
||||
}));
|
||||
|
||||
async function loadModule() {
|
||||
return await import("./channel-options.js");
|
||||
}
|
||||
let resolveCliChannelOptions: typeof import("./channel-options.js").resolveCliChannelOptions;
|
||||
let __testing: typeof import("./channel-options.js").__testing;
|
||||
|
||||
beforeAll(async () => {
|
||||
({ resolveCliChannelOptions, __testing } = await import("./channel-options.js"));
|
||||
});
|
||||
|
||||
describe("resolveCliChannelOptions", () => {
|
||||
afterEach(() => {
|
||||
vi.resetModules();
|
||||
__testing.resetPrecomputedChannelOptionsForTests();
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
@@ -34,8 +37,7 @@ describe("resolveCliChannelOptions", () => {
|
||||
JSON.stringify({ channelOptions: ["cached", "telegram", "cached"] }),
|
||||
);
|
||||
|
||||
const mod = await loadModule();
|
||||
expect(mod.resolveCliChannelOptions()).toEqual(["cached", "telegram"]);
|
||||
expect(resolveCliChannelOptions()).toEqual(["cached", "telegram"]);
|
||||
});
|
||||
|
||||
it("falls back to core channel order when metadata is missing", async () => {
|
||||
@@ -43,16 +45,14 @@ describe("resolveCliChannelOptions", () => {
|
||||
throw new Error("ENOENT");
|
||||
});
|
||||
|
||||
const mod = await loadModule();
|
||||
expect(mod.resolveCliChannelOptions()).toEqual(["telegram", "discord"]);
|
||||
expect(resolveCliChannelOptions()).toEqual(["telegram", "discord"]);
|
||||
});
|
||||
|
||||
it("ignores external catalog env during CLI bootstrap", async () => {
|
||||
process.env.OPENCLAW_PLUGIN_CATALOG_PATHS = "/tmp/plugins-catalog.json";
|
||||
readFileSyncMock.mockReturnValue(JSON.stringify({ channelOptions: ["cached", "telegram"] }));
|
||||
|
||||
const mod = await loadModule();
|
||||
expect(mod.resolveCliChannelOptions()).toEqual(["cached", "telegram"]);
|
||||
expect(resolveCliChannelOptions()).toEqual(["cached", "telegram"]);
|
||||
delete process.env.OPENCLAW_PLUGIN_CATALOG_PATHS;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -51,3 +51,9 @@ export function resolveCliChannelOptions(): string[] {
|
||||
export function formatCliChannelOptions(extra: string[] = []): string {
|
||||
return [...extra, ...resolveCliChannelOptions()].join("|");
|
||||
}
|
||||
|
||||
export const __testing = {
|
||||
resetPrecomputedChannelOptionsForTests(): void {
|
||||
precomputedChannelOptions = undefined;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -64,7 +64,6 @@ function mockSnapshot(token: unknown = "abc") {
|
||||
|
||||
describe("dashboardCommand", () => {
|
||||
beforeAll(async () => {
|
||||
vi.resetModules();
|
||||
({ dashboardCommand } = await import("./dashboard.js"));
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user