LogBoxData test migrated to Jest modern timers#55757
Closed
chicio wants to merge 1 commit intofacebook:mainfrom
Closed
LogBoxData test migrated to Jest modern timers#55757chicio wants to merge 1 commit intofacebook:mainfrom
chicio wants to merge 1 commit intofacebook:mainfrom
Conversation
Contributor
Author
|
Hi @cortinico, can you help me to import this and send to the right devs? The pipeline is green for the code that I modified (JS tests where I removed legacy timers). PS sorry for bothering you 😅 |
Contributor
Let me take a look at this on monday 👍 |
Contributor
|
/rebase |
3a710ab to
2bb868c
Compare
|
@cortinico has imported this pull request. If you are a Meta employee, you can view this in D94903193. |
Collaborator
|
This pull request was successfully merged by @chicio in dea2136 When will my fix make it into a release? | How to file a pick request? |
meta-codesync bot
pushed a commit
that referenced
this pull request
Mar 3, 2026
…age and improved assertions (#55863) Summary: This PR removes the dependency on Jest legacy fake timers from the `loadBundleFromServer` test 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 `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: #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
zoontek
pushed a commit
to zoontek/react-native
that referenced
this pull request
Mar 9, 2026
Summary: This PR migrates the LogBoxData tests so that it uses Jest modern timers. I removed the `legacyFakeTimers` property from `useFakeTimers` (like I did in the previous PR for Pressability tests facebook#55410), and moved it to a `beforeEach`. This in combination with restoring real timers in `afterEach` improves tests reliability and isolation. Then I modified some tests that started to fail by adding explicit `flushToObservers()`. The extra flushToObservers() calls are necessary because addLog/addException schedule processing using `setImmediate`, and inside that callback `handleUpdate()` schedules observer notifications using another `setImmediate` (so we need to flush twice to simulate the correct behaviour like it was already done in some other tests in the test suite). ## Changelog: [GENERAL] [CHANGED] - Migrated LogBoxData tests to Jest modern timers Pull Request resolved: facebook#55757 Test Plan: - Ran LogBoxData-test and verify 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. removing the `handleUpdate` call in `addException`, that changes the call to the `observer`) Reviewed By: fabriziocucci Differential Revision: D94903193 Pulled By: cortinico fbshipit-source-id: caf497b77610c701849ceab5068e54589684d2ab
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 migrates the LogBoxData tests so that it uses Jest modern timers.
I removed the
legacyFakeTimersproperty fromuseFakeTimers(like I did in the previous PR for Pressability tests #55410), and moved it to abeforeEach. This in combination with restoring real timers inafterEachimproves tests reliability and isolation.Then I modified some tests that started to fail by adding explicit
flushToObservers().The extra flushToObservers() calls are necessary because addLog/addException schedule processing using
setImmediate, and inside that callbackhandleUpdate()schedules observer notifications using anothersetImmediate(so we need to flush twice to simulate the correct behaviour like it was already done in some other tests in the test suite).Changelog:
[GENERAL] [CHANGED] - Migrated LogBoxData tests to Jest modern timers
Test Plan:
handleUpdatecall inaddException, that changes the call to theobserver)