-
Notifications
You must be signed in to change notification settings - Fork 46.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add test run that uses www feature flags #18234
Conversation
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.
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 89ba911:
|
Details of bundled changes.Comparing: 4027f2a...89ba911 react-dom
react-art
Size changes (experimental) |
Details of bundled changes.Comparing: 4027f2a...89ba911 react-art
react-dom
Size changes (stable) |
a9a522f
to
e7a3213
Compare
wwwFlags.warnAboutUnmockedScheduler = defaultFlags.warnAboutUnmockedScheduler; | ||
wwwFlags.enableUserTimingAPI = defaultFlags.enableUserTimingAPI; | ||
wwwFlags.disableJavaScriptURLs = defaultFlags.disableJavaScriptURLs; | ||
wwwFlags.enableDeprecatedFlareAPI = defaultFlags.enableDeprecatedFlareAPI; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@trueadm When I ran the tests with Flare enabled, this test started failing sporadically:
Summary of all failing tests
FAIL packages/react-dom/src/__tests__/ReactDOMFiber-test.js
● ReactDOMFiber › should not update event handlers until commit
Expected warning was not recorded:
"Warning: unstable_flushDiscreteUpdates: Cannot flush updates when React is already rendering."
1051 | expect(() => {
1052 | node.click();
> 1053 | }).toErrorDev(
| ^
1054 | 'Warning: unstable_flushDiscreteUpdates: Cannot flush updates when React is already rendering.',
1055 | );
1056 | }
Not sure if this is an issue or not, but letting you know just in case. Since Flare is enabled in the www build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is known, and it seemed like maybe a fragile test from memory as it’s related to the discrete flushing logic based on the timeStamp logic.
deferPassiveEffectCleanupDuringUnmount, | ||
disableInputAttributeSyncing, | ||
enableTrustedTypesIntegration, | ||
runAllPassiveEffectDestroysBeforeCreates, | ||
warnAboutShorthandPropertyCollision, | ||
disableSchedulerTimeoutBasedOnReactExpirationTime, | ||
warnAboutSpreadingKeyToJSX, | ||
replayFailedUnitOfWorkWithInvokeGuardedCallback, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noticed this was off in the www build. I think maybe we wanted to ramp this up in case it breaks something? Seems unlikely, but to decouple it from the rest of the changes I've made it a dynamic flag.
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 commandyarn test-www-variant
.__VARIANT__
is set to false by default; when runningtest-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 totrue
, and once with it set tofalse
. 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 importshared/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.