The best way to control Claude Code, Codex and more from any computer or phone
test(web): jsdom-leftovers tests run in a real browser (#20862)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 17, 2026 at 02:49 UTC
759f68fdf5b2c34caf3b1d194795e5557a46cc18
4 files changed
+123
-114
apps/web/src/components/ComposerPromptEditorTiptap.citationDraft.browser.test.tsx
renamed
+25
-28
@@ -1,5 +1,3 @@
1
-// @vitest-environment jsdom
2
-
1
import { EnvironmentId, MessageId, ThreadId } from "@t3tools/contracts";
2
import {
3
serializeAssistantCitation,
@@ -9,22 +7,15 @@ import { act, createRef, useState, type ReactNode } from "react";
7
import { createRoot, type Root } from "react-dom/client";
8
import { afterEach, beforeEach, expect, it, vi } from "vite-plus/test";
9
12
-import type { AssistantCitationSourceAnchor } from "~/lib/assistantTextSelection";
10
+import { page, userEvent } from "vite-plus/test/browser";
11
14
-vi.mock("./chat/AssistantCitationSource", () => ({
15
- observeAssistantCitationCommentSource: () => () => {},
16
-}));
17
-vi.mock("@tanstack/react-router", () => ({
18
- useNavigate: () => () => {},
19
- Link: ({ children }: { children: ReactNode }) => <a>{children}</a>,
20
-}));
21
-vi.mock("./ui/popover", () => ({
22
- Popover: ({ children }: { children: ReactNode }) => <>{children}</>,
23
- PopoverTrigger: ({ "aria-label": label }: { "aria-label": string }) => (
24
- <button aria-label={label} />
25
- ),
26
- PopoverPopup: ({ children }: { children: ReactNode }) => <>{children}</>,
27
- PopoverClose: ({ children }: { children: ReactNode }) => <>{children}</>,
12
+import { findAssistantCitationSourceAnchor } from "~/lib/assistantTextSelection";
13
+
14
+// No router is mounted; the citation chip only needs navigation to exist.
15
+vi.mock(import("@tanstack/react-router"), async (original) => ({
16
+ ...(await original()),
17
+ useNavigate: () => async () => {},
18
+ Link: (({ children }: { children: ReactNode }) => <a>{children}</a>) as never,
19
}));
20
21
import { ComposerPromptEditor, type ComposerPromptEditorHandle } from "./ComposerPromptEditor";
@@ -46,7 +37,6 @@ let root: Root;
37
let container: HTMLDivElement;
38
39
beforeEach(() => {
49
- vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
40
container = document.createElement("div");
41
document.body.append(container);
42
root = createRoot(container);
@@ -55,7 +45,6 @@ beforeEach(() => {
45
afterEach(async () => {
46
await act(async () => root.unmount());
47
container.remove();
58
- vi.unstubAllGlobals();
48
});
49
50
function Composer({
@@ -69,6 +58,15 @@ function Composer({
58
const [answer, setAnswer] = useState("");
59
return (
60
<>
61
+ <div data-assistant-citation-viewport="">
62
+ <p
63
+ data-assistant-citation-source={citation.messageId}
64
+ data-assistant-citation-environment={citation.environmentId}
65
+ data-assistant-citation-thread={citation.threadId}
66
+ >
67
+ hello world
68
+ </p>
69
+ </div>
70
<output data-prompt={prompt} data-answer={answer} />
71
<ComposerPromptEditor
72
editorRef={editorRef}
@@ -93,22 +91,21 @@ it("keeps an unsaved citation comment when a question takes the composer", async
91
const drafts = () => container.querySelector("output")?.dataset;
92
93
await act(async () => root.render(<Composer question={false} editorRef={editorRef} />));
94
+ const sourceAnchor = findAssistantCitationSourceAnchor(document, citation);
95
+ if (!sourceAnchor) throw new Error("Citation source did not resolve");
96
await act(async () =>
97
editorRef.current?.requestCitationComment({
98
previousValue: "See ",
99
value: promptBefore,
100
citationStart: "See ".length,
101
- sourceAnchor: {} as AssistantCitationSourceAnchor,
101
+ sourceAnchor,
102
insertedSpaces: { before: false, after: true },
103
}),
104
);
105
- const textarea = container.querySelector("textarea");
106
- if (!textarea) throw new Error("Comment editor did not open");
107
- await act(async () => {
108
- const setValue = Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, "value")?.set;
109
- setValue?.call(textarea, "check this");
110
- textarea.dispatchEvent(new Event("input", { bubbles: true }));
111
- });
105
+ const comment = page.getByLabelText("Comment on selected text");
106
+ await expect.element(comment).toBeVisible();
107
+ await comment.click();
108
+ await userEvent.keyboard("check this");
109
110
await act(async () => root.render(<Composer question editorRef={editorRef} />));
111
expect(drafts()?.answer).toBe("");
@@ -117,5 +114,5 @@ it("keeps an unsaved citation comment when a question takes the composer", async
114
expect(drafts()?.prompt).toBe(
115
`See ${serializeAssistantCitation(withAssistantCitationComment(citation, "check this"))} `,
116
);
120
- expect(container.querySelector('[aria-label="Edit citation comment"]')).not.toBeNull();
117
+ await expect.element(page.getByLabelText("Edit citation comment")).toBeInTheDocument();
118
});
apps/web/src/components/chat/HtmlRenderDialog.browser.test.tsx
renamed
+28
-30
@@ -1,12 +1,13 @@
1
-// @vitest-environment jsdom
2
-
1
import { act } from "react";
2
import { createRoot, type Root } from "react-dom/client";
3
import { afterEach, beforeEach, expect, it, vi } from "vite-plus/test";
4
+import { page, userEvent } from "vite-plus/test/browser";
5
import { htmlRenderTheme, HTML_RENDER_DEFAULT_FONTS } from "@t3tools/shared/htmlRender";
6
import { T3_CODE_DARK_THEME_COLORS } from "@t3tools/shared/themePalettes";
7
import { EnvironmentId, ThreadId } from "@t3tools/contracts";
8
9
+import "~/index.css";
10
+
11
import { HtmlRenderDialog } from "./HtmlRenderDialog";
12
import { HtmlRenderFrame } from "./HtmlRenderFrame";
13
@@ -17,11 +18,16 @@ const { cachedUrl, refresh, showError, openLink, openChangeRequestLink } = vi.ho
18
openLink: vi.fn(),
19
openChangeRequestLink: vi.fn(),
20
}));
20
-vi.mock("~/browser/useOpenLink", () => ({ useOpenLink: () => openLink }));
21
-vi.mock("~/lib/openPullRequestLink", () => ({
21
+vi.mock(import("~/browser/useOpenLink"), async (original) => ({
22
+ ...(await original()),
23
+ useOpenLink: () => openLink,
24
+}));
25
+vi.mock(import("~/lib/openPullRequestLink"), async (original) => ({
26
+ ...(await original()),
27
useOpenChangeRequestLink: () => openChangeRequestLink,
28
}));
24
-vi.mock("~/assets/assetUrls", () => ({
29
+vi.mock(import("~/assets/assetUrls"), async (original) => ({
30
+ ...(await original()),
31
useAssetUrlState: () => ({
32
_tag: "Success",
33
url: "https://environment.test/original.html",
@@ -29,9 +35,12 @@ vi.mock("~/assets/assetUrls", () => ({
35
}),
36
useAssetUrlRefresh: () => refresh,
37
}));
32
-vi.mock("../ui/toast", () => ({ toastManager: { add: showError } }));
33
-
34
-vi.mock("~/hooks/useHtmlRenderTheme", () => ({
38
+vi.mock(import("../ui/toast"), async (original) => {
39
+ const actual = await original();
40
+ return { ...actual, toastManager: { ...actual.toastManager, add: showError } };
41
+});
42
+vi.mock(import("~/hooks/useHtmlRenderTheme"), async (original) => ({
43
+ ...(await original()),
44
useHtmlRenderTheme: () =>
45
htmlRenderTheme(T3_CODE_DARK_THEME_COLORS, "dark", HTML_RENDER_DEFAULT_FONTS),
46
}));
@@ -41,15 +50,6 @@ let container: HTMLDivElement;
50
const onClose = vi.fn();
51
52
beforeEach(async () => {
44
- vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
45
- vi.stubGlobal(
46
- "ResizeObserver",
47
- class {
48
- observe() {}
49
- disconnect() {}
50
- unobserve() {}
51
- },
52
- );
53
refresh.mockReset();
54
cachedUrl.lifeMs = 60 * 60_000;
55
openLink.mockReset().mockResolvedValue(undefined);
@@ -73,23 +73,25 @@ beforeEach(async () => {
73
afterEach(async () => {
74
await act(() => root.unmount());
75
container.remove();
76
- vi.unstubAllGlobals();
76
});
77
78
+function button(label: string) {
79
+ return page.getByRole("button", { name: label, exact: true });
80
+}
81
+
82
+// A trusted click, so the page also gets the user activation the link handler requires.
83
async function click(label: string) {
80
- const button = document.querySelector<HTMLButtonElement>(`button[aria-label="${label}"]`);
81
- expect(button).not.toBeNull();
82
- await act(() => button!.click());
84
+ await button(label).click();
85
}
86
87
it("zooms the loaded page within bounds and resets without reloading it", async () => {
88
const frame = document.querySelector("iframe")!;
89
const src = frame.src;
88
- for (let step = 0; step < 6; step += 1) await click("Zoom in");
89
- expect(document.querySelector<HTMLButtonElement>('[aria-label="Zoom in"]')!.disabled).toBe(true);
90
+ for (let step = 0; step < 4; step += 1) await click("Zoom in");
91
+ await expect.element(button("Zoom in")).toBeDisabled();
92
expect(frame.parentElement!.style.getPropertyValue("zoom")).toBe("2");
91
- for (let step = 0; step < 8; step += 1) await click("Zoom out");
92
- expect(document.querySelector<HTMLButtonElement>('[aria-label="Zoom out"]')!.disabled).toBe(true);
93
+ for (let step = 0; step < 6; step += 1) await click("Zoom out");
94
+ await expect.element(button("Zoom out")).toBeDisabled();
95
expect(frame.parentElement!.style.getPropertyValue("zoom")).toBe("0.5");
96
await click("Reset zoom");
97
expect(frame.parentElement!.style.getPropertyValue("zoom")).toBe("1");
@@ -102,11 +104,7 @@ it("closes with the close button or Escape", async () => {
104
await click("Close");
105
expect(onClose).toHaveBeenCalledOnce();
106
onClose.mockClear();
105
- await act(() => {
106
- document.activeElement?.dispatchEvent(
107
- new KeyboardEvent("keydown", { key: "Escape", bubbles: true }),
108
- );
109
- });
107
+ await userEvent.keyboard("{Escape}");
108
expect(onClose).toHaveBeenCalledOnce();
109
});
110
apps/web/src/components/settings/StorageSettings.browser.test.tsx
renamed
+32
-29
@@ -1,4 +1,3 @@
1
-// @vitest-environment jsdom
1
import { RegistryProvider } from "@effect/atom-react";
2
import {
3
DEFAULT_SERVER_SETTINGS,
@@ -16,20 +15,30 @@ const state = vi.hoisted(() => ({
15
report: null as StorageCleanupReport | null,
16
}));
17
19
-vi.mock("../../state/server", async () => {
18
+vi.mock(import("../../state/server"), async (original) => {
19
+ const actual = await original();
20
const { Atom } = await import("effect/reactivity");
21
const report = Atom.make(() => ({ _tag: "Success", value: state.report, waiting: false }));
22
const allowed = Atom.make(true);
23
return {
24
+ ...actual,
25
serverEnvironment: {
25
- storageCleanupReport: () => report,
26
- runStorageCleanup: { permissionAtom: () => allowed },
26
+ ...actual.serverEnvironment,
27
+ storageCleanupReport: (() => report) as never,
28
+ runStorageCleanup: {
29
+ ...actual.serverEnvironment.runStorageCleanup,
30
+ permissionAtom: () => allowed,
31
+ },
32
},
33
};
34
});
30
-vi.mock("../../state/use-atom-command", () => ({ useAtomCommand: () => state.run }));
31
-vi.mock("./SettingsScopeContext", () => ({
32
- useSettingsScope: () => {
35
+vi.mock(import("../../state/use-atom-command"), async (original) => ({
36
+ ...(await original()),
37
+ useAtomCommand: (() => state.run) as never,
38
+}));
39
+vi.mock(import("./SettingsScopeContext"), async (original) => ({
40
+ ...(await original()),
41
+ useSettingsScope: (() => {
42
const environment = {
43
environmentId: "env",
44
label: "Machine",
@@ -51,38 +60,34 @@ vi.mock("./SettingsScopeContext", () => ({
60
targets: [],
61
target: null,
62
};
54
- },
63
+ }) as never,
64
}));
56
-vi.mock("./useScopedSettings", () => ({
57
- useScopedSettings: () => state.settings,
65
+vi.mock(import("./useScopedSettings"), async (original) => ({
66
+ ...(await original()),
67
+ useScopedSettings: (() => state.settings) as never,
68
useScopedSettingsMixed: () => false,
69
useUpdateScopedSettings: () => vi.fn(),
70
useClearScopedSettings: () => vi.fn(),
71
}));
62
-vi.mock("./settingsLayout", () => ({
63
- SettingsPageContainer: ({ children }: { children: ReactNode }) => children,
64
- SettingsSection: ({ children }: { children: ReactNode }) => children,
65
- SettingsRow: ({
66
- title,
67
- description,
68
- control,
69
- }: {
70
- title: ReactNode;
71
- description: ReactNode;
72
- control: ReactNode;
73
- }) => (
72
+// The real page container needs a router and the real row reads write permission and
73
+// overrides from live environment state; this suite is about the cleanup panel.
74
+vi.mock(import("./settingsLayout"), async (original) => ({
75
+ ...(await original()),
76
+ SettingsPageContainer: (({ children }: { children: ReactNode }) => children) as never,
77
+ SettingsRow: ({ title, description, control, children }) => (
78
<div>
79
<h3>{title}</h3>
80
{description}
81
{control}
82
+ {children}
83
</div>
84
),
80
- SettingResetButton: () => null,
81
- useRelativeTimeTick: () => undefined,
82
- useSettingsSearchTargetId: () => null,
83
- useSettingsSearchTarget: () => undefined,
85
+ SettingResetButton: (() => null) as never,
86
}));
85
-vi.mock("../ui/toast", () => ({ toastManager: { add: vi.fn() } }));
87
+vi.mock(import("../ui/toast"), async (original) => {
88
+ const actual = await original();
89
+ return { ...actual, toastManager: { ...actual.toastManager, add: vi.fn() } };
90
+});
91
92
import { StorageSettingsPanel } from "./StorageSettings";
93
@@ -90,7 +95,6 @@ let root: Root;
95
let container: HTMLDivElement;
96
97
beforeEach(() => {
93
- vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
98
state.settings = {
99
...DEFAULT_SERVER_SETTINGS,
100
storageCleanup: {
@@ -115,7 +119,6 @@ beforeEach(() => {
119
afterEach(async () => {
120
await act(async () => root.unmount());
121
container.remove();
118
- vi.unstubAllGlobals();
122
});
123
124
async function render() {
apps/web/src/components/settings/settingsScopeRetention.browser.test.tsx
renamed
+38
-27
@@ -1,4 +1,3 @@
1
-// @vitest-environment jsdom
1
import { act, useState, type ReactNode } from "react";
2
import { createRoot, type Root } from "react-dom/client";
3
import { afterEach, beforeEach, expect, it, vi } from "vite-plus/test";
@@ -14,28 +13,28 @@ const state = vi.hoisted(() => ({
13
scope: { search: {}, environmentId: null } as ScopeState,
14
}));
15
17
-vi.mock("@tanstack/react-router", async (importOriginal) => ({
18
- ...(await importOriginal<typeof import("@tanstack/react-router")>()),
19
- createFileRoute: () => (options: { component: () => ReactNode }) => ({
16
+vi.mock(import("@tanstack/react-router"), async (original) => ({
17
+ ...(await original()),
18
+ createFileRoute: (() => (options: { component: () => ReactNode }) => ({
19
options,
20
useSearch: () => state.scope.search,
21
useNavigate: () => vi.fn(),
23
- }),
24
- useLocation: (options?: { select: (location: unknown) => unknown }) => {
22
+ })) as never,
23
+ useLocation: ((options?: { select: (location: unknown) => unknown }) => {
24
const location = { pathname: state.pathname, hash: "", state: {} };
25
return options ? options.select(location) : location;
27
- },
28
- Outlet: () => <StatefulContent />,
29
- redirect: vi.fn(),
26
+ }) as never,
27
+ Outlet: (() => <StatefulContent />) as never,
28
}));
31
-vi.mock("./SettingsScopeContext", async () => {
29
+vi.mock(import("./SettingsScopeContext"), async (original) => {
30
const { createContext, useContext } = await import("react");
31
const Scope = createContext<ScopeState>(state.scope);
32
return {
35
- SettingsScopeProvider: ({ children }: { children: ReactNode }) => (
33
+ ...(await original()),
34
+ SettingsScopeProvider: (({ children }: { children: ReactNode }) => (
35
<Scope value={state.scope}>{children}</Scope>
37
- ),
38
- useSettingsScope: () => {
36
+ )) as never,
37
+ useSettingsScope: (() => {
38
const { search, environmentId } = useContext(Scope);
39
return {
40
search,
@@ -43,23 +42,37 @@ vi.mock("./SettingsScopeContext", async () => {
42
environment: environmentId ? { environmentId } : null,
43
connectedEnvironments: environmentId ? [{}] : [],
44
};
46
- },
45
+ }) as never,
46
};
47
});
49
-vi.mock("../../state/environments", () => ({ useEnvironments: () => ({ environments: [] }) }));
50
-vi.mock("../ui/sidebar", () => ({
51
- SidebarInset: ({ children }: { children: ReactNode }) => <div>{children}</div>,
48
+vi.mock(import("../../state/environments"), async (original) => ({
49
+ ...(await original()),
50
+ useEnvironments: (() => ({ environments: [] })) as never,
51
}));
53
-vi.mock("../WorkspacePageHeader", () => ({
54
- WorkspacePageHeader: ({ children }: { children: ReactNode }) => <div>{children}</div>,
52
+vi.mock(import("../ui/sidebar"), async (original) => ({
53
+ ...(await original()),
54
+ SidebarInset: ({ children }: { children?: ReactNode }) => <div>{children}</div>,
55
}));
56
-vi.mock("./settingsLayout", () => ({
57
- SettingsPageContainer: ({ children }: { children: ReactNode }) => <div>{children}</div>,
56
+vi.mock(import("../WorkspacePageHeader"), async (original) => ({
57
+ ...(await original()),
58
+ WorkspacePageHeader: ({ children }: { children?: ReactNode }) => <div>{children}</div>,
59
+}));
60
+vi.mock(import("./SettingsBreadcrumb"), async (original) => ({
61
+ ...(await original()),
62
+ SettingsBreadcrumb: (() => null) as never,
63
+}));
64
+vi.mock(import("../sidebar/mainAppLocation"), async (original) => ({
65
+ ...(await original()),
66
+ useNavigateToMainApp: () => vi.fn(),
67
+}));
68
+vi.mock(import("../../hooks/useNavigateBack"), async (original) => ({
69
+ ...(await original()),
70
+ useEscapeToGoBack: () => undefined,
71
+}));
72
+vi.mock(import("./SettingsPanels"), async (original) => ({
73
+ ...(await original()),
74
+ useSettingsRestore: (() => ({ changedSettingLabels: [] })) as never,
75
}));
59
-vi.mock("./SettingsBreadcrumb", () => ({ SettingsBreadcrumb: () => null }));
60
-vi.mock("../sidebar/mainAppLocation", () => ({ useNavigateToMainApp: () => vi.fn() }));
61
-vi.mock("../../hooks/useNavigateBack", () => ({ useEscapeToGoBack: () => undefined }));
62
-vi.mock("./SettingsPanels", () => ({ useSettingsRestore: () => ({ changedSettingLabels: [] }) }));
76
77
import { Route } from "../../routes/settings";
78
@@ -86,7 +99,6 @@ function retainedValue() {
99
}
100
101
beforeEach(() => {
89
- vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
102
container = document.createElement("div");
103
document.body.append(container);
104
root = createRoot(container);
@@ -94,7 +106,6 @@ beforeEach(() => {
106
afterEach(async () => {
107
await act(async () => root.unmount());
108
container.remove();
97
- vi.unstubAllGlobals();
109
});
110
111
const first = { search: { machine: "first", project: "one" }, environmentId: "first" };