Repository navigation
test(frontend): hold the drawer slides until the test presses Escape - #397
Conversation
The drawer tests that press Escape while the drawer slides in checked that the drawer still slides in. The React Aria Sheet ends its slide-in on the scrollend of its smooth scroll, about 500 ms after the drawer opens. On a slow runner the test reached that check after the slide ended, and failed. Each such test now holds the scrollend of the sheet scroller and the react-aria-sheet-close event of the overlay until the test pressed Escape, then lets them through. The slides now end when the test says, on a runner of any speed. With the Escape fix of #391 reverted, the four tests that close the drawer on Escape still fail.
Independent verification of #397: PASS+NOTESGoal: CI with no flaky drawer tests. I checked head Each loop ran
I read The CI checks on this PR pass. Notes:
|
The drawer tests hold scrollend on [data-sheet-scroll] and react-aria-sheet-close. If an upgrade renames one, the hold catches nothing, the flake from #397 comes back, and no test shows why. A healthy run of the six tests that use the hold catches nothing on a fast machine, so they cannot make the check. A new test waits for each event.
The drawer tests hold scrollend on [data-sheet-scroll] and react-aria-sheet-close. If an upgrade renames one, the hold catches nothing, the flake from #397 comes back, and no test shows why. A healthy run of the six tests that use the hold catches nothing on a fast machine, so they cannot make the check. A new test waits for each event.
…#427) ## Why If a `react-aria-components` upgrade renames an event that the drawer tests hold, the hold catches nothing and the flake from #397 comes back with no failing test to explain it. This PR adds a test that fails with a message that names the event. Closes #405 ## What changed - A new test in `drawer.test.tsx` opens a drawer with the hold on, and waits for `scrollend` on `[data-sheet-scroll]`. Then it presses Escape and waits for `react-aria-sheet-close`. It also checks that the drawer stays in `data-entering` and in `data-exiting` while the events are held, and that it closes when they are released. - `holdSlides()` now returns `{ endSlides, held }`, so that the new test can read what it caught. ## Scope - The check is in one new test, not in the six tests that use the hold. On a fast machine those six tests hold nothing when they call `endSlides()`, because they press Escape before the slide ends. An assert in them would fail on a correct run. - Known gap: `scrollend` is a browser event, so an upgrade cannot rename it. An upgrade can stop waiting for it. The test catches that only if the slide ends within about 50 ms of the event. ## Tradeoffs - Each wait has a 10 s limit and the test has a 30 s limit. A correct run ends each wait when the event arrives. A stall of up to about 10 s in a wait does not fail the test. A longer stall fails it, and the message names a stalled runner as a possible cause. The 30 s limit gives a real rename its message and not a test timeout. ## Blast Radius Only the drawer test file changes. The new test adds about 1.2 s to the suite. ## Verification - Five mistakes in the hold each fail only the new test, with a message that names the fault: the `scrollend` listener, the `react-aria-sheet-close` listener, the `data-sheet-scroll` attribute, and each of the two events no longer stopped. Before this change, all tests passed with both event names wrong. - The drawer tests pass 25 of 25 runs, one at a time, with a machine load average of about 100. - `pnpm lint` passes, and `pnpm test` passes 628 of 628 on the final base.
Why
CI must have no flaky tests. On #396, the
api-contractjob failed atdrawer.test.tsx:170withexpected false to be true. That PR does not touch the drawer, and a rerun passed.Cause
The React Aria
Sheetends its slide-in on thescrollendof its scroller. It ends its slide-out on areact-aria-sheet-closeevent. Each comes about 500 ms after the slide starts, on a real-time clock. CPU throttling does not slow it, even at 20x. The tests that press Escape "while it slides in" reach theirdata-enteringcheck after 130 to 270 ms on a fast machine. A slow runner reaches it after the slide ended.This is not a product bug. A real user can press Escape after the slide ends, and the drawer handles that too.
Fix
holdSlides()in the test file stops those two events before the Sheet gets them.endSlides()sends them again after the test presses Escape.onTestFinishedalso calls it. Six tests use it: each test that checksdata-entering, and the "twice fast" test, which also raced the slide-out.Proof
slowMo: 150With the #391 fix reverted (no
CloseOnEscapeindrawer.tsx), the four Escape tests still fail 3 of 3 times. So the tests still catch that bug.pnpm lint,pnpm build, andpnpm test(524 tests) pass.