Skip to content

LogBoxData test migrated to Jest modern timers#55757

Closed
chicio wants to merge 1 commit intofacebook:mainfrom
chicio:logboxdata_jest_timers
Closed

LogBoxData test migrated to Jest modern timers#55757
chicio wants to merge 1 commit intofacebook:mainfrom
chicio:logboxdata_jest_timers

Conversation

@chicio
Copy link
Copy Markdown
Contributor

@chicio chicio commented Feb 25, 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 #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

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)

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 25, 2026
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Feb 25, 2026
@chicio
Copy link
Copy Markdown
Contributor Author

chicio commented Feb 27, 2026

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 😅

@cortinico
Copy link
Copy Markdown
Contributor

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 😅

Let me take a look at this on monday 👍

@cortinico
Copy link
Copy Markdown
Contributor

/rebase

@github-actions github-actions bot force-pushed the logboxdata_jest_timers branch from 3a710ab to 2bb868c Compare March 2, 2026 13:33
@meta-codesync
Copy link
Copy Markdown

meta-codesync bot commented Mar 2, 2026

@cortinico has imported this pull request. If you are a Meta employee, you can view this in D94903193.

@react-native-bot
Copy link
Copy Markdown
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?

@react-native-bot react-native-bot added the Merged This PR has been merged. label Mar 3, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants