Skip to content
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

Merged
merged 1 commit into from
Mar 6, 2020
Merged

Conversation

acdlite
Copy link
Collaborator

@acdlite acdlite commented Mar 6, 2020

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.

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.
@acdlite acdlite requested a review from sebmarkbage March 6, 2020 06:09
@facebook-github-bot facebook-github-bot added React Core Team Opened by a member of the React Core Team CLA Signed labels Mar 6, 2020
@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 6, 2020

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:

Sandbox Source
confident-shannon-6b5zg Configuration

@sizebot
Copy link

sizebot commented Mar 6, 2020

Details of bundled changes.

Comparing: 4027f2a...89ba911

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactDOM-dev.js +0.5% +0.6% 907.29 KB 911.46 KB 202.52 KB 203.64 KB FB_WWW_DEV
ReactDOMServer-dev.js +0.2% +0.1% 137.4 KB 137.64 KB 35.11 KB 35.16 KB FB_WWW_DEV
ReactDOMTesting-dev.js 0.0% 0.0% 873.31 KB 873.31 KB 195.61 KB 195.61 KB FB_WWW_DEV
react-dom-server.node.development.js 0.0% -0.0% 131.08 KB 131.08 KB 34.83 KB 34.83 KB NODE_DEV
react-dom-test-utils.production.min.js 0.0% -0.0% 10.81 KB 10.81 KB 4.1 KB 4.1 KB NODE_PROD
react-dom.development.js 0.0% 0.0% 914.35 KB 914.35 KB 200.16 KB 200.16 KB UMD_DEV
react-dom-server.browser.development.js 0.0% -0.0% 136.87 KB 136.87 KB 34.99 KB 34.99 KB UMD_DEV
ReactTestUtils-dev.js +0.5% +0.4% 51.37 KB 51.61 KB 13.72 KB 13.77 KB FB_WWW_DEV
react-dom.development.js 0.0% 0.0% 870.34 KB 870.34 KB 197.7 KB 197.7 KB NODE_DEV
react-dom-server.browser.development.js 0.0% -0.0% 129.87 KB 129.87 KB 34.58 KB 34.58 KB NODE_DEV
react-dom.production.min.js 0.0% -0.0% 120.04 KB 120.04 KB 37.53 KB 37.52 KB NODE_PROD
ReactDOM-prod.js 0.0% 0.0% 376.26 KB 376.34 KB 68.37 KB 68.38 KB FB_WWW_PROD
ReactDOM-profiling.js 0.0% 0.0% 387.95 KB 388.04 KB 70.54 KB 70.55 KB FB_WWW_PROFILING
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 55.87 KB 55.87 KB 14.47 KB 14.47 KB NODE_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% 0.0% 10 KB 10 KB 3.37 KB 3.38 KB NODE_PROD
react-dom-unstable-fizz.node.production.min.js 0.0% -0.2% 1.16 KB 1.16 KB 663 B 662 B NODE_PROD

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-art.development.js 0.0% 0.0% 635.52 KB 635.52 KB 133.57 KB 133.57 KB UMD_DEV
react-art.production.min.js 0.0% 0.0% 106.64 KB 106.64 KB 32.25 KB 32.25 KB UMD_PROD
react-art.development.js 0.0% 0.0% 539.67 KB 539.67 KB 115.97 KB 115.97 KB NODE_DEV
ReactART-dev.js +0.8% +1.0% 543.41 KB 547.59 KB 114.11 KB 115.26 KB FB_WWW_DEV
ReactART-prod.js 0.0% 0.0% 226.66 KB 226.7 KB 38.52 KB 38.53 KB FB_WWW_PROD

Size changes (experimental)

Generated by 🚫 dangerJS against 89ba911

@sizebot
Copy link

sizebot commented Mar 6, 2020

Details of bundled changes.

