[tests] Fix flaky flight tests (#35513)

Flights tests are failing locally and in CI non-deterministically
because we're not disabling async hooks after tests, and GC can clear
WeakRefs non-deterministically.

This PR fixes the issue by adding an afterEach to disable installed
hooks, and normalizing the `value` to `value: {value: undefined}}` when
snapshotting.
This commit is contained in:
Ricky authored and GitHub committed 2026-01-18 15:36:00 -05:00
1 parent d87298ae16
commit 195fd2286b
2 files changed
+23

No files matched your search

+12
View File
@@ -79,6 +79,18 @@ function normalizeIOInfo(config: DebugInfoConfig, ioInfo) {
status: promise.status,
};
}
} else if ('value' in ioInfo) {
// If value exists in ioInfo but is undefined (e.g., WeakRef was GC'd),
// ensure we still include it in the normalized output for consistency
copy.value = {
value: undefined,
};
} else if (ioInfo.name && ioInfo.name !== 'rsc stream') {
// For non-rsc-stream IO that doesn't have a value field, add a default.
// This handles the case where the server doesn't send the field when WeakRef is GC'd.
copy.value = {
value: undefined,
};
}
return copy;
}
+11
View File
@@ -319,3 +319,14 @@ jest.mock('async_hooks', () => {
},
};
});
// Ensure async hooks are disabled after each test to prevent cross-test pollution.
// This is needed because test files that load the Node server (with async debug hooks)
// can pollute test files that load the Edge server (which doesn't create new hooks
// to trigger the cleanup in the mock above).
afterEach(() => {
if (installedHook) {
installedHook.disable();
installedHook = null;
}
});