react/scripts/jest/devtools/config.build-devtools-regression.js
Ruslan Lesiutin 88b0809447
fix: partially revert jest setup config removal to fix regression tests (#28247)
Partially reverting what has been removed in
https://github.com/facebook/react/pull/28186.

We need `'scheduler/tracing'` mock for React >= 16.8.
The error:
```
Invariant Violation: It is not supported to run the profiling version of a renderer (for example, `react-dom/profiling`) without also replacing the `scheduler/tracing` module with `scheduler/tracing-profiling`. Your bundler might have a setting for aliasing both modules. Learn more at http://fb.me/react-profiling
```

Validated by running regression tests for the whole version matrix:
```
./scripts/circleci/download_devtools_regression_build.js 16.0 --replaceBuild && node ./scripts/jest/jest-cli.js --build --project devtools --release-channel=experimental --reactVersion 16.0 --ci && ./scripts/circleci/download_devtools_regression_build.js 16.5 --replaceBuild && node ./scripts/jest/jest-cli.js --build --project devtools --release-channel=experimental --reactVersion 16.5 --ci && ./scripts/circleci/download_devtools_regression_build.js 16.8 --replaceBuild && node ./scripts/jest/jest-cli.js --build --project devtools --release-channel=experimental --reactVersion 16.8 --ci && ./scripts/circleci/download_devtools_regression_build.js 17.0 --replaceBuild && node ./scripts/jest/jest-cli.js --build --project devtools --release-channel=experimental --reactVersion 17.0 --ci && ./scripts/circleci/download_devtools_regression_build.js 18.0 --replaceBuild && node ./scripts/jest/jest-cli.js --build --project devtools --release-channel=experimental --reactVersion 18.0 --ci
```
2024-02-05 17:07:41 +00: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,
};