Comparing: 4027f2a...89ba911

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactART-dev.js +0.8% +0.9% 569.13 KB 573.42 KB 119.38 KB 120.51 KB FB_WWW_DEV
ReactART-prod.js 0.0% 0.0% 233.84 KB 233.88 KB 39.73 KB 39.74 KB FB_WWW_PROD
react-art.development.js 0.0% 0.0% 616.35 KB 616.35 KB 130.17 KB 130.17 KB UMD_DEV
react-art.development.js 0.0% 0.0% 521.24 KB 521.25 KB 112.53 KB 112.53 KB NODE_DEV

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactDOM-profiling.js 0.0% 0.0% 412.95 KB 413.03 KB 75.11 KB 75.12 KB FB_WWW_PROFILING
react-dom-server.browser.development.js 0.0% 0.0% 135.28 KB 135.28 KB 34.78 KB 34.79 KB UMD_DEV
react-dom-unstable-fizz.node.production.min.js 0.0% -0.2% 1.15 KB 1.15 KB 654 B 653 B NODE_PROD
ReactTestUtils-dev.js +0.5% +0.4% 51.38 KB 51.62 KB 13.71 KB 13.76 KB FB_WWW_DEV
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 55.86 KB 55.86 KB 14.46 KB 14.46 KB NODE_DEV
react-dom.development.js 0.0% 0.0% 885.67 KB 885.67 KB 195.23 KB 195.23 KB UMD_DEV
react-dom.development.js 0.0% 0.0% 842.84 KB 842.85 KB 192.79 KB 192.79 KB NODE_DEV
react-dom-server.node.development.js 0.0% -0.0% 129.57 KB 129.57 KB 34.61 KB 34.61 KB NODE_DEV
react-dom.production.min.js 0.0% -0.0% 116.09 KB 116.09 KB 36.5 KB 36.5 KB NODE_PROD
ReactDOM-dev.js +0.5% +0.5% 950.85 KB 955.14 KB 212.11 KB 213.25 KB FB_WWW_DEV
ReactDOM-prod.js 0.0% 0.0% 401.18 KB 401.26 KB 72.85 KB 72.86 KB FB_WWW_PROD
ReactDOMTesting-dev.js 0.0% 0.0% 899.95 KB 899.95 KB 201.19 KB 201.19 KB FB_WWW_DEV
react-dom-server.browser.development.js 0.0% -0.0% 128.35 KB 128.35 KB 34.36 KB 34.36 KB NODE_DEV
react-dom-test-utils.development.js 0.0% 0.0% 53.77 KB 53.77 KB 14 KB 14 KB UMD_DEV
ReactDOMServer-dev.js +0.2% +0.1% 138.25 KB 138.5 KB 35.25 KB 35.3 KB FB_WWW_DEV
react-dom-unstable-fizz.browser.development.js 0.0% -0.1% 2.94 KB 2.94 KB 1.17 KB 1.17 KB NODE_DEV
react-dom-test-utils.production.min.js 0.0% -0.0% 10.79 KB 10.79 KB 4.09 KB 4.09 KB NODE_PROD
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 58.9 KB 58.9 KB 14.7 KB 14.7 KB UMD_DEV

Size changes (stable)

Generated by 🚫 dangerJS against 89ba911

@acdlite acdlite force-pushed the www-tests branch 2 times, most recently from a9a522f to e7a3213 Compare March 6, 2020 06:55
wwwFlags.warnAboutUnmockedScheduler = defaultFlags.warnAboutUnmockedScheduler;
wwwFlags.enableUserTimingAPI = defaultFlags.enableUserTimingAPI;
wwwFlags.disableJavaScriptURLs = defaultFlags.disableJavaScriptURLs;
wwwFlags.enableDeprecatedFlareAPI = defaultFlags.enableDeprecatedFlareAPI;
Copy link
Collaborator Author

@acdlite acdlite Mar 6, 2020

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 |       }

Details: https://circleci.com/gh/facebook/react/97022?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link

Not sure if this is an issue or not, but letting you know just in case. Since Flare is enabled in the www build.

Copy link
Contributor

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,
Copy link
Collaborator Author

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.

@acdlite acdlite merged commit 115cd12 into facebook:master Mar 6, 2020
@acdlite acdlite mentioned this pull request Mar 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants