Skip to content

Use modern timers in monorepo Jest tests#38955

Closed
robhogan wants to merge 1 commit into
facebook:mainfrom
robhogan:export-D48189907
Closed

Use modern timers in monorepo Jest tests#38955
robhogan wants to merge 1 commit into
facebook:mainfrom
robhogan:export-D48189907

Conversation

@robhogan
Copy link
Copy Markdown
Contributor

Summary:
Jest introduced "modern" timers based on sinon/fake-timers in 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, 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]

Differential Revision: D48189907

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Facebook Partner: Facebook Partner labels Aug 11, 2023
@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D48189907

@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D48189907

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
@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D48189907

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Aug 11, 2023
@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request has been merged in 86968c1.

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. fb-exported Merged This PR has been merged. p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants