next.js
7195ca2f - test: fix flaky dev-validation-worker-source-maps (#101524)

Commit
23 days ago
test: fix flaky dev-validation-worker-source-maps (#101524) ## Summary Fixes a flaky test, `test/development/app-dir/dev-validation-worker-source-maps/dev-validation-worker-source-maps.test.ts`. On canary it failed every in-job attempt in `test dev` (webpack). There were two races, both in the test: 1. **Stale redbox after the second edit.** The redbox from the first edit (`5:9`) is still open when the second edit lands. `toDisplayRedbox` doesn't retry, so it snapshotted the old frame before the HMR refresh replaced it with `7:9`. 2. **First validation after an edit can be stale.** One edit can trigger several Fast Refresh cycles and RSC refreshes. In the CI log, the first validation after the edit was aborted. The next one rendered the module from before the edit and logged nothing. Only the third one reported the error. `getDevCliValidationOutput` returns the *first* validation after the mark, so the test read empty output. Fix (test-only): - After the second edit, wait with `retry()` until `getRedboxSource()` shows `app/updated/page.tsx (7:9)`, then take the redbox snapshot once. Snapshot matchers are deliberately kept out of `retry()`: Jest records every failed attempt as a failed snapshot, and the suite exits 1 under `--ci`. - Add a test-local `getLatestDevCliValidationOutput` helper. It reads the latest *finished* validation of the URL since the mark, not the first one. It is called after the redbox shows the edit, so the validation that reported it has already started. It is used for the `/updated` and `/shared` edits. A worker that is genuinely stuck on an old update would still report the old frame on every validation, so the test still catches that bug. ## Verification - `CI=1 IS_WEBPACK_TEST=1 NEXT_TEST_MODE=dev NEXT_TEST_REACT_VERSION=18.3.1 __NEXT_EXPERIMENTAL_STRICT_ROUTE_TYPES=true node run-tests.js --retries 0 --runs 5 -c 2 <test>`: 5/5 passed on first attempt. - Under CPU stress (8 busy loops): `pnpm test-dev-webpack` 10/10 in two parallel lanes, `pnpm test-dev-turbo` 5/5. All exited 0 with every snapshot passing. <!-- NEXT_JS_LLM --> <!-- fleet bed5b445-101e-4438-a441-a6911cf4e8c6 --> Co-authored-by: vercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com> Co-authored-by: Fleet Dev Agent <fleet-agent@users.noreply.github.com> Co-authored-by: Tobias Koppers <1365881+sokra@users.noreply.github.com>
Author
Parents
Loading