Files
react/scripts/jest/devtools/setupEnv.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

44 lines
1.2 KiB
JavaScript
Raw Normal View History

'use strict';
2019-04-11 09:07:40 -07:00
const semver = require('semver');
fix[ci]: fixed jest configuration not to skip too many devtools tests (#26955) ## Summary Running `yarn test --project devtools --build` currently skips all non-gated (without `@reactVersion` directives) devtools tests. This is not expected behaviour, these changes are fixing it. There were multiple related PRs to it: - https://github.com/facebook/react/pull/26742 - https://github.com/facebook/react/pull/25712 - https://github.com/facebook/react/pull/24555 With these changes, the resulting behaviour will be: - If `REACT_VERSION` env variable is specified: - jest will not include all non-gated test cases in the test run - jest will run only a specific test case, when specified `REACT_VERSION` value satisfies the range defined by `@reactVersion` directives for this test case - If `REACT_VERSION` env variable is not specified, jest will run all non-gated tests: - jest will include all non-gated test cases in the test run - jest will run all non-gated test cases, the only skipped test cases will be those, which specified the range that does not include the next stable version of react, which will be imported from `ReactVersions.js` ## How did you test this change? Running `profilingCache` test suite without specifying `reactVersion` now skips gated (>= 17 & < 18) test <img width="1447" alt="Screenshot 2023-06-15 at 11 18 22" src="https://github.com/facebook/react/assets/28902667/cad58994-2cb3-44b3-9eb2-1699c01a1eb3"> Running `profilingCache` test suite with specifying `reactVersion` to `17` now runs this test case and skips others correctly <img width="1447" alt="Screenshot 2023-06-15 at 11 20 11" src="https://github.com/facebook/react/assets/28902667/d308960a-c172-4422-ba6f-9c0dbcd6f7d5"> Running `yarn test --project devtools ...` without specifying `reactVersion` now runs all non-gated test cases <img width="398" alt="Screenshot 2023-06-15 at 12 25 12" src="https://github.com/facebook/react/assets/28902667/2b329634-0efd-4c4c-b460-889696bbc9e1"> Running `yarn test --project devtools ...` with specifying `reactVersion` (to `17` in this example) now includes only gated tests <img width="414" alt="Screenshot 2023-06-15 at 12 26 31" src="https://github.com/facebook/react/assets/28902667/a702c27e-4c35-4b12-834c-e5bb06728997">
2023-06-22 09:33:05 +01:00
const {ReactVersion} = require('../../../ReactVersions');
2019-04-11 11:21:59 -07:00
// DevTools stores preferences between sessions in localStorage
if (!global.hasOwnProperty('localStorage')) {
global.localStorage = require('local-storage-fallback').default;
2019-04-11 11:21:59 -07:00
}
// Mimic the global we set with Webpack's DefinePlugin
global.__DEV__ = process.env.NODE_ENV !== 'production';
global.__TEST__ = true;
chore[react-devtools]: unify console patching and default to ansi escape symbols (#29869) Stacked on https://github.com/facebook/react/pull/29856. ## Summary By default, React DevTools will apply dimming with ANSI escape symbols, so it works for both terminals and browser consoles. For Firefox, which doesn't support ANSI escape symbols console stylings, we fallback to css properties, like we used to do before. ## How did you test this change? | Environment | Dark mode | Light mode | |--------|--------|--------| | Terminal | ![Screenshot 2024-06-12 at 19 39 46](https://github.com/facebook/react/assets/28902667/2d470eee-ec5f-4362-be7d-8d80c6c72d09) | ![Screenshot 2024-06-12 at 19 39 09](https://github.com/facebook/react/assets/28902667/616f2c58-a251-406b-aee6-841e07d652ba) | | Fusebox&nbsp;console | ![Screenshot 2024-06-12 at 21 03 14](https://github.com/facebook/react/assets/28902667/6050f730-8e82-4aa1-acbc-7179aac3a8aa) | ![Screenshot 2024-06-12 at 21 02 48](https://github.com/facebook/react/assets/28902667/6708b938-8a90-476f-a057-427963d58caa) | | Firefox&nbsp;console | ![Screenshot 2024-06-12 at 21 40 29](https://github.com/facebook/react/assets/28902667/4721084f-bbfa-438c-b61b-395da8ded590) | ![Screenshot 2024-06-12 at 21 40 42](https://github.com/facebook/react/assets/28902667/72bbf001-2d3d-49e7-91c9-20a4f0914d4d) | | Chrome&nbsp;console | ![Screenshot 2024-06-12 at 21 43 09](https://github.com/facebook/react/assets/28902667/93c47881-a0dd-44f8-8dc2-8710149774e5) | ![Screenshot 2024-06-12 at 21 43 00](https://github.com/facebook/react/assets/28902667/07ea4ff5-4322-4db9-9c12-4321d9577c9d) |
2024-06-17 16:31:36 +01:00
global.__IS_FIREFOX__ = false;
global.__IS_CHROME__ = false;
global.__IS_EDGE__ = false;
global.__IS_NATIVE__ = false;
const ReactVersionTestingAgainst = process.env.REACT_VERSION || ReactVersion;
global._test_react_version = (range, testName, callback) => {
const shouldPass = semver.satisfies(ReactVersionTestingAgainst, range);
if (shouldPass) {
test(testName, callback);
} else {
test.skip(testName, callback);
}
};
global._test_react_version_focus = (range, testName, callback) => {
const shouldPass = semver.satisfies(ReactVersionTestingAgainst, range);
if (shouldPass) {
test.only(testName, callback);
} else {
test.skip(testName, callback);
}
};
global._test_ignore_for_react_version = (testName, callback) => {
test.skip(testName, callback);
};