Use modern timers in monorepo Jest tests#38955
Closed
robhogan wants to merge 1 commit into
Closed
Conversation
Contributor
|
This pull request was exported from Phabricator. Differential Revision: D48189907 |
Contributor
|
This pull request was exported from Phabricator. Differential Revision: D48189907 |
17853ae to
efcb9fa
Compare
Summary: Pull Request resolved: facebook#38955 Jest introduced "modern" timers based on `sinon/fake-timers` in Jest 26 ([release announcement](https://jestjs.io/blog/2020/05/05/jest-26#new-fake-timers)), and they became the default in Jest 27, in May 2021. Modern timers have more capabilities - they were introduced with support for `queueMicrotask`, mocking `Date`, etc., and they've continued to receive more attention from the Jest team since - they're now much more comprehensive and more configurable than legacy timers. Importantly, because they're not based on Jest mocks, they're not affected in surprising ways by eg `jest.resetAllMocks()` (a particularly confusing side-effect when fake timers are enabled globally, as in our setup). This migrates RN's own tests and config to modern fake timers, or real timers where that's more appropriate. NOTE: In cases where non-trivial changes to the tests are required, four test files are individually opted-in to `legacyFakeTimers` with a `TODO(legacy-fake-timers)`. I'll open these up for community contributions to fix. Changelog: [Internal] Reviewed By: motiz88 Differential Revision: D48189907 fbshipit-source-id: f5eea9a1880cbf98070e09b7639045d412bc11c3
Contributor
|
This pull request was exported from Phabricator. Differential Revision: D48189907 |
efcb9fa to
b19e7c9
Compare
Contributor
|
This pull request has been merged in 86968c1. |
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:
Jest introduced "modern" timers based on
sinon/fake-timersin Jest 26 (release announcement), and they became the default in Jest 27, in May 2021.Modern timers have more capabilities - they were introduced with support for
queueMicrotask, mockingDate, etc., and they've continued to receive more attention from the Jest team since - they're now much more comprehensive and more configurable than legacy timers.Importantly, because they're not based on Jest mocks, they're not affected in surprising ways by eg
jest.resetAllMocks()(a particularly confusing side-effect when fake timers are enabled globally, as in our setup).This migrates RN's own tests and config to modern fake timers, or real timers where that's more appropriate.
NOTE: In cases where non-trivial changes to the tests are required, four test files are individually opted-in to
legacyFakeTimerswith aTODO(legacy-fake-timers). I'll open these up for community contributions to fix.Changelog: [Internal]
Differential Revision: D48189907