From f2f475e86968284ad1ef673365d2f2486266c923 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Thu, 23 Apr 2026 20:17:16 +0100 Subject: [PATCH] perf: run ui node tests without jsdom --- ui/src/ui/app-gateway.node.test.ts | 4 ++++ ui/src/ui/app-gateway.sessions.node.test.ts | 1 + ui/src/ui/app-lifecycle-connect.node.test.ts | 4 ++++ ui/src/ui/app-lifecycle.node.test.ts | 5 +++++ ui/src/ui/app-render.helpers.node.test.ts | 1 + ui/src/ui/app-settings.refresh-active-tab.node.test.ts | 1 + ui/src/ui/app-tool-stream.node.test.ts | 1 + ui/src/ui/chat/export.node.test.ts | 1 + ui/src/ui/chat/slash-command-executor.node.test.ts | 1 + ui/src/ui/chat/slash-commands.node.test.ts | 1 + ui/src/ui/connect-error.node.test.ts | 1 + ui/src/ui/controllers/config/form-utils.node.test.ts | 1 + ui/src/ui/controllers/usage.node.test.ts | 1 + ui/src/ui/gateway.node.test.ts | 1 + ui/src/ui/storage.node.test.ts | 1 + ui/src/ui/usage-helpers.node.test.ts | 1 + ui/src/ui/views/config-form.search.node.test.ts | 1 + ui/src/ui/views/cron-quick-create.node.test.ts | 1 + ui/src/ui/views/overview.node.test.ts | 1 + 19 files changed, 29 insertions(+) diff --git a/ui/src/ui/app-gateway.node.test.ts b/ui/src/ui/app-gateway.node.test.ts index ba3500585b2..0e774e24f2a 100644 --- a/ui/src/ui/app-gateway.node.test.ts +++ b/ui/src/ui/app-gateway.node.test.ts @@ -1,3 +1,4 @@ +// @vitest-environment node import { beforeEach, describe, expect, it, vi } from "vitest"; import { GATEWAY_EVENT_UPDATE_AVAILABLE } from "../../../src/gateway/events.js"; import { ConnectErrorDetailCodes } from "../../../src/gateway/protocol/connect-error-details.js"; @@ -206,6 +207,9 @@ describe("connectGateway", () => { gatewayClientInstances.length = 0; loadChatHistoryMock.mockClear(); loadControlUiBootstrapConfigMock.mockClear(); + vi.stubGlobal("window", { + setTimeout: globalThis.setTimeout, + }); }); it("ignores stale client onGap callbacks after reconnect", () => { diff --git a/ui/src/ui/app-gateway.sessions.node.test.ts b/ui/src/ui/app-gateway.sessions.node.test.ts index 1bc9178fd1c..d8e0b250f0b 100644 --- a/ui/src/ui/app-gateway.sessions.node.test.ts +++ b/ui/src/ui/app-gateway.sessions.node.test.ts @@ -1,3 +1,4 @@ +// @vitest-environment node import { describe, expect, it, vi } from "vitest"; const loadSessionsMock = vi.fn(); diff --git a/ui/src/ui/app-lifecycle-connect.node.test.ts b/ui/src/ui/app-lifecycle-connect.node.test.ts index 93f14648715..c49adc81a5b 100644 --- a/ui/src/ui/app-lifecycle-connect.node.test.ts +++ b/ui/src/ui/app-lifecycle-connect.node.test.ts @@ -1,3 +1,4 @@ +// @vitest-environment node import { beforeEach, describe, expect, it, vi } from "vitest"; const { applySettingsFromUrlMock, connectGatewayMock, loadBootstrapMock } = vi.hoisted(() => ({ @@ -70,6 +71,9 @@ describe("handleConnected", () => { applySettingsFromUrlMock.mockReset(); connectGatewayMock.mockReset(); loadBootstrapMock.mockReset(); + vi.stubGlobal("window", { + addEventListener: vi.fn(), + }); }); it("waits for bootstrap load before first gateway connect", async () => { diff --git a/ui/src/ui/app-lifecycle.node.test.ts b/ui/src/ui/app-lifecycle.node.test.ts index de87d71334a..23d3129d887 100644 --- a/ui/src/ui/app-lifecycle.node.test.ts +++ b/ui/src/ui/app-lifecycle.node.test.ts @@ -1,3 +1,4 @@ +// @vitest-environment node import { describe, expect, it, vi } from "vitest"; import { handleDisconnected } from "./app-lifecycle.ts"; @@ -28,6 +29,9 @@ function createHost() { describe("handleDisconnected", () => { it("stops and clears gateway client on teardown", () => { + vi.stubGlobal("window", { + removeEventListener: vi.fn(), + }); const removeSpy = vi.spyOn(window, "removeEventListener").mockImplementation(() => undefined); const host = createHost(); const disconnectSpy = ( @@ -43,5 +47,6 @@ describe("handleDisconnected", () => { expect(disconnectSpy).toHaveBeenCalledTimes(1); expect(host.topbarObserver).toBeNull(); removeSpy.mockRestore(); + vi.unstubAllGlobals(); }); }); diff --git a/ui/src/ui/app-render.helpers.node.test.ts b/ui/src/ui/app-render.helpers.node.test.ts index 44cf48d3415..8687328d94c 100644 --- a/ui/src/ui/app-render.helpers.node.test.ts +++ b/ui/src/ui/app-render.helpers.node.test.ts @@ -1,3 +1,4 @@ +// @vitest-environment node import { describe, expect, it, vi } from "vitest"; const { refreshChatMock, diff --git a/ui/src/ui/app-settings.refresh-active-tab.node.test.ts b/ui/src/ui/app-settings.refresh-active-tab.node.test.ts index 13e0959c7af..3466897693e 100644 --- a/ui/src/ui/app-settings.refresh-active-tab.node.test.ts +++ b/ui/src/ui/app-settings.refresh-active-tab.node.test.ts @@ -1,3 +1,4 @@ +// @vitest-environment node import { beforeEach, describe, expect, it, vi } from "vitest"; const mocks = vi.hoisted(() => ({ diff --git a/ui/src/ui/app-tool-stream.node.test.ts b/ui/src/ui/app-tool-stream.node.test.ts index 05ff73873e1..6784d8a63e3 100644 --- a/ui/src/ui/app-tool-stream.node.test.ts +++ b/ui/src/ui/app-tool-stream.node.test.ts @@ -1,3 +1,4 @@ +// @vitest-environment node import { beforeAll, describe, expect, it, vi } from "vitest"; import { handleAgentEvent, type FallbackStatus, type ToolStreamEntry } from "./app-tool-stream.ts"; diff --git a/ui/src/ui/chat/export.node.test.ts b/ui/src/ui/chat/export.node.test.ts index 807fba8813a..92bfaa3e52c 100644 --- a/ui/src/ui/chat/export.node.test.ts +++ b/ui/src/ui/chat/export.node.test.ts @@ -1,3 +1,4 @@ +// @vitest-environment node import { describe, expect, it } from "vitest"; import { buildChatMarkdown } from "./export.ts"; diff --git a/ui/src/ui/chat/slash-command-executor.node.test.ts b/ui/src/ui/chat/slash-command-executor.node.test.ts index d170113e596..c0891621126 100644 --- a/ui/src/ui/chat/slash-command-executor.node.test.ts +++ b/ui/src/ui/chat/slash-command-executor.node.test.ts @@ -1,3 +1,4 @@ +// @vitest-environment node import { describe, expect, it, vi } from "vitest"; import { createResolvedModelPatch, diff --git a/ui/src/ui/chat/slash-commands.node.test.ts b/ui/src/ui/chat/slash-commands.node.test.ts index 963d94770cb..fdc504fd414 100644 --- a/ui/src/ui/chat/slash-commands.node.test.ts +++ b/ui/src/ui/chat/slash-commands.node.test.ts @@ -1,3 +1,4 @@ +// @vitest-environment node import { afterEach, describe, expect, it, vi } from "vitest"; import { parseSlashCommand, diff --git a/ui/src/ui/connect-error.node.test.ts b/ui/src/ui/connect-error.node.test.ts index 71f81622884..c005a9473e1 100644 --- a/ui/src/ui/connect-error.node.test.ts +++ b/ui/src/ui/connect-error.node.test.ts @@ -1,3 +1,4 @@ +// @vitest-environment node import { describe, expect, it } from "vitest"; import { formatConnectError } from "./connect-error.ts"; diff --git a/ui/src/ui/controllers/config/form-utils.node.test.ts b/ui/src/ui/controllers/config/form-utils.node.test.ts index abd9256d663..cd3bc451d46 100644 --- a/ui/src/ui/controllers/config/form-utils.node.test.ts +++ b/ui/src/ui/controllers/config/form-utils.node.test.ts @@ -1,3 +1,4 @@ +// @vitest-environment node import { describe, expect, it } from "vitest"; import type { JsonSchema } from "../../views/config-form.shared.ts"; import { coerceFormValues } from "./form-coerce.ts"; diff --git a/ui/src/ui/controllers/usage.node.test.ts b/ui/src/ui/controllers/usage.node.test.ts index 8ddd6cbce2f..378c2db4c55 100644 --- a/ui/src/ui/controllers/usage.node.test.ts +++ b/ui/src/ui/controllers/usage.node.test.ts @@ -1,3 +1,4 @@ +// @vitest-environment node import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { __test, diff --git a/ui/src/ui/gateway.node.test.ts b/ui/src/ui/gateway.node.test.ts index 90ef9e32ce7..ef8d9a2f21f 100644 --- a/ui/src/ui/gateway.node.test.ts +++ b/ui/src/ui/gateway.node.test.ts @@ -1,3 +1,4 @@ +// @vitest-environment node import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { createStorageMock } from "../test-helpers/storage.ts"; import { loadDeviceAuthToken, storeDeviceAuthToken } from "./device-auth.ts"; diff --git a/ui/src/ui/storage.node.test.ts b/ui/src/ui/storage.node.test.ts index 0c9dc43f39d..4fc48b85f1f 100644 --- a/ui/src/ui/storage.node.test.ts +++ b/ui/src/ui/storage.node.test.ts @@ -1,3 +1,4 @@ +// @vitest-environment node import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { createStorageMock } from "../test-helpers/storage.ts"; import { diff --git a/ui/src/ui/usage-helpers.node.test.ts b/ui/src/ui/usage-helpers.node.test.ts index 441c64ab167..afc4ffb5193 100644 --- a/ui/src/ui/usage-helpers.node.test.ts +++ b/ui/src/ui/usage-helpers.node.test.ts @@ -1,3 +1,4 @@ +// @vitest-environment node import { describe, expect, it } from "vitest"; import { extractQueryTerms, filterSessionsByQuery, parseToolSummary } from "./usage-helpers.ts"; diff --git a/ui/src/ui/views/config-form.search.node.test.ts b/ui/src/ui/views/config-form.search.node.test.ts index ee2387ee393..6e8ad5e177b 100644 --- a/ui/src/ui/views/config-form.search.node.test.ts +++ b/ui/src/ui/views/config-form.search.node.test.ts @@ -1,3 +1,4 @@ +// @vitest-environment node import { describe, expect, it } from "vitest"; import { matchesNodeSearch, parseConfigSearchQuery } from "./config-form.node.ts"; diff --git a/ui/src/ui/views/cron-quick-create.node.test.ts b/ui/src/ui/views/cron-quick-create.node.test.ts index ca6dc4f787a..5a3c6b8022c 100644 --- a/ui/src/ui/views/cron-quick-create.node.test.ts +++ b/ui/src/ui/views/cron-quick-create.node.test.ts @@ -1,3 +1,4 @@ +// @vitest-environment node import { describe, expect, it } from "vitest"; import { draftToCronFormPatch, type CronQuickCreateDraft } from "./cron-quick-create.ts"; diff --git a/ui/src/ui/views/overview.node.test.ts b/ui/src/ui/views/overview.node.test.ts index c91e6ca7f02..33500d1dae6 100644 --- a/ui/src/ui/views/overview.node.test.ts +++ b/ui/src/ui/views/overview.node.test.ts @@ -1,3 +1,4 @@ +// @vitest-environment node import { describe, expect, it } from "vitest"; import { ConnectErrorDetailCodes } from "../../../../src/gateway/protocol/connect-error-details.js"; import {