@devries-cameron20 / t3code Mirror · read-only / commits / fee2e0ff81
Fork 0

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 24, 11:30 UTC

test(web): fix flaky startup and Tailwind tests (#9558)

Theo Browne committed Sep 3, 2026 at 19:50 UTC fee2e0ff8168b82ab19f496fcc874c1f3871f522
2 files changed +21 -15
apps/web/src/bootstrap.test.ts
+4 -3
@@ -30,9 +30,6 @@ describe("app startup failures", () => {
30
31 beforeEach(() => {
32 vi.resetModules();
33 - vi.doMock("./main", () => {
34 - throw new Error("@vitejs/plugin-react can't detect preamble. Something is wrong.");
35 - });
33 bootShell = new BootElement("div");
34 vi.stubGlobal("document", {
35 getElementById: () => bootShell,
@@ -51,12 +48,16 @@ describe("app startup failures", () => {
48 });
49
50 afterEach(() => {
51 + vi.doUnmock("./main");
52 vi.unstubAllGlobals();
53 vi.unstubAllEnvs();
54 vi.restoreAllMocks();
55 });
56
57 it("replaces the splash when an app import throws before main can run", async () => {
58 + vi.doMock("./main", () => {
59 + throw new Error("@vitejs/plugin-react can't detect preamble. Something is wrong.");
60 + });
61 const reload = vi.fn();
62 vi.stubGlobal("window", { location: { reload } });
63
apps/web/src/bundledDev.test.ts
+17 -12
@@ -147,7 +147,8 @@ it("hot updates Tailwind classes when a source file changes in bundled dev", asy
147 );
148 const logger = createLogger("silent");
149 logger.error = (message) => events.emit("error", new Error(message));
150 - const built = NodeEvents.EventEmitter.once(events, "built");
150 + const connected = NodeEvents.EventEmitter.once(events, "connected");
151 + const ready = NodeEvents.EventEmitter.once(events, "ready");
152 server = await createServer({
153 configFile: false,
154 root,
@@ -168,19 +169,18 @@ it("hot updates Tailwind classes when a source file changes in bundled dev", asy
169 transform(code, id) {
170 if (id.endsWith("/style.css")) css = code;
171 },
171 - generateBundle() {
172 - events.emit("built");
172 + async generateBundle() {
173 + // Keep the build pending until the socket can receive Vite's ready message.
174 + await connected;
175 },
176 },
177 ],
178 server: { host: "127.0.0.1", port: 0 },
179 });
180 await server.listen();
179 - await built;
181 const address = server.httpServer?.address();
182 if (!address || typeof address === "string") throw new Error("Vite did not bind a port");
183
183 - const connected = NodeEvents.EventEmitter.once(events, "connected");
184 server.ws.on("vite:client-connected", () => events.emit("connected"));
185 socket = new WebSocket(
186 `ws://127.0.0.1:${address.port}/?token=${server.config.webSocketToken}`,
@@ -197,16 +197,21 @@ it("hot updates Tailwind classes when a source file changes in bundled dev", asy
197 });
198 socket.addEventListener("message", ({ data }) => {
199 const message: unknown = JSON.parse(String(data));
200 - if (
201 - message !== null &&
202 - typeof message === "object" &&
203 - "type" in message &&
204 - message.type === "bundled-dev-update"
205 - ) {
206 - events.emit("updated");
200 + if (message !== null && typeof message === "object" && "type" in message) {
201 + // generateBundle runs before Vite stores the files for HTTP requests.
202 + if (
203 + message.type === "full-reload" &&
204 + "ifFallback" in message &&
205 + message.ifFallback === true
206 + ) {
207 + events.emit("ready");
208 + } else if (message.type === "bundled-dev-update") {
209 + events.emit("updated");
210 + }
211 }
212 });
213 await connected;
214 + await ready;
215 const entry = await fetch(`http://127.0.0.1:${address.port}/assets/index.js`);
216 expect(entry.headers.get("content-type")).toContain("javascript");
217 await entry.text();