loadBundleFromServer test: remove legacy Jest timers, increased coverage and improved assertions#55863
Closed
chicio wants to merge 8 commits intofacebook:mainfrom
Closed
Conversation
Use promise to simulate RCTNetworking delayed callback (microtask flushed at the end of sync code sendRequest)
mocked request id is now shared between sendRequest mock and addListener mock
tests that check load bundle errors now catch then error and check with the expect. This avoid the problem of before implementation: if no error was thrown the tests were still green
Separated tests for checking loading bundle from root or from subdir. Added assertion for removeListener tests.
Tests now check that the addListener and removeListener number of calls matcher. This is testing the invariant that each registered listener should be remove (later on)
cortinico
approved these changes
Mar 3, 2026
Contributor
cortinico
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
Collaborator
|
This pull request was successfully merged by @chicio in a19d98e When will my fix make it into a release? | How to file a pick request? |
zoontek
pushed a commit
to zoontek/react-native
that referenced
this pull request
Mar 9, 2026
…age and improved assertions (facebook#55863) Summary: This PR removes the dependency on Jest legacy fake timers from the `loadBundleFromServer` test suite. Together with facebook#55757, this should remove the last usages of `jest.useFakeTimers({legacyFakeTimers: true});` in the codebase. In this PR in particular, instead of migrating to modern timers, I refactored the `addListener` mock to use a Promise based approach. By leveraging microtask scheduling, the tests simulate asynchronous functions flushed after the execution of the `sendRequest` without relying on timers. In addition, I also improved the tests in other areas: * improved readability by extracting a constant for the request id, used in both `sendRequest` and `addListener` mocks * improved errors assertions to explicitly verify the errors are thrown (before the refactoring these tests could still be green if no error was thrown, because the expectations were only in the catch clause that could be skipped) * improved the tests that verify the successful bundle load: * spit long test in ad hoc isolated ones * added listeners registration and cleanup verification to improve the coverage * added more fine-grained check for the `sendRequest` parameters I tried to separate all the changes above in specific commit so that the review can check the incremental improvements I applied with the refactoring steps. ## Changelog: [GENERAL] [CHANGED] - loadBundleFromServer test: remove legacy Jest timers, increased coverage and improved assertions Pull Request resolved: facebook#55863 Test Plan: * Ran loadBundleFromServer-test and verified all tests cases passed * Ran the React Native test suite to ensure all tests pass * Verified test correctness by intentionally breaking production code after fixing the tests (eg. remove observer/change listener code) Reviewed By: cortinico Differential Revision: D95034650 Pulled By: vzaidman fbshipit-source-id: f6ae7cbc95ccfe606c1054c9044bf733e41bc2f9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
This PR removes the dependency on Jest legacy fake timers from the
loadBundleFromServertest suite.Together with #55757, this should remove the last usages of
jest.useFakeTimers({legacyFakeTimers: true});in the codebase.In this PR in particular, instead of migrating to modern timers, I refactored the
addListenermock to use a Promise based approach. By leveraging microtask scheduling, the tests simulate asynchronous functions flushed after the execution of thesendRequestwithout relying on timers.In addition, I also improved the tests in other areas:
sendRequestandaddListenermockssendRequestparametersI tried to separate all the changes above in specific commit so that the review can check the incremental improvements I applied with the refactoring steps.
Changelog:
[GENERAL] [CHANGED] - loadBundleFromServer test: remove legacy Jest timers, increased coverage and improved assertions
Test Plan: