Unverified Commit a55efd47 authored by vercel-fleet-prod[bot]'s avatar vercel-fleet-prod[bot] Committed by GitHub

Run unit tests on Node 24

Wait for WebNextResponse onClose in its stream-body test instead of relying on undici microtask timing.

Account for AsyncContextFrame-backed AsyncLocalStorage in setImmediate uncaughtException tests.
Co-authored-by: 's avatarTobias Koppers <1365881+sokra@users.noreply.github.com>
parent fa1eab66
...@@ -706,7 +706,7 @@ jobs: ...@@ -706,7 +706,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
node: [20, 22] # TODO: use env var like [env.NODE_MAINTENANCE_VERSION, env.NODE_LTS_VERSION] node: [20, 22, 24] # TODO: use env var like [env.NODE_MAINTENANCE_VERSION, env.NODE_LTS_VERSION]
permissions: permissions:
contents: read contents: read
...@@ -783,7 +783,7 @@ jobs: ...@@ -783,7 +783,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
node: [20, 22] # TODO: use env var like [env.NODE_MAINTENANCE_VERSION, env.NODE_LTS_VERSION] node: [20, 22, 24] # TODO: use env var like [env.NODE_MAINTENANCE_VERSION, env.NODE_LTS_VERSION]
permissions: permissions:
contents: read contents: read
......
...@@ -3,6 +3,12 @@ import { WebNextResponse } from './web' ...@@ -3,6 +3,12 @@ import { WebNextResponse } from './web'
describe('WebNextResponse onClose', () => { describe('WebNextResponse onClose', () => {
it('stream body', async () => { it('stream body', async () => {
const cb = jest.fn() const cb = jest.fn()
// `onClose` is driven by the `pipeTo()` promise in `trackStreamConsumed`,
// which settles independently of the consumer observing the end of the
// body, so wait for the callback itself rather than assuming an ordering.
const closed = new Promise<void>((resolve) => {
cb.mockImplementation(() => resolve())
})
const ts = new TransformStream({ const ts = new TransformStream({
transform(chunk, controller) { transform(chunk, controller) {
controller.enqueue(chunk) controller.enqueue(chunk)
...@@ -24,6 +30,7 @@ describe('WebNextResponse onClose', () => { ...@@ -24,6 +30,7 @@ describe('WebNextResponse onClose', () => {
await writer.close() await writer.close()
const text = await t const text = await t
await closed
expect(cb).toHaveBeenCalledTimes(1) expect(cb).toHaveBeenCalledTimes(1)
expect(text).toBe('abcdef') expect(text).toBe('abcdef')
}) })
......
...@@ -30,6 +30,36 @@ function createLogger() { ...@@ -30,6 +30,36 @@ function createLogger() {
return { logs, log } return { logs, log }
} }
/**
* Whether `AsyncLocalStorage` is backed by `AsyncContextFrame`, which makes the
* async context visible in `uncaughtException` handlers. It is enabled by
* default in Node.js 24+ and opt-in via `--experimental-async-context-frame`
* in earlier versions. Node.js 24 also accepts `--async-context-frame`. Flags
* in `NODE_OPTIONS` are applied before CLI flags, and the last matching flag
* wins.
*/
function isAsyncContextFrameEnabled(): boolean {
let enabled = Number(process.versions.node.split('.')[0]) >= 24
const flags = [
...(process.env.NODE_OPTIONS ?? '').split(/\s+/),
...process.execArgv,
]
for (const flag of flags) {
if (
flag === '--async-context-frame' ||
flag === '--experimental-async-context-frame'
) {
enabled = true
} else if (
flag === '--no-async-context-frame' ||
flag === '--no-experimental-async-context-frame'
) {
enabled = false
}
}
return enabled
}
it('runs immediates after each task', async () => { it('runs immediates after each task', async () => {
const { log, logs } = createLogger() const { log, logs } = createLogger()
const done = createPromiseWithResolvers<void>() const done = createPromiseWithResolvers<void>()
...@@ -1662,9 +1692,8 @@ describe('uncaught errors in setImmediate do not affect surrounding tasks or oth ...@@ -1662,9 +1692,8 @@ describe('uncaught errors in setImmediate do not affect surrounding tasks or oth
'timeout 1 -> immediate 1', 'timeout 1 -> immediate 1',
'timeout 1 -> immediate 1 -> nextTick', // undesirable (too early) but acceptable 'timeout 1 -> immediate 1 -> nextTick', // undesirable (too early) but acceptable
// FIXME: no async context in uncaughtException // FIXME: without AsyncContextFrame, there's no async context in uncaughtException
// `uncaughtException - ${contextValue}`, `uncaughtException - ${isAsyncContextFrameEnabled() ? contextValue : undefined}`,
`uncaughtException - undefined`,
// ====================== // ======================
'timeout 1 -> immediate 2', 'timeout 1 -> immediate 2',
...@@ -1728,9 +1757,8 @@ describe('uncaught errors in setImmediate do not affect surrounding tasks or oth ...@@ -1728,9 +1757,8 @@ describe('uncaught errors in setImmediate do not affect surrounding tasks or oth
'timeout 1 -> immediate 1', 'timeout 1 -> immediate 1',
`timeout 1 -> immediate 1 -> nextTick - ${contextValue}`, `timeout 1 -> immediate 1 -> nextTick - ${contextValue}`,
// FIXME: no async context in uncaughtException // FIXME: without AsyncContextFrame, there's no async context in uncaughtException
// `uncaughtException - ${contextValue}`, `uncaughtException - ${isAsyncContextFrameEnabled() ? contextValue : undefined}`,
`uncaughtException - undefined`,
// ====================== // ======================
'timeout 1 -> immediate 2', 'timeout 1 -> immediate 2',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment