Skip to content

Commit 3cf3358

Browse files
authored
perf(test): speed up lazy UI lifecycle polling (#127025)
1 parent b6c5d84 commit 3cf3358

2 files changed

Lines changed: 19 additions & 17 deletions

File tree

‎ui/src/app/app-host-onboarding-memory-import.test.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* @vitest-environment jsdom */
22

33
import { afterEach, describe, expect, it, vi } from "vitest";
4+
import { waitForFast } from "../test-helpers/wait-for.ts";
45
import {
56
createLazyElementSpec,
67
resetAppHostTestGlobals,
@@ -29,10 +30,10 @@ describe("OpenClaw shell onboarding memory import", () => {
2930

3031
shell.lazyCustomElements.requestWhileActive(element, true);
3132

32-
await vi.waitFor(() => expect(shell.lazyCustomElements.visibleState?.status).toBe("error"));
33+
await waitForFast(() => expect(shell.lazyCustomElements.visibleState?.status).toBe("error"));
3334
expect(shell.lazyCustomElements.visibleState?.element).toBe(element);
3435
shell.lazyCustomElements.retry();
35-
await vi.waitFor(() => expect(customElements.get(element.tagName)).toBeDefined());
36+
await waitForFast(() => expect(customElements.get(element.tagName)).toBeDefined());
3637
expect(shell.lazyCustomElements.visibleState).toBeUndefined();
3738
});
3839

@@ -53,7 +54,7 @@ describe("OpenClaw shell onboarding memory import", () => {
5354
shell.onboardingMemoryImportElement = element;
5455

5556
shell.lazyCustomElements.requestWhileActive(element, true);
56-
await vi.waitFor(() => expect(element.loadModule).toHaveBeenCalledOnce());
57+
await waitForFast(() => expect(element.loadModule).toHaveBeenCalledOnce());
5758
expect(shell.lazyCustomElements.visibleState?.status).toBe("loading");
5859
shell.lazyCustomElements.requestWhileActive(element, false);
5960
const error = new Error("late memory import chunk failure");

‎ui/src/app/lazy-custom-element.test.ts‎

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* @vitest-environment jsdom */
22

33
import { describe, expect, it, vi } from "vitest";
4+
import { waitForFast } from "../test-helpers/wait-for.ts";
45
import {
56
ensureCustomElementDefined,
67
LazyCustomElementRequestController,
@@ -82,7 +83,7 @@ describe("optional custom element requests", () => {
8283
requests.request(element, continuation);
8384

8485
expect(requests.visibleState).toMatchObject({ status: "loading", element });
85-
await vi.waitFor(() =>
86+
await waitForFast(() =>
8687
expect(requests.visibleState).toMatchObject({
8788
status: "error",
8889
element,
@@ -95,7 +96,7 @@ describe("optional custom element requests", () => {
9596
requests.retry();
9697

9798
expect(requests.visibleState).toMatchObject({ status: "loading", element });
98-
await vi.waitFor(() => expect(continuation).toHaveBeenCalledOnce());
99+
await waitForFast(() => expect(continuation).toHaveBeenCalledOnce());
99100
expect(element.loadModule).toHaveBeenCalledTimes(2);
100101
expect(requests.visibleState).toBeUndefined();
101102
});
@@ -129,15 +130,15 @@ describe("optional custom element requests", () => {
129130
};
130131

131132
requests.requestWhileActive(activeElement, true);
132-
await vi.waitFor(() => expect(activeElement.loadModule).toHaveBeenCalledOnce());
133+
await waitForFast(() => expect(activeElement.loadModule).toHaveBeenCalledOnce());
133134
requests.request(foregroundElement);
134-
await vi.waitFor(() => expect(foregroundElement.loadModule).toHaveBeenCalledOnce());
135+
await waitForFast(() => expect(foregroundElement.loadModule).toHaveBeenCalledOnce());
135136
resolveForeground?.();
136-
await vi.waitFor(() => expect(requests.visibleState?.element).toBe(activeElement));
137+
await waitForFast(() => expect(requests.visibleState?.element).toBe(activeElement));
137138

138139
const error = new Error("active chunk unavailable");
139140
rejectActive?.(error);
140-
await vi.waitFor(() =>
141+
await waitForFast(() =>
141142
expect(requests.visibleState).toMatchObject({
142143
element: activeElement,
143144
error,
@@ -162,7 +163,7 @@ describe("optional custom element requests", () => {
162163
};
163164

164165
requests.requestWhileActive(element, true);
165-
await vi.waitFor(() => expect(requests.visibleState?.status).toBe("error"));
166+
await waitForFast(() => expect(requests.visibleState?.status).toBe("error"));
166167
requests.close();
167168
requests.requestWhileActive(element, true);
168169

@@ -171,7 +172,7 @@ describe("optional custom element requests", () => {
171172

172173
requests.requestWhileActive(element, false);
173174
requests.requestWhileActive(element, true);
174-
await vi.waitFor(() => expect(element.loadModule).toHaveBeenCalledTimes(2));
175+
await waitForFast(() => expect(element.loadModule).toHaveBeenCalledTimes(2));
175176
});
176177

177178
it("delegates stale recovery before falling back to the same in-place load", async () => {
@@ -191,12 +192,12 @@ describe("optional custom element requests", () => {
191192
};
192193

193194
requests.request(element, continuation);
194-
await vi.waitFor(() => expect(requests.visibleState?.status).toBe("error"));
195+
await waitForFast(() => expect(requests.visibleState?.status).toBe("error"));
195196
expect(requests.visibleState).toMatchObject({ stale: true });
196197

197198
requests.retry();
198199

199-
await vi.waitFor(() => expect(continuation).toHaveBeenCalledOnce());
200+
await waitForFast(() => expect(continuation).toHaveBeenCalledOnce());
200201
expect(retryStale).toHaveBeenCalledOnce();
201202
expect(element.loadModule).toHaveBeenCalledTimes(2);
202203
});
@@ -222,12 +223,12 @@ describe("optional custom element requests", () => {
222223

223224
requests.request(element, continuation);
224225
expect(requests.visibleState?.status).toBe("loading");
225-
await vi.waitFor(() => expect(element.loadModule).toHaveBeenCalledOnce());
226+
await waitForFast(() => expect(element.loadModule).toHaveBeenCalledOnce());
226227

227228
requests.close();
228229
resolveLoad?.();
229230

230-
await vi.waitFor(() => expect(customElements.get(element.tagName)).toBeDefined());
231+
await waitForFast(() => expect(customElements.get(element.tagName)).toBeDefined());
231232
expect(requests.visibleState).toBeUndefined();
232233
expect(continuation).not.toHaveBeenCalled();
233234
});
@@ -246,11 +247,11 @@ describe("optional custom element requests", () => {
246247
requests.preload(element);
247248
requests.preload(element);
248249

249-
await vi.waitFor(() => expect(element.loadModule).toHaveBeenCalledOnce());
250+
await waitForFast(() => expect(element.loadModule).toHaveBeenCalledOnce());
250251
expect(requests.visibleState).toBeUndefined();
251252

252253
requests.request(element);
253-
await vi.waitFor(() => expect(requests.visibleState?.status).toBe("error"));
254+
await waitForFast(() => expect(requests.visibleState?.status).toBe("error"));
254255
expect(element.loadModule).toHaveBeenCalledTimes(2);
255256
});
256257
});

0 commit comments

Comments
 (0)