-
Notifications
You must be signed in to change notification settings - Fork 46.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test run that uses www feature flags
In CI, we run our test suite against multiple build configurations. For example, we run our tests in both dev and prod, and in both the experimental and stable release channels. This is to prevent accidental deviations in behavior between the different builds. If there's an intentional deviation in behavior, the test author must account for them. However, we currently don't run tests against the www builds. That's a problem, because it's common for features to land in www before they land anywhere else, including the experimental release channel. Typically we do this so we can gradually roll out the feature behind a flag before deciding to enable it. The way we test those features today is by mutating the `shared/ReactFeatureFlags` module. There are a few downsides to this approach, though. The flag is only overridden for the specific tests or test suites where you apply the override. But usually what you want is to run *all* tests with the flag enabled, to protect against unexpected regressions. Also, mutating the feature flags module only works when running the tests against source, not against the final build artifacts, because the ReactFeatureFlags module is inlined by the build script. Instead, we should run the test suite against the www configuration, just like we do for prod, experimental, and so on. I've added a new command, `yarn test-www`. It automatically runs in CI. Some of the www feature flags are dynamic; that is, they depend on a runtime condition (i.e. a GK). These flags are imported from an external module that lives in www. Those flags will be enabled for some clients and disabled for others, so we should run the tests against *both* modes. So I've added a new global `__VARIANT__`, and a new test command `yarn test-www-variant`. `__VARIANT__` is set to false by default; when running `test-www-variant`, it's set to true. If we were going for *really* comprehensive coverage, we would run the tests against every possible configuration of feature flags: 2 ^ numberOfFlags total combinations. That's not practical, though, so instead we only run against two combinations: once with `__VARIANT__` set to `true`, and once with it set to `false`. We generally assume that flags can be toggled independently, so in practice this should be enough. You can also refer to `__VARIANT__` in tests to detect which mode you're running in. Or, you can import `shared/ReactFeatureFlags` and read the specific flag you can about. However, we should stop mutating that module going forward. Treat it as read-only. In this commit, I have only setup the www tests to run against source. I'll leave running against build for a follow up. Many of our tests currently assume they run only in the default configuration, and break when certain flags are toggled. Rather than fix these all up front, I've hard-coded the relevant flags to the default values. We can incrementally migrate those tests later.
- Loading branch information
Showing
12 changed files
with
233 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow strict | ||
*/ | ||
|
||
// In www, these flags are controlled by GKs. Because most GKs have some | ||
// population running in either mode, we should run our tests that way, too, | ||
// | ||
// Use __VARIANT__ to simulate a GK. The tests will be run twice: once | ||
// with the __VARIANT__ set to `true`, and once set to `false`. | ||
|
||
export const deferPassiveEffectCleanupDuringUnmount = __VARIANT__; | ||
export const runAllPassiveEffectDestroysBeforeCreates = __VARIANT__; | ||
export const warnAboutSpreadingKeyToJSX = __VARIANT__; | ||
|
||
// These are already tested in both modes using the build type dimension, | ||
// so we don't need to use __VARIANT__ to get extra coverage. | ||
export const debugRenderPhaseSideEffectsForStrictMode = __DEV__; | ||
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__; | ||
|
||
// TODO: These flags are hard-coded to the default values used in open source. | ||
// Update the tests so that they pass in either mode, then set these | ||
// to __VARIANT__. | ||
export const enableTrustedTypesIntegration = false; | ||
export const warnAboutShorthandPropertyCollision = true; | ||
export const disableInputAttributeSyncing = false; | ||
export const disableSchedulerTimeoutBasedOnReactExpirationTime = false; | ||
export const enableModernEventSystem = false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict'; | ||
|
||
const baseConfig = require('./config.base'); | ||
|
||
const RELEASE_CHANNEL = process.env.RELEASE_CHANNEL; | ||
|
||
// Default to building in experimental mode. If the release channel is set via | ||
// an environment variable, then check if it's "experimental". | ||
const __EXPERIMENTAL__ = | ||
typeof RELEASE_CHANNEL === 'string' | ||
? RELEASE_CHANNEL === 'experimental' | ||
: true; | ||
|
||
const preferredExtension = __EXPERIMENTAL__ ? '.js' : '.stable.js'; | ||
|
||
const moduleNameMapper = {}; | ||
moduleNameMapper[ | ||
'^react$' | ||
] = `<rootDir>/packages/react/index${preferredExtension}`; | ||
moduleNameMapper[ | ||
'^react-dom$' | ||
] = `<rootDir>/packages/react-dom/index${preferredExtension}`; | ||
|
||
module.exports = Object.assign({}, baseConfig, { | ||
// Prefer the stable forks for tests. | ||
moduleNameMapper, | ||
modulePathIgnorePatterns: [ | ||
...baseConfig.modulePathIgnorePatterns, | ||
'packages/react-devtools-shared', | ||
], | ||
setupFiles: [ | ||
...baseConfig.setupFiles, | ||
require.resolve('./setupHostConfigs.js'), | ||
require.resolve('./setupTests.www.js'), | ||
], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
|
||
jest.mock('shared/ReactFeatureFlags', () => { | ||
jest.mock( | ||
'ReactFeatureFlags', | ||
() => jest.requireActual('shared/forks/ReactFeatureFlags.www-dynamic'), | ||
{virtual: true} | ||
); | ||
|
||
const wwwFlags = jest.requireActual('shared/forks/ReactFeatureFlags.www'); | ||
const defaultFlags = jest.requireActual('shared/ReactFeatureFlags'); | ||
|
||
// TODO: Many tests were written before we started running them against the | ||
// www configuration. Update those tests so that they work against the www | ||
// configuration, too. Then remove these overrides. | ||
wwwFlags.disableLegacyContext = defaultFlags.disableLegacyContext; | ||
wwwFlags.warnAboutUnmockedScheduler = defaultFlags.warnAboutUnmockedScheduler; | ||
wwwFlags.enableUserTimingAPI = defaultFlags.enableUserTimingAPI; | ||
wwwFlags.disableJavaScriptURLs = defaultFlags.disableJavaScriptURLs; | ||
wwwFlags.enableDeprecatedFlareAPI = defaultFlags.enableDeprecatedFlareAPI; | ||
|
||
return wwwFlags; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters