Skip to content

Commit

Permalink
Prepare for Jest 27+ by making legacy fake timer use explicit
Browse files Browse the repository at this point in the history
Summary:
Jest 27 [flips defaults](https://jestjs.io/blog/2021/05/25/jest-27#flipping-defaults), making "modern" fake timers (ie, `sinonjs/fake-timers`) the default, over "legacy", which we currently use.

We're not quite ready for modern timers yet, partly due to Promise polyfills (facebook#34659), and also some internal issues with specific tests.

This makes our use of legacy timers explicit in preparation for an update to Jest. A switch to modern timers may follow later.

Changelog:
[Internal][Changed] - Prepare for Jest 27+ by making legacy fake timer use explicit

Reviewed By: jacdebug

Differential Revision: D39383719

fbshipit-source-id: 6a3dc6f8547cc76f7702a5a39c9b30a184303f17
  • Loading branch information
robhogan authored and OlimpiaZurek committed May 22, 2023
1 parent 22b8bf5 commit 9e5788d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Libraries/Interaction/__tests__/InteractionManager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ describe('promise tasks', () => {
}
beforeEach(() => {
jest.resetModules();
jest.useFakeTimers();
jest.useFakeTimers('legacy');
InteractionManager = require('../InteractionManager');
BatchedBridge = require('../../BatchedBridge/BatchedBridge');
sequenceId = 0;
Expand Down
2 changes: 1 addition & 1 deletion flow/jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ type JestObjectType = {
* (setTimeout, setInterval, clearTimeout, clearInterval, nextTick,
* setImmediate and clearImmediate).
*/
useFakeTimers(): JestObjectType,
useFakeTimers(type?: 'legacy' | 'modern'): JestObjectType,
/**
* Instructs Jest to use the real versions of the standard timer functions.
*/
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = {
'.*': './jest/private/preprocessor.js',
},
setupFiles: ['./jest/setup.js'],
timers: 'fake',
timers: 'legacy',
testRegex: '/__tests__/.*-test\\.js$',
testPathIgnorePatterns: [
'/node_modules/',
Expand Down

0 comments on commit 9e5788d

Please sign in to comment.