mirror of
https://github.com/facebook/react.git
synced 2026-11-18 20:15:56 +00:00
[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:
1 parent
d87298ae16
commit
195fd2286b
2 files changed
+23
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user