fix(webapp): stop feed page tests flaking on a cold jest cache - #6532
Merged
Conversation
MainFeedLayout only reaches the feed pages through next/dynamic, so its module graph is compiled inside the first findBy*/waitFor call. That compile takes ~470ms with a warm jest transform cache but over 3 seconds with a cold one, which blows RTL's 1000ms default timeout and fails with "Unable to find an element by: [data-testid=postItem]". CI restores no jest transform cache and reorders test files between runs (--runInBand with --split-by=timings), so whichever feed page test lands first pays the compile. That is why the failure showed up on main and on unrelated PRs. Preload the module in beforeAll so the compile no longer sits inside the wait window, raise the file timeout to cover that compile, and give the feed waits an explicit budget. A cold-cache sweep over the other feed page tests found only these four affected, all of them pages whose getLayout is getMainFeedLayout. Cold-cache duration of the affected tests drops from 2992-4145ms (failing) to 494-678ms (passing).
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
packages/webapp/__tests__/MyFeedPage.tsx→should request user feedfails intermittently withUnable to find an element by: [data-testid="postItem"]. Seen onmain(CircleCI build 161384) and on unrelated PRs (#6531, build 161573).Root cause
MainFeedLayoutonly reaches the feed pages throughnext/dynamic, so its module graph is compiled by babel-jest inside the firstfindBy*wait. An event-loop heartbeat during the test shows it plainly:With a warm transform cache that is ~470ms of a 1000ms budget. With a cold one the same block runs 3s+, and the test fails deterministically:
CI reproduces this by accident:
test_webappruns--runInBandwithcircleci tests run --split-by=timingsand restores only the pnpm deps cache, never a jest transform cache. File order changes between runs, so whichever feed page test lands first in the container pays the compile and fails; when another feed test runs first, the cache is warm and it passes.Fix
Preload the module in
beforeAllso the compile no longer sits inside the wait window, raise the file timeout to cover that compile, and give the feed waits an explicit budget.Scope
A cold-cache sweep over 14 candidate test files found exactly four affected, all of them pages whose
getLayoutisgetMainFeedLayout(the only path that reachesMainFeedLayoutthroughnext/dynamic):TagPage, KeywordPage, SquadFeedPage, SearchPage, SearchResultsPage, BookmarksPage, HistoryPage and the Profile* feed tests all pass cold — they reach the feed through static imports, so their compile happens at module load. That also clears
waitForNock's hardcoded 1000ms in practice, so no shared helper or global jest config change is included here.Two incidental cleanups in the files being touched:
MostUpvotedPage's existing{ timeout: 3000 }was below the observed 4145ms, andMostDiscussedPagehad a nestedwaitFor(async () => findAllByTestId(...))where a 1s inner wait sat inside a 1s outer one.Verification
--cacheDirectory), all four files: pass--ci --runInBand): 74 suites, 587 tests, all passeslintandnode ./scripts/typecheck-strict-changed.js: cleanPreview domain
https://claude-youthful-saha-7e3dd2.preview.app.daily.dev