From 52ba7d630fd06beedfa51886541244c84d1e308a Mon Sep 17 00:00:00 2001 From: Luke Parker <10430890+Hona@users.noreply.github.com> Date: Wed, 14 Oct 2026 12:58:50 +1000 Subject: [PATCH] test(app): stop partial settings mocks leaking across browser tests (#55276) --- packages/app/package.json | 6 +++--- packages/app/src/composer/comments.test.ts | 17 ++-------------- .../server-notification-state.test.ts | 20 ++++++++++++++----- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/packages/app/package.json b/packages/app/package.json index 279202c223b..4815e137b58 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "build": "vite build", "serve": "vite preview", "test": "bun run test:unit && bun run test:browser", - "test:unit": "bun test --conditions=solid --only-failures --preload ./happydom.ts ./src", - "test:browser": "bun test --conditions=browser --preload ./happydom.ts ./test-browser", - "test:unit:watch": "bun test --conditions=solid --watch --preload ./happydom.ts ./src", + "test:unit": "bun test --conditions=solid --only-failures --isolate --preload ./happydom.ts ./src", + "test:browser": "bun test --conditions=browser --isolate --preload ./happydom.ts ./test-browser", + "test:unit:watch": "bun test --conditions=solid --watch --isolate --preload ./happydom.ts ./src", "test:e2e": "playwright test", "test:e2e:built": "PLAYWRIGHT_BUILD=1 playwright test", "test:e2e:local": "playwright test", diff --git a/packages/app/src/composer/comments.test.ts b/packages/app/src/composer/comments.test.ts index 784c2004ac6..44e182a3525 100644 --- a/packages/app/src/composer/comments.test.ts +++ b/packages/app/src/composer/comments.test.ts @@ -1,19 +1,6 @@ -import { beforeAll, describe, expect, mock, test } from "bun:test" +import { describe, expect, test } from "bun:test" import { createRoot } from "solid-js" -import type { LineComment } from "./comments" - -let createCommentSessionForTest: typeof import("./comments").createCommentSessionForTest - -beforeAll(async () => { - mock.module("@solidjs/router", () => ({ - useNavigate: () => () => undefined, - useParams: () => ({}), - useLocation: () => ({}), - useSearchParams: () => [{}, () => undefined], - })) - const mod = await import("./comments") - createCommentSessionForTest = mod.createCommentSessionForTest -}) +import { createCommentSessionForTest, type LineComment } from "./comments" function line(file: string, id: string, time: number): LineComment { return { diff --git a/packages/app/test-browser/server-notification-state.test.ts b/packages/app/test-browser/server-notification-state.test.ts index 7afeda3fa9b..fd582cb3f5c 100644 --- a/packages/app/test-browser/server-notification-state.test.ts +++ b/packages/app/test-browser/server-notification-state.test.ts @@ -23,8 +23,17 @@ const createState = (input: { sdk: object; data: object; coordinator: object }) createServerNotificationState({ key: server, ...input } as never) beforeAll(async () => { - const { sessionIDHasOpenTab } = await import("@/shell/tabs/tabs") + // Fakes replace only the hooks this test controls. Spreading the real module keeps every other export, such as + // projectSettingsKey, for the modules the notification state imports. + const real = { + platform: await import("@/runtime/platform/platform"), + settings: await import("@/settings/model"), + language: await import("@/runtime/i18n/language"), + tabs: await import("@/shell/tabs/tabs"), + } + mock.module("@/runtime/platform/platform", () => ({ + ...real.platform, usePlatform: () => ({ platform: "web", notify: async (title: string) => { @@ -33,16 +42,17 @@ beforeAll(async () => { }), })) mock.module("@/settings/model", () => ({ + ...real.settings, useSettings: () => ({ sounds: { agentEnabled: () => false, errorsEnabled: () => false }, notifications: { agent: () => true, errors: () => true }, }), })) - mock.module("@/runtime/i18n/language", () => ({ useLanguage: () => ({ t: (key: string) => key }) })) - mock.module("@/shell/tabs/tabs", () => ({ - useTabs: () => tabs, - sessionIDHasOpenTab, + mock.module("@/runtime/i18n/language", () => ({ + ...real.language, + useLanguage: () => ({ t: (key: string) => key }), })) + mock.module("@/shell/tabs/tabs", () => ({ ...real.tabs, useTabs: () => tabs })) createServerNotificationState = (await import("@/shell/notifications/notification")).createServerNotificationState })