2019-02-26 05:46:16 +00:00
|
|
|
/**
|
2021-12-30 23:08:43 +00:00
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
2019-02-26 05:46:16 +00:00
|
|
|
*
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2020-07-22 09:59:15 +00:00
|
|
|
*
|
|
|
|
* @format
|
2019-02-26 05:46:16 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2023-04-12 12:17:01 +00:00
|
|
|
const {defaults} = require('jest-config');
|
|
|
|
|
2019-02-26 05:46:16 +00:00
|
|
|
module.exports = {
|
2020-07-22 09:59:15 +00:00
|
|
|
transform: {
|
|
|
|
'^.+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$':
|
2023-03-17 12:03:25 +00:00
|
|
|
'<rootDir>/packages/react-native/jest/assetFileTransformer.js',
|
2023-03-20 12:44:34 +00:00
|
|
|
'.*': './jest/preprocessor.js',
|
2020-07-22 09:59:15 +00:00
|
|
|
},
|
2023-03-17 12:03:25 +00:00
|
|
|
setupFiles: ['./packages/react-native/jest/local-setup.js'],
|
2022-09-20 21:15:50 +00:00
|
|
|
fakeTimers: {
|
|
|
|
enableGlobally: true,
|
Use modern timers in monorepo Jest tests (#38955)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/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: 2e7ce74cc60e80679d81d7c16d599ad1bbe2c921
2023-08-11 18:01:06 +00:00
|
|
|
legacyFakeTimers: false,
|
2022-09-20 21:15:50 +00:00
|
|
|
},
|
|
|
|
snapshotFormat: {
|
|
|
|
escapeString: true,
|
|
|
|
printBasicPrototype: true,
|
|
|
|
},
|
2023-04-12 12:17:01 +00:00
|
|
|
// This allows running Meta-internal tests with the `-test.fb.js` suffix.
|
|
|
|
testRegex: '/__tests__/.*-test(\\.fb)?\\.js$',
|
2020-07-22 09:59:15 +00:00
|
|
|
testPathIgnorePatterns: [
|
|
|
|
'/node_modules/',
|
2023-03-17 12:03:25 +00:00
|
|
|
'<rootDir>/packages/react-native/template',
|
2023-10-09 22:30:00 +00:00
|
|
|
'<rootDir>/packages/react-native/sdks',
|
2023-03-28 11:31:49 +00:00
|
|
|
'<rootDir>/packages/react-native/Libraries/Renderer',
|
2023-03-17 12:03:25 +00:00
|
|
|
'<rootDir>/packages/rn-tester/e2e',
|
2020-07-22 09:59:15 +00:00
|
|
|
],
|
|
|
|
transformIgnorePatterns: ['node_modules/(?!@react-native/)'],
|
|
|
|
haste: {
|
|
|
|
defaultPlatform: 'ios',
|
|
|
|
platforms: ['ios', 'android'],
|
|
|
|
},
|
2023-04-12 12:17:01 +00:00
|
|
|
moduleNameMapper: {
|
|
|
|
// This module is internal to Meta and used by their custom React renderer.
|
|
|
|
// In tests, we can just use a mock.
|
|
|
|
'^ReactNativeInternalFeatureFlags$':
|
|
|
|
'<rootDir>/packages/react-native/jest/ReactNativeInternalFeatureFlagsMock.js',
|
|
|
|
},
|
|
|
|
moduleFileExtensions: ['fb.js'].concat(defaults.moduleFileExtensions),
|
2020-07-22 09:59:15 +00:00
|
|
|
unmockedModulePathPatterns: [
|
|
|
|
'node_modules/react/',
|
2023-03-17 12:03:25 +00:00
|
|
|
'packages/react-native/Libraries/Renderer',
|
2020-07-22 09:59:15 +00:00
|
|
|
'promise',
|
|
|
|
'source-map',
|
|
|
|
'fastpath',
|
|
|
|
'denodeify',
|
|
|
|
],
|
|
|
|
testEnvironment: 'node',
|
2023-03-17 12:03:25 +00:00
|
|
|
collectCoverageFrom: ['packages/react-native/Libraries/**/*.js'],
|
2020-07-22 09:59:15 +00:00
|
|
|
coveragePathIgnorePatterns: [
|
|
|
|
'/__tests__/',
|
|
|
|
'/vendor/',
|
2023-03-17 12:03:25 +00:00
|
|
|
'<rootDir>/packages/react-native/Libraries/react-native/',
|
2020-07-22 09:59:15 +00:00
|
|
|
],
|
2019-02-26 05:46:16 +00:00
|
|
|
};
|