[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.
Ricky committed
Jan 18, 2026 at 15:36 UTC
195fd2286bcc3286859651d6709e5ae5a250335b
2 files changed
+23
packages/internal-test-utils/debugInfo.js
+12
@@ -79,6 +79,18 @@ function normalizeIOInfo(config: DebugInfoConfig, ioInfo) {
79
status: promise.status,
80
};
81
}
82
+ } else if ('value' in ioInfo) {
83
+ // If value exists in ioInfo but is undefined (e.g., WeakRef was GC'd),
84
+ // ensure we still include it in the normalized output for consistency
85
+ copy.value = {
86
+ value: undefined,
87
+ };
88
+ } else if (ioInfo.name && ioInfo.name !== 'rsc stream') {
89
+ // For non-rsc-stream IO that doesn't have a value field, add a default.
90
+ // This handles the case where the server doesn't send the field when WeakRef is GC'd.
91
+ copy.value = {
92
+ value: undefined,
93
+ };
94
}
95
return copy;
96
}
scripts/jest/setupTests.js
+11
@@ -319,3 +319,14 @@ jest.mock('async_hooks', () => {
319
},
320
};
321
});
322
+
323
+// Ensure async hooks are disabled after each test to prevent cross-test pollution.
324
+// This is needed because test files that load the Node server (with async debug hooks)
325
+// can pollute test files that load the Edge server (which doesn't create new hooks
326
+// to trigger the cleanup in the mock above).
327
+afterEach(() => {
328
+ if (installedHook) {
329
+ installedHook.disable();
330
+ installedHook = null;
331
+ }
332
+});