Home / Function/ getTestFlags() — react Function Reference

getTestFlags() — react Function Reference

Architecture documentation for the getTestFlags() function in TestFlags.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  7ccddecb_db51_b49d_fcf0_2af38937aabb["getTestFlags()"]
  41d0113d_a39c_ee8e_f5f4_00b1c31a9274["TestFlags.js"]
  7ccddecb_db51_b49d_fcf0_2af38937aabb -->|defined in| 41d0113d_a39c_ee8e_f5f4_00b1c31a9274
  style 7ccddecb_db51_b49d_fcf0_2af38937aabb fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

scripts/jest/TestFlags.js lines 56–128

function getTestFlags() {
  // These are required on demand because some of our tests mutate them. We try
  // not to but there are exceptions.
  const featureFlags = require('shared/ReactFeatureFlags');
  const schedulerFeatureFlags = require('scheduler/src/SchedulerFeatureFlags');

  const www = global.__WWW__ === true;
  const xplat = global.__XPLAT__ === true;
  const releaseChannel = www
    ? __EXPERIMENTAL__
      ? 'modern'
      : 'classic'
    : __EXPERIMENTAL__
      ? 'experimental'
      : 'stable';

  // Return a proxy so we can throw if you attempt to access a flag that
  // doesn't exist.
  return new Proxy(
    {
      channel: releaseChannel,
      modern: releaseChannel === 'modern',
      classic: releaseChannel === 'classic',
      source: !process.env.IS_BUILD,
      www,
      fb: www || xplat,

      // These aren't flags, just a useful aliases for tests.
      // TODO: Clean this up.
      enableActivity: true,
      enableSuspenseList: releaseChannel === 'experimental' || www || xplat,
      enableLegacyHidden: www,
      // TODO: Suspending the work loop during the render phase is currently
      // not compatible with sibling prerendering. We will add this optimization
      // back in a later step.
      enableSuspendingDuringWorkLoop: false,

      // This flag is used to determine whether we should run Fizz tests using
      // the external runtime or the inline script runtime.
      // For Meta we use variant to gate the feature. For OSS we use experimental
      shouldUseFizzExternalRuntime: !featureFlags.enableFizzExternalRuntime
        ? false
        : www
          ? __VARIANT__
          : __EXPERIMENTAL__,

      // This is used by useSyncExternalStoresShared-test.js to decide whether
      // to test the shim or the native implementation of useSES.

      enableUseSyncExternalStoreShim: !__VARIANT__,

      // If there's a naming conflict between scheduler and React feature flags, the
      // React ones take precedence.
      // TODO: Maybe we should error on conflicts? Or we could namespace
      // the flags
      ...schedulerFeatureFlags,
      ...featureFlags,
      ...environmentFlags,
    },
    {
      get(flags, flagName) {
        const flagValue = flags[flagName];
        if (flagValue === undefined && typeof flagName === 'string') {
          throw Error(
            `Feature flag "${flagName}" does not exist. See TestFlags.js ` +
              'for more details.'
          );
        }
        return flagValue;
      },
    }
  );
}

Domain

Subdomains

Frequently Asked Questions

What does getTestFlags() do?
getTestFlags() is a function in the react codebase, defined in scripts/jest/TestFlags.js.
Where is getTestFlags() defined?
getTestFlags() is defined in scripts/jest/TestFlags.js at line 56.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free