next.js
1aa680d3 - Run unit tests on Node.js 24 (#100560)

Commit
3 hours ago
Run unit tests on Node.js 24 (#100560) ### What? Adds Node.js 24 to the `test unit` and `test unit windows` CI matrices (`[20, 22, 24]`), and fixes the two unit test files that fail on Node 24. ### Why? Unit tests only ran on Node 20 and 22, so Node 24-specific failures went unnoticed. They show up when running `pnpm test-unit` locally on Node 24. The rest of the suite was already green on Node 24; there were two independent causes: - **`server/base-http/web.test.ts` › `WebNextResponse onClose` › `stream body`** assumed `onClose` fires before `await response.text()` resolves. - `onClose` is driven by the `pipeTo()` promise in `trackStreamConsumed`, which settles independently of the body consumer. Even on Node 20/22, a plain stream reader sees end-of-body before the callback. - The assertion held only because older undici versions took more microtask ticks inside `Response.text()`. With undici ≥ 7.16 (bundled since Node 24.9) it fails deterministically. - Swapping only the undici package on a fixed Node binary reproduces the shift. - **`node-environment-extensions/fast-set-immediate.external.test.ts`** (two `uncaughtException` tests) hard-coded that `AsyncLocalStorage` context is lost in `uncaughtException` handlers, under a FIXME. - Node 24 enables `AsyncContextFrame` by default, and the context is now preserved. The tests pass on Node 24 with `--no-async-context-frame`. ### How? Test-only changes; no runtime code changes. - **Stream body test:** waits for the close callback itself (the mock resolves a promise) instead of assuming a microtask ordering. The existing assertions are kept, and a missing callback still fails via the test timeout. - I deliberately did not change `trackStreamConsumed` to fire earlier: it avoids `Transformer.cancel` on purpose for older Node 20 support, and the "after the body is consumed" semantics are what its consumers (`after()`, close hooks) need. - **`uncaughtException` tests:** the expected context value now depends on whether `AsyncContextFrame` is active. - A small local helper derives this from the Node major version and the relevant flags (`--async-context-frame`, `--experimental-async-context-frame`, and their `--no-` forms). - It reads `NODE_OPTIONS` before CLI flags, and the last matching flag wins. - All other ordering and error assertions are unchanged. - **CI:** both matrices use the major version `24`, matching the existing `20`/`22` entries. The unit jobs don't install Playwright, so the Playwright/Node 24.16 pin used by other jobs doesn't apply. ### Verification - `node run-tests.js --type unit` passes on Node 24.15.0 and 22.22.0. - `fast-set-immediate.external.test.ts` passes on Node 20, 22 and 24 with default flags. It also passes with `AsyncContextFrame` opted in or out through `NODE_OPTIONS`, the CLI, and conflicting combinations of both. <!-- NEXT_JS_LLM --> <!-- fleet 9c97796f-a83b-441b-a176-e8b833adf1c5 --> Co-authored-by: vercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com> Co-authored-by: Tobias Koppers <1365881+sokra@users.noreply.github.com>
Author
Parents
Loading