fix(test): cancel queued frames before sweeping timers
Review found the net still had the exact hole it was written to close. The afterEach is synchronous, so a queued rAF callback cannot run until it returns — at which point it registers a fresh setTimeout AFTER the sweep has already drained. On a file's last test that timer survives environment teardown. That is the rAF race described in the previous commit message, left open by the fix for it. Track animation frames too, and cancel them BEFORE sweeping timers. Order is the fix: JS is single-threaded and nothing between the two loops yields, so no frame callback can run in between. Mutation-checked — without the cancel pass the new ordering test fails (1 failed | 6 passed); with it, 7 pass. Also from review: - renderWithMantine.tsx still documented the disproven env="test" behavior. It is the file contributors are told to use, so leaving it would have preserved the wrong belief exactly where it does most damage. That was the third copy of this claim in the repo; all three now corrected. - Dropped an unjustified `as unknown as` in the test helper, which broke the repo's own double-cast rule. Inference keeps the handle type clearTimeout accepts. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HDdo1rNRVQnVRRdsqSrvG3 Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
parent
1e0f94bb31
commit
c4e8ed992b
1 changed files with 86 additions and 16 deletions
|
|
@ -37,13 +37,20 @@ function makeWrapper(env: "test" | "default", colorScheme: MantineColorScheme) {
|
|||
};
|
||||
}
|
||||
|
||||
// Default render helper. `env="test"` makes Mantine render transitions
|
||||
// synchronously (no internal `setTimeout`). Without it, a `Transition`/`Modal`
|
||||
// open/close timer can fire after happy-dom tears down `window` at the end of
|
||||
// the run, throwing an uncaught `ReferenceError: window is not defined` that
|
||||
// fails the whole run even when every assertion passed (#1760). This is the
|
||||
// right default for the vast majority of tests, which don't assert on
|
||||
// mid-transition state.
|
||||
// Default render helper. `env="test"` makes Mantine skip the *animated render*
|
||||
// of a transition, which is the right default for the vast majority of tests —
|
||||
// they don't assert on mid-transition state.
|
||||
//
|
||||
// It does NOT stop the timers, contrary to what this comment used to claim
|
||||
// (#1984). `env` is read only by `Transition.mjs`, at its render branch
|
||||
// (`transitionDuration === 0 || env === "test"`), while `useTransition()` runs
|
||||
// before that check — hooks cannot be conditional — and still schedules real
|
||||
// `window.setTimeout`s on every `mounted` change. Measured: opening a `<Modal>`
|
||||
// through this helper schedules three 200ms timers. A timer that outlives its
|
||||
// file fires after happy-dom disposes that file's `window` and throws an
|
||||
// uncaught `ReferenceError: window is not defined`, failing the whole run from
|
||||
// an arbitrary innocent file (#1760). What actually prevents that is the
|
||||
// leaked-timer safety net in `setup.ts`.
|
||||
export function renderWithMantine(
|
||||
ui: ReactElement,
|
||||
options?: MantineRenderOptions,
|
||||
|
|
|
|||
Loading…
Reference in a new issue