react/scripts/jest/devtools/config.build-devtools-regression.js
Luna Ruan 5a1e558df2
[DevTools] Regression Test Jest Config (#24598)
Some older React versions have different module import names and are missing certain features. This PR mocks modules that don't exist and maps modules in older versions to the ones that are required in tests. Specifically:

* In React v16.5, scheduler is named schedule
* In pre concurrent React, there is no act
* Prior to React v18.0, react-dom/client doesn't exist
* In DevTools, we expect to use scheduler/tracing-profiling instead of scheduler/tracing
2022-05-23 13:50:53 -04:00

42 lines
1.1 KiB
JavaScript

'use strict';
const semver = require('semver');
const NODE_MODULES_DIR =
process.env.RELEASE_CHANNEL === 'stable' ? 'oss-stable' : 'oss-experimental';
const REACT_VERSION = process.env.REACT_VERSION;
const moduleNameMapper = {};
const setupFiles = [];
// We only want to add these if we are in a regression test, IE if there
// is a REACT_VERSION specified
if (REACT_VERSION) {
// React version 16.5 has a schedule package instead of a scheduler
// package, so we need to rename them accordingly
if (semver.satisfies(REACT_VERSION, '16.5')) {
moduleNameMapper[
`^schedule$`
] = `<rootDir>/build/${NODE_MODULES_DIR}/schedule`;
moduleNameMapper[
'^schedule/tracing$'
] = `<rootDir>/build/${NODE_MODULES_DIR}/schedule/tracing-profiling`;
}
// react-dom/client is only in v18.0.0 and up, so we
// map it to react-dom instead
if (semver.satisfies(REACT_VERSION, '<18.0')) {
moduleNameMapper[
'^react-dom/client$'
] = `<rootDir>/build/${NODE_MODULES_DIR}/react-dom`;
}
setupFiles.push(require.resolve('./setupTests.build-devtools-regression'));
}
module.exports = {
moduleNameMapper,
setupFiles,
};