Skip to content

Commit 8edaffe

Browse files
Shawclaude
andcommitted
fix(ui): drain React 19 scheduler before jsdom teardown in App.cloud-shell test
CI's "Client Tests" job failed with an unhandled `ReferenceError: window is not defined` originating in `App.cloud-shell.test.tsx`. All 835 tests passed, but a React 19 scheduler callback queued via `setImmediate` fired after the per-file jsdom environment was torn down, after which `window` no longer exists. Add an `afterAll` that awaits a `setImmediate` tick so the scheduler's pending work runs while `window` is still alive, and an `afterEach` that calls testing-library's `cleanup` to unmount any straggler trees before the drain. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 947f17c commit 8edaffe

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

packages/ui/src/App.cloud-shell.test.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,22 @@
1414
import { readFileSync } from "node:fs";
1515
import { resolve } from "node:path";
1616

17-
import { render } from "@testing-library/react";
18-
import { beforeAll, describe, expect, it, vi } from "vitest";
17+
import { cleanup, render } from "@testing-library/react";
18+
import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from "vitest";
19+
20+
afterEach(() => {
21+
cleanup();
22+
});
23+
24+
// React 19's scheduler can post a `setImmediate` callback that runs AFTER
25+
// the test file completes but while Vitest is tearing down the per-file
26+
// jsdom environment, throwing `ReferenceError: window is not defined`
27+
// from react-dom-client.development.js. Drain the macrotask queue before
28+
// the environment is unwound so any pending scheduler work runs while
29+
// `window` still exists.
30+
afterAll(async () => {
31+
await new Promise<void>((resolve) => setImmediate(resolve));
32+
});
1933

2034
beforeAll(() => {
2135
if (typeof window.matchMedia !== "function") {

0 commit comments

Comments
 (0)