The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 03:00 UTC
test(web): burst-merged jsdom tests run in a real browser (#21318)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 18, 2026 at 15:37 UTC
8cd9641f76874f2ce17d6c80acd71fab1f0b99d3
8 files changed
+35
-115
apps/web/src/components/CommandPalette.focus.browser.test.tsx
renamed
-14
@@ -1,5 +1,3 @@
1
-// @vitest-environment jsdom
2
-
1
import { act, useImperativeHandle, useRef } from "react";
2
import { createRoot, type Root } from "react-dom/client";
3
import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
@@ -73,18 +71,6 @@ let container: HTMLDivElement;
71
beforeEach(() => {
72
vi.useFakeTimers();
73
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
76
- vi.stubGlobal(
77
- "ResizeObserver",
78
- class {
79
- observe() {}
80
- disconnect() {}
81
- unobserve() {}
82
- },
83
- );
84
- Object.defineProperty(Element.prototype, "getAnimations", {
85
- configurable: true,
86
- value: () => [],
87
- });
74
container = document.createElement("div");
75
document.body.append(container);
76
root = createRoot(container);
apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx
renamed
-3
@@ -1,5 +1,3 @@
1
-// @vitest-environment jsdom
2
-
1
import type { Editor } from "@tiptap/core";
2
import { act, createRef } from "react";
3
import { createRoot, type Root } from "react-dom/client";
@@ -43,7 +41,6 @@ async function mountEditor(value: string, richTextEnabled = true) {
41
);
42
const element = container.querySelector<HTMLElement & { editor: Editor }>(".tiptap");
43
if (!element) throw new Error("Composer did not mount");
46
- element.editor.view.setProps({ handleScrollToSelection: () => true });
44
return element.editor;
45
}
46
apps/web/src/components/chat/MermaidDiagram.browser.test.tsx
renamed
-2
@@ -1,5 +1,3 @@
1
-// @vitest-environment jsdom
2
-
1
import { describe, expect, it } from "vite-plus/test";
2
3
import { sanitizeMermaidSvg } from "./MermaidDiagram";
apps/web/src/components/chat/threadContextDrag.browser.test.tsx
renamed
-2
@@ -1,5 +1,3 @@
1
-// @vitest-environment jsdom
2
-
1
import { act, memo, useRef } from "react";
2
import { createRoot, type Root } from "react-dom/client";
3
import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
apps/web/src/components/preview/PreviewPanelShell.a11y.browser.test.tsx
renamed
+12
-20
@@ -1,9 +1,8 @@
1
-// @vitest-environment jsdom
2
-
1
import { Dialog } from "@base-ui/react/dialog";
2
import { act } from "react";
3
import { createRoot, type Root } from "react-dom/client";
4
import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
5
+import { userEvent } from "vite-plus/test/browser";
6
7
import { PanelLayoutControls } from "../chat/PanelLayoutControls";
8
import { PreviewPanelShell, type PreviewPanelMode } from "./PreviewPanelShell";
@@ -13,15 +12,6 @@ let container: HTMLDivElement;
12
13
beforeEach(() => {
14
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
16
- vi.useFakeTimers({ toFake: ["requestAnimationFrame", "cancelAnimationFrame"] });
17
- vi.stubGlobal(
18
- "ResizeObserver",
19
- class {
20
- observe() {}
21
- unobserve() {}
22
- disconnect() {}
23
- },
24
- );
15
container = document.createElement("div");
16
document.body.append(container);
17
root = createRoot(container);
@@ -31,7 +21,6 @@ afterEach(async () => {
21
await act(async () => root.unmount());
22
container.remove();
23
vi.unstubAllGlobals();
34
- vi.useRealTimers();
24
});
25
26
async function renderPanel(
@@ -76,17 +65,20 @@ async function renderPanel(
65
</Dialog.Root>,
66
);
67
});
79
- await act(async () => vi.advanceTimersToNextFrame());
68
+ await act(nextFrame);
69
+}
70
+
71
+function nextFrame() {
72
+ return new Promise<void>((resolve) => requestAnimationFrame(() => resolve()));
73
}
74
75
+// Tabbing past the popup's last control wraps through Base UI's focus guard
76
+// to the first tabbable descendant, which skips anything inert.
77
async function enterFocusScope() {
83
- // Base UI's focus guard models Tab wrapping into the scope. Its production
84
- // focus manager chooses the first tabbable descendant, including inert rules
85
- // that jsdom's native focus() does not implement.
86
- const guards = document.querySelectorAll<HTMLElement>("[data-base-ui-focus-guard]");
87
- expect(guards.length).toBe(2);
88
- await act(async () => guards[1]!.focus());
89
- await act(async () => vi.advanceTimersToNextFrame());
78
+ const toggle = document.querySelector<HTMLElement>('[aria-label="Toggle right panel"]')!;
79
+ await act(async () => toggle.focus());
80
+ await act(() => userEvent.tab());
81
+ await act(nextFrame);
82
}
83
84
describe("right panel keyboard access", () => {
apps/web/src/components/pullRequest/PullRequestCandidatePicker.browser.test.tsx
renamed
+11
-28
@@ -1,8 +1,7 @@
1
-// @vitest-environment jsdom
2
-
1
import { act } from "react";
2
import { createRoot, type Root } from "react-dom/client";
3
import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
4
+import { userEvent } from "vite-plus/test/browser";
5
6
import { PullRequestCandidatePicker } from "./PullRequestCandidatePicker";
7
@@ -11,14 +10,6 @@ let container: HTMLDivElement;
10
11
beforeEach(() => {
12
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
14
- vi.stubGlobal(
15
- "ResizeObserver",
16
- class {
17
- observe() {}
18
- unobserve() {}
19
- disconnect() {}
20
- },
21
- );
13
container = document.createElement("div");
14
document.body.append(container);
15
root = createRoot(container);
@@ -28,7 +19,6 @@ afterEach(async () => {
19
await act(async () => root.unmount());
20
container.remove();
21
vi.unstubAllGlobals();
31
- vi.useRealTimers();
22
});
23
24
describe("disabled candidate picker", () => {
@@ -69,27 +59,20 @@ describe("disabled candidate picker", () => {
59
'button[aria-label="Request reviewers"]',
60
)!;
61
if (input === "keyboard") {
72
- await act(async () => {
73
- document.dispatchEvent(new KeyboardEvent("keydown", { key: "Tab", bubbles: true }));
74
- trigger.focus();
75
- });
62
+ await act(() => userEvent.tab());
63
expect(document.activeElement).toBe(trigger);
64
} else {
78
- vi.useFakeTimers();
79
- await act(async () => {
80
- trigger.dispatchEvent(new MouseEvent("mouseover", { bubbles: true }));
81
- trigger.dispatchEvent(new MouseEvent("mouseenter"));
82
- trigger.dispatchEvent(new MouseEvent("mousemove", { bubbles: true }));
83
- await vi.advanceTimersByTimeAsync(1000);
84
- });
65
+ await act(() => userEvent.hover(trigger));
66
}
86
- expect(
87
- document.querySelector('[data-slot="tooltip-popup"][data-open]')?.textContent,
88
- ).toContain("Only collaborators can request reviewers.");
67
+ await expect
68
+ .poll(() => document.querySelector('[data-slot="tooltip-popup"][data-open]')?.textContent)
69
+ .toContain("Only collaborators can request reviewers.");
70
await act(async () => {
90
- trigger.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true }));
91
- trigger.dispatchEvent(new KeyboardEvent("keydown", { key: " ", bubbles: true }));
92
- trigger.click();
71
+ trigger.focus();
72
+ await userEvent.keyboard("{Enter}");
73
+ await userEvent.keyboard(" ");
74
+ // Playwright skips aria-disabled targets; the click must still land to prove it is inert.
75
+ await userEvent.click(trigger, { force: true });
76
});
77
expect(onOpenChange).not.toHaveBeenCalled();
78
expect(onSelect).not.toHaveBeenCalled();
apps/web/src/components/settings/FontFamilyPicker.browser.test.tsx
renamed
+4
-33
@@ -1,8 +1,7 @@
1
-// @vitest-environment jsdom
2
-
1
import { act } from "react";
2
import { createRoot, type Root } from "react-dom/client";
3
import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
4
+import { userEvent } from "vite-plus/test/browser";
5
6
const families = vi.hoisted(() => {
7
const families = [
@@ -32,23 +31,6 @@ let container: HTMLDivElement;
31
32
beforeEach(async () => {
33
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
35
- vi.stubGlobal(
36
- "ResizeObserver",
37
- class {
38
- observe() {}
39
- disconnect() {}
40
- unobserve() {}
41
- },
42
- );
43
- // jsdom has no layout; give LegendList a 30px viewport and 30px rows so it
44
- // renders a window of rows the way it does in a browser.
45
- vi.spyOn(Element.prototype, "getBoundingClientRect").mockReturnValue(
46
- DOMRect.fromRect({ width: 288, height: 30 }),
47
- );
48
- Object.defineProperty(Element.prototype, "getAnimations", {
49
- configurable: true,
50
- value: () => [],
51
- });
34
container = document.createElement("div");
35
document.body.append(container);
36
root = createRoot(container);
@@ -68,14 +50,6 @@ function highlightedOptions(): string[] {
50
);
51
}
52
71
-async function typeQuery(input: HTMLInputElement, value: string) {
72
- const setValue = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")!.set!;
73
- await act(async () => {
74
- setValue.call(input, value);
75
- input.dispatchEvent(new Event("input", { bubbles: true }));
76
- });
77
-}
78
-
53
describe("FontFamilyPicker", () => {
54
it("highlights, moves through, and selects matches after filtering", async () => {
55
const onSelect = vi.fn();
@@ -93,14 +67,11 @@ describe("FontFamilyPicker", () => {
67
68
const input = document.querySelector<HTMLInputElement>('input[placeholder="Search fonts…"]');
69
expect(input).not.toBeNull();
96
- const press = (key: string) =>
97
- act(async () => {
98
- input!.dispatchEvent(new KeyboardEvent("keydown", { key, bubbles: true }));
99
- });
70
+ const press = (key: string) => act(() => userEvent.keyboard(`{${key}}`));
71
72
// Both matches were already rendered further down the unfiltered list.
102
- await typeQuery(input!, "co");
103
- expect(highlightedOptions()).toEqual(["Courier New"]);
73
+ await act(() => userEvent.type(input!, "co"));
74
+ await expect.poll(highlightedOptions).toEqual(["Courier New"]);
75
76
await press("ArrowDown");
77
expect(highlightedOptions()).toEqual(["Fira Code"]);
apps/web/src/components/usage/UsageLimitsPooled.browser.test.tsx
renamed
+8
-13
@@ -1,5 +1,3 @@
1
-// @vitest-environment jsdom
2
-
1
import {
2
EnvironmentId,
3
ProviderDriverKind,
@@ -10,6 +8,10 @@ import type { LimitPresentations } from "@t3tools/shared/usageLimits";
8
import { act } from "react";
9
import { createRoot, type Root } from "react-dom/client";
10
import { afterEach, beforeEach, expect, it, vi } from "vite-plus/test";
11
+import { userEvent } from "vite-plus/test/browser";
12
+
13
+// Real pointer clicks need the dialog's stacking styles to land above Base UI's modal overlay.
14
+import "~/index.css";
15
16
const consume = vi.hoisted(() => vi.fn());
17
vi.mock("../../state/session", () => ({
@@ -71,14 +73,6 @@ let container: HTMLDivElement;
73
74
beforeEach(async () => {
75
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
74
- vi.stubGlobal(
75
- "ResizeObserver",
76
- class {
77
- observe() {}
78
- disconnect() {}
79
- unobserve() {}
80
- },
81
- );
76
consume.mockReset();
77
container = document.createElement("div");
78
document.body.append(container);
@@ -97,7 +91,7 @@ async function click(label: string) {
91
(node) => node.textContent === label || node.getAttribute("aria-label")?.startsWith(label),
92
);
93
expect(button).toBeDefined();
100
- await act(() => button!.click());
94
+ await act(() => userEvent.click(button!));
95
}
96
97
it.each([
@@ -123,8 +117,9 @@ it.each([
117
await click("Use reset");
118
await click("Use credit");
119
expect(consume).toHaveBeenCalledOnce();
126
- expect(document.querySelector('[role="alertdialog"]')).toBeNull();
127
- expect(document.querySelector('[data-slot="popover-popup"]')).toBeNull();
120
+ // Both popups unmount once their exit animations finish.
121
+ await expect.poll(() => document.querySelector('[role="alertdialog"]')).toBeNull();
122
+ await expect.poll(() => document.querySelector('[data-slot="popover-popup"]')).toBeNull();
123
const status = document.querySelector('[role="status"]');
124
expect(status?.textContent).toBe("Alpha Using reset credit…");
125
await click("Alpha:");