mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-29 01:31:18 +00:00
test: streamline runtime wrapper test reloads
This commit is contained in:
@@ -1,21 +1,15 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { createStorageMock } from "../../test-helpers/storage.ts";
|
||||
import * as translate from "../lib/translate.ts";
|
||||
import { pt_BR } from "../locales/pt-BR.ts";
|
||||
import { zh_CN } from "../locales/zh-CN.ts";
|
||||
import { zh_TW } from "../locales/zh-TW.ts";
|
||||
|
||||
type TranslateModule = typeof import("../lib/translate.ts");
|
||||
|
||||
describe("i18n", () => {
|
||||
let translate: TranslateModule;
|
||||
|
||||
beforeEach(async () => {
|
||||
vi.resetModules();
|
||||
vi.stubGlobal("localStorage", createStorageMock());
|
||||
vi.stubGlobal("navigator", { language: "en-US" } as Navigator);
|
||||
translate = await import("../lib/translate.ts");
|
||||
localStorage.clear();
|
||||
// Reset to English
|
||||
await translate.i18n.setLocale("en");
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* @vitest-environment jsdom */
|
||||
|
||||
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { ChatHost } from "./app-chat.ts";
|
||||
|
||||
const { setLastActiveSessionKeyMock } = vi.hoisted(() => ({
|
||||
@@ -15,8 +15,10 @@ let handleSendChat: typeof import("./app-chat.ts").handleSendChat;
|
||||
let refreshChatAvatar: typeof import("./app-chat.ts").refreshChatAvatar;
|
||||
let clearPendingQueueItemsForRun: typeof import("./app-chat.ts").clearPendingQueueItemsForRun;
|
||||
|
||||
async function loadChatHelpers(): Promise<void> {
|
||||
vi.resetModules();
|
||||
async function loadChatHelpers(params?: { reload?: boolean }): Promise<void> {
|
||||
if (params?.reload) {
|
||||
vi.resetModules();
|
||||
}
|
||||
({ handleSendChat, refreshChatAvatar, clearPendingQueueItemsForRun } =
|
||||
await import("./app-chat.ts"));
|
||||
}
|
||||
@@ -47,7 +49,7 @@ function makeHost(overrides?: Partial<ChatHost>): ChatHost {
|
||||
}
|
||||
|
||||
describe("refreshChatAvatar", () => {
|
||||
beforeEach(async () => {
|
||||
beforeAll(async () => {
|
||||
await loadChatHelpers();
|
||||
});
|
||||
|
||||
@@ -91,11 +93,14 @@ describe("refreshChatAvatar", () => {
|
||||
});
|
||||
|
||||
describe("handleSendChat", () => {
|
||||
beforeEach(async () => {
|
||||
setLastActiveSessionKeyMock.mockReset();
|
||||
beforeAll(async () => {
|
||||
await loadChatHelpers();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
setLastActiveSessionKeyMock.mockReset();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
vi.doUnmock("./chat/slash-command-executor.ts");
|
||||
@@ -173,7 +178,7 @@ describe("handleSendChat", () => {
|
||||
})),
|
||||
};
|
||||
});
|
||||
await loadChatHelpers();
|
||||
await loadChatHelpers({ reload: true });
|
||||
|
||||
const host = makeHost({
|
||||
client: { request: vi.fn() } as unknown as ChatHost["client"],
|
||||
|
||||
@@ -1,24 +1,9 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { createStorageMock } from "../test-helpers/storage.ts";
|
||||
|
||||
type NavigationModule = typeof import("./navigation.ts");
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { TAB_GROUPS, tabFromPath } from "./navigation.ts";
|
||||
|
||||
describe("TAB_GROUPS", () => {
|
||||
let navigation: NavigationModule;
|
||||
|
||||
beforeEach(async () => {
|
||||
vi.resetModules();
|
||||
vi.stubGlobal("localStorage", createStorageMock());
|
||||
vi.stubGlobal("navigator", { language: "en-US" } as Navigator);
|
||||
navigation = await import("./navigation.ts");
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
it("does not expose unfinished settings slices in the sidebar", () => {
|
||||
const settings = navigation.TAB_GROUPS.find((group) => group.label === "settings");
|
||||
const settings = TAB_GROUPS.find((group) => group.label === "settings");
|
||||
expect(settings?.tabs).toEqual([
|
||||
"config",
|
||||
"communications",
|
||||
@@ -32,11 +17,11 @@ describe("TAB_GROUPS", () => {
|
||||
});
|
||||
|
||||
it("routes every published settings slice", () => {
|
||||
expect(navigation.tabFromPath("/communications")).toBe("communications");
|
||||
expect(navigation.tabFromPath("/appearance")).toBe("appearance");
|
||||
expect(navigation.tabFromPath("/automation")).toBe("automation");
|
||||
expect(navigation.tabFromPath("/infrastructure")).toBe("infrastructure");
|
||||
expect(navigation.tabFromPath("/ai-agents")).toBe("aiAgents");
|
||||
expect(navigation.tabFromPath("/config")).toBe("config");
|
||||
expect(tabFromPath("/communications")).toBe("communications");
|
||||
expect(tabFromPath("/appearance")).toBe("appearance");
|
||||
expect(tabFromPath("/automation")).toBe("automation");
|
||||
expect(tabFromPath("/infrastructure")).toBe("infrastructure");
|
||||
expect(tabFromPath("/ai-agents")).toBe("aiAgents");
|
||||
expect(tabFromPath("/config")).toBe("config");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { createStorageMock } from "../test-helpers/storage.ts";
|
||||
import { loadSettings, saveSettings } from "./storage.ts";
|
||||
|
||||
function setTestLocation(params: { protocol: string; host: string; pathname: string }) {
|
||||
vi.stubGlobal("location", {
|
||||
@@ -38,7 +39,6 @@ function expectedGatewayUrl(basePath: string): string {
|
||||
|
||||
describe("loadSettings default gateway URL derivation", () => {
|
||||
beforeEach(() => {
|
||||
vi.resetModules();
|
||||
vi.stubGlobal("localStorage", createStorageMock());
|
||||
vi.stubGlobal("sessionStorage", createStorageMock());
|
||||
vi.stubGlobal("navigator", { language: "en-US" } as Navigator);
|
||||
@@ -61,7 +61,6 @@ describe("loadSettings default gateway URL derivation", () => {
|
||||
});
|
||||
setControlUiBasePath(" /openclaw/ ");
|
||||
|
||||
const { loadSettings } = await import("./storage.ts");
|
||||
expect(loadSettings().gatewayUrl).toBe(expectedGatewayUrl("/openclaw"));
|
||||
});
|
||||
|
||||
@@ -72,12 +71,10 @@ describe("loadSettings default gateway URL derivation", () => {
|
||||
pathname: "/apps/openclaw/chat",
|
||||
});
|
||||
|
||||
const { loadSettings } = await import("./storage.ts");
|
||||
expect(loadSettings().gatewayUrl).toBe(expectedGatewayUrl("/apps/openclaw"));
|
||||
});
|
||||
|
||||
it("skips node sessionStorage accessors that warn without a storage file", async () => {
|
||||
vi.resetModules();
|
||||
vi.unstubAllGlobals();
|
||||
vi.stubGlobal("localStorage", createStorageMock());
|
||||
vi.stubGlobal("navigator", { language: "en-US" } as Navigator);
|
||||
@@ -89,8 +86,6 @@ describe("loadSettings default gateway URL derivation", () => {
|
||||
setControlUiBasePath(undefined);
|
||||
const warningSpy = vi.spyOn(process, "emitWarning").mockImplementation(() => undefined);
|
||||
|
||||
const { loadSettings } = await import("./storage.ts");
|
||||
|
||||
expect(loadSettings()).toMatchObject({
|
||||
gatewayUrl: expectedGatewayUrl(""),
|
||||
token: "",
|
||||
@@ -118,7 +113,6 @@ describe("loadSettings default gateway URL derivation", () => {
|
||||
}),
|
||||
);
|
||||
|
||||
const { loadSettings } = await import("./storage.ts");
|
||||
expect(loadSettings()).toMatchObject({
|
||||
gatewayUrl: "wss://gateway.example:8443/openclaw",
|
||||
token: "",
|
||||
@@ -155,7 +149,6 @@ describe("loadSettings default gateway URL derivation", () => {
|
||||
});
|
||||
|
||||
const gwUrl = expectedGatewayUrl("");
|
||||
const { loadSettings, saveSettings } = await import("./storage.ts");
|
||||
saveSettings({
|
||||
gatewayUrl: gwUrl,
|
||||
token: "session-token",
|
||||
@@ -188,7 +181,6 @@ describe("loadSettings default gateway URL derivation", () => {
|
||||
|
||||
const gwUrl = expectedGatewayUrl("");
|
||||
const otherUrl = "wss://other-gateway.example:8443";
|
||||
const { loadSettings, saveSettings } = await import("./storage.ts");
|
||||
saveSettings({
|
||||
gatewayUrl: gwUrl,
|
||||
token: "gateway-a-token",
|
||||
@@ -237,7 +229,6 @@ describe("loadSettings default gateway URL derivation", () => {
|
||||
});
|
||||
|
||||
const gwUrl = expectedGatewayUrl("");
|
||||
const { loadSettings, saveSettings } = await import("./storage.ts");
|
||||
saveSettings({
|
||||
gatewayUrl: gwUrl,
|
||||
token: "memory-only-token",
|
||||
@@ -290,7 +281,6 @@ describe("loadSettings default gateway URL derivation", () => {
|
||||
});
|
||||
|
||||
const gwUrl = expectedGatewayUrl("");
|
||||
const { loadSettings, saveSettings } = await import("./storage.ts");
|
||||
saveSettings({
|
||||
gatewayUrl: gwUrl,
|
||||
token: "stale-token",
|
||||
@@ -336,7 +326,6 @@ describe("loadSettings default gateway URL derivation", () => {
|
||||
});
|
||||
|
||||
const gwUrl = expectedGatewayUrl("");
|
||||
const { saveSettings } = await import("./storage.ts");
|
||||
saveSettings({
|
||||
gatewayUrl: gwUrl,
|
||||
token: "",
|
||||
@@ -370,8 +359,6 @@ describe("loadSettings default gateway URL derivation", () => {
|
||||
});
|
||||
|
||||
const gwUrl = expectedGatewayUrl("");
|
||||
const { loadSettings, saveSettings } = await import("./storage.ts");
|
||||
|
||||
saveSettings({
|
||||
gatewayUrl: gwUrl,
|
||||
token: "",
|
||||
@@ -403,7 +390,6 @@ describe("loadSettings default gateway URL derivation", () => {
|
||||
pathname: "/",
|
||||
});
|
||||
|
||||
const { saveSettings } = await import("./storage.ts");
|
||||
const gwUrl = expectedGatewayUrl("");
|
||||
const scopedKey = `openclaw.control.settings.v1:wss://gateway.example:8443`;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user