From 09a910f80beff678c38f0f1a65e6f08e240f6644 Mon Sep 17 00:00:00 2001 From: Rob Hogan Date: Mon, 12 Sep 2022 04:59:18 -0700 Subject: [PATCH] Prepare for Jest 27+ by making legacy fake timer use explicit 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 (https://github.com/facebook/react-native/pull/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 --- Libraries/Interaction/__tests__/InteractionManager-test.js | 2 +- flow/jest.js | 2 +- jest.config.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Libraries/Interaction/__tests__/InteractionManager-test.js b/Libraries/Interaction/__tests__/InteractionManager-test.js index 3b551e84b3f..00428e8eabe 100644 --- a/Libraries/Interaction/__tests__/InteractionManager-test.js +++ b/Libraries/Interaction/__tests__/InteractionManager-test.js @@ -168,7 +168,7 @@ describe('promise tasks', () => { } beforeEach(() => { jest.resetModules(); - jest.useFakeTimers(); + jest.useFakeTimers('legacy'); InteractionManager = require('../InteractionManager'); BatchedBridge = require('../../BatchedBridge/BatchedBridge'); sequenceId = 0; diff --git a/flow/jest.js b/flow/jest.js index 8f562116961..c64fc43c224 100644 --- a/flow/jest.js +++ b/flow/jest.js @@ -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. */ diff --git a/jest.config.js b/jest.config.js index 512bd1b538e..4c5aee76f41 100644 --- a/jest.config.js +++ b/jest.config.js @@ -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/',