Skip to content

fix(test): stabilize flaky trace view keyboard navigation test#111917

Draft
JoshuaKGoldberg wants to merge 18 commits intomasterfrom
fix/flaky-trace-keyboard-nav-spec
Draft

fix(test): stabilize flaky trace view keyboard navigation test#111917
JoshuaKGoldberg wants to merge 18 commits intomasterfrom
fix/flaky-trace-keyboard-nav-spec

Conversation

@JoshuaKGoldberg
Copy link
Copy Markdown
Member

@JoshuaKGoldberg JoshuaKGoldberg commented Mar 31, 2026

Summary

  • Fixes flaky test trace view › keyboard navigation › arrowup+shift scrolls to the start of the list which was previously skipped with it.skip
  • The test scrolls a virtualized trace list from end back to start using Shift+ArrowUp, then asserts that transaction-op-0 is visible. The flake occurred because the findByText assertion could time out before the virtualized list finished re-rendering after a large scroll

Root Cause

After Shift+ArrowUp scrolls the virtualized list from item 99 back to item 0 across 100 rows, the test immediately called findByText(/transaction-op-0/i) which has a default 1s timeout. The virtualized list may not have finished re-rendering the first row within that window, causing the flake.

Additionally, the test used inconsistent patterns compared to its working sibling test (arrowdown+shift scrolls to the end of the list):

  • Used getVirtualizedRows(virtualizedContainer) instead of container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR)
  • Started from rows[1] instead of rows[0]

Fix

  1. Wait for focus before asserting text: After Shift+ArrowUp, wait for rows[0] to receive focus (via waitFor) before checking for the text. Focus settling confirms the virtualized list has completed scrolling and rendering. This matches the pattern used in the working arrowdown on last node jumps to start test.
  2. Consistent row querying: Use container.querySelectorAll(VISIBLE_TRACE_ROW_SELECTOR) to match the sibling test pattern.
  3. Start from rows[0]: Match the sibling test for consistency.
  4. Removed it.skip and the associated eslint-disable comment.

Fixes BROWSE-411

Note that CI Jest tests are failing because the Frontend: Rerun Flaky Tests Known flaky tests should be run many times, just to be safe. label is causing other, still-flaky tests to be run.

Made with Cursor

JoshuaKGoldberg and others added 3 commits March 31, 2026 09:34
Adds infrastructure for validating flaky test fixes in CI:

- `itRepeatsWhenFlaky()`: a test wrapper in tests/js/sentry-test/ that
  runs a test 50x when the RERUN_KNOWN_FLAKY_TESTS env var is set,
  otherwise runs once as a normal it()
- CI wiring: frontend.yml sets RERUN_KNOWN_FLAKY_TESTS=true when the PR
  has the "Frontend: Rerun Flaky Tests" label
- ESLint: configured jest/no-standalone-expect to recognize
  itRepeatsWhenFlaky as a test block

Wraps all 13 known flaky tests (identified from 30 days of CI failures
on master) with itRepeatsWhenFlaky so fixes can be stress-tested:
- eventReplay/index.spec.tsx (6 occ)
- stackTrace.spec.tsx (5 occ)
- resultsSearchQueryBuilder.spec.tsx (5 occ, 2 tests)
- metricsTab.spec.tsx (4 occ)
- customerDetails.spec.tsx (4 occ)
- eventsSearchBar.spec.tsx (3 occ)
- trace.spec.tsx (3 occ, previously skipped)
- allMonitors.spec.tsx (2 occ)
- spansSearchBar.spec.tsx (2 occ)
- react-native/metrics.spec.tsx (2 occ)
- useReplaysFromIssue.spec.tsx (2 occ)
- spanEvidencePreview.spec.tsx (2 occ)
- groupingInfoSection.spec.tsx (2 occ)

Made-with: Cursor
@JoshuaKGoldberg JoshuaKGoldberg added Scope: Frontend Automatically applied to PRs that change frontend components Frontend: Rerun Flaky Tests Known flaky tests should be run many times, just to be safe. labels Mar 31, 2026
@JoshuaKGoldberg JoshuaKGoldberg changed the title fix(test): Fix flaky trace view keyboard navigation test fix(test): stabilize flaky trace view keyboard navigation test Mar 31, 2026
@linear-code
Copy link
Copy Markdown

linear-code bot commented Apr 1, 2026

Un-skips and fixes the flaky "arrowup+shift scrolls to the start
of the list" test by using waitFor with longer timeouts for the
virtualized row assertions. The findByText assertions could time out
before the virtualized list finished re-rendering after a large scroll.

Made-with: Cursor
@JoshuaKGoldberg JoshuaKGoldberg force-pushed the fix/flaky-trace-keyboard-nav-spec branch from 1b2ad25 to ee10dda Compare April 1, 2026 18:45
@JoshuaKGoldberg JoshuaKGoldberg changed the base branch from fix/flaky-test-rerun-infra to master April 7, 2026 14:09
@JoshuaKGoldberg JoshuaKGoldberg removed the Frontend: Rerun Flaky Tests Known flaky tests should be run many times, just to be safe. label Apr 7, 2026
@JoshuaKGoldberg JoshuaKGoldberg added the Frontend: Rerun Flaky Tests Known flaky tests should be run many times, just to be safe. label Apr 15, 2026
during search, expanding a row retriggers search used within(container).findByText(/transaction-op-0/i), which throws when multiple nodes match the same op label (e.g. virtualized rows plus other UI). Match keyboardNavigationTestSetup by scoping to the virtualized list and using findAllByText for transaction-op- rows.

Fixes CI failure in Jest (1) for trace.spec.

Fixes BROWSE-411.

Made-with: Cursor
… rerun

Wait for the search result iterator to advance to the second match after arrowdown before asserting the highlighted row index. Combine highlight assertions into a single waitFor so the index is checked on the same DOM snapshot as the highlight count.

Re-query virtualized rows immediately before each click so clicks target current nodes after list updates. Raise the known-flake timeout for the row-click test to 12s so repeated search resolution under load stays within Jest limits.

Fixes BROWSE-411.

Made-with: Cursor
The search result iterator can remain on the first match index while arrowdown moves the highlighted row, so waiting for a 2/ prefix was incorrect and failed in CI.

Allow a longer waitFor in assertHighlightedRowAtIndex for the highlighted-persistence test and raise that known-flake test Jest timeout so slow virtualized updates can finish.

Fixes BROWSE-411.

Made-with: Cursor
ArrowDown from the search field did not reliably move the active search highlight to the second result within the wait window under CI load. Click the second visible trace row after results resolve instead, which matches user intent and stabilizes the setup for the persistence assertions.

Fixes BROWSE-411.

Made-with: Cursor
assertHighlightedRowAtIndex used the full render container while row clicks used getVirtualizedRows(virtualizedContainer), so visible-row indices could disagree when other TraceRow nodes exist outside the list.

Fixes BROWSE-411.

Made-with: Cursor
Visible row index 2 is not always the second search hit, and DOM node identity does not survive re-renders. Click the second .SearchResult row, record the highlighted row TraceOperation text, then assert that text is unchanged after narrowing the query.

Fixes BROWSE-411.

Made-with: Cursor
…test

Click the search field before appending act so typing applies to the input. Wait for focus before pasting the no-match query. Restore container-scoped highlight count for the no-results case to match prior behavior.

Fixes BROWSE-411.

Made-with: Cursor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Frontend: Rerun Flaky Tests Known flaky tests should be run many times, just to be safe. Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant