mirror of
https://github.com/facebook/react.git
synced 2026-02-25 21:55:00 +00:00
In DevTools tests, if the REACT_VERSION specified, we know this is a regression test (testing older React Versions). Because a lot of tests test the DevTools front end and we don't want to run them in the regression test scenario, we decided to only run tests that have the // @reactVersion pragma defined. Because if there are no tests specified, jest will fail, we also opt to use jest.skip to skip all the tests that we don't want to run for a specific React version istead. This PR makes this change.
59 lines
2.0 KiB
JavaScript
59 lines
2.0 KiB
JavaScript
'use strict';
|
|
|
|
const semver = require('semver');
|
|
const ReactVersion = require('../../../packages/shared/ReactVersion');
|
|
|
|
const {
|
|
DARK_MODE_DIMMED_WARNING_COLOR,
|
|
DARK_MODE_DIMMED_ERROR_COLOR,
|
|
DARK_MODE_DIMMED_LOG_COLOR,
|
|
LIGHT_MODE_DIMMED_WARNING_COLOR,
|
|
LIGHT_MODE_DIMMED_ERROR_COLOR,
|
|
LIGHT_MODE_DIMMED_LOG_COLOR,
|
|
} = require('react-devtools-extensions/utils');
|
|
|
|
// DevTools stores preferences between sessions in localStorage
|
|
if (!global.hasOwnProperty('localStorage')) {
|
|
global.localStorage = require('local-storage-fallback').default;
|
|
}
|
|
|
|
// Mimic the global we set with Webpack's DefinePlugin
|
|
global.__DEV__ = process.env.NODE_ENV !== 'production';
|
|
global.__TEST__ = true;
|
|
|
|
global.process.env.DARK_MODE_DIMMED_WARNING_COLOR = DARK_MODE_DIMMED_WARNING_COLOR;
|
|
global.process.env.DARK_MODE_DIMMED_ERROR_COLOR = DARK_MODE_DIMMED_ERROR_COLOR;
|
|
global.process.env.DARK_MODE_DIMMED_LOG_COLOR = DARK_MODE_DIMMED_LOG_COLOR;
|
|
global.process.env.LIGHT_MODE_DIMMED_WARNING_COLOR = LIGHT_MODE_DIMMED_WARNING_COLOR;
|
|
global.process.env.LIGHT_MODE_DIMMED_ERROR_COLOR = LIGHT_MODE_DIMMED_ERROR_COLOR;
|
|
global.process.env.LIGHT_MODE_DIMMED_LOG_COLOR = LIGHT_MODE_DIMMED_LOG_COLOR;
|
|
|
|
global._test_react_version = (range, testName, callback) => {
|
|
const trimmedRange = range.replaceAll(' ', '');
|
|
const reactVersion = process.env.REACT_VERSION || ReactVersion.default;
|
|
const shouldPass = semver.satisfies(reactVersion, trimmedRange);
|
|
|
|
if (shouldPass) {
|
|
test(testName, callback);
|
|
} else {
|
|
test.skip(testName, callback);
|
|
}
|
|
};
|
|
|
|
global._test_react_version_focus = (range, testName, callback) => {
|
|
const trimmedRange = range.replaceAll(' ', '');
|
|
const reactVersion = process.env.REACT_VERSION || ReactVersion.default;
|
|
const shouldPass = semver.satisfies(reactVersion, trimmedRange);
|
|
|
|
if (shouldPass) {
|
|
// eslint-disable-next-line jest/no-focused-tests
|
|
test.only(testName, callback);
|
|
} else {
|
|
test.skip(testName, callback);
|
|
}
|
|
};
|
|
|
|
global._test_ignore_for_react_version = (testName, callback) => {
|
|
test.skip(testName, callback);
|
|
};
|