Home / File/ compiler-integration-test.js — react Source File

compiler-integration-test.js — react Source File

Architecture documentation for compiler-integration-test.js, a javascript file in the react codebase. 1 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  df7cfb22_5a3b_8a9a_0fbe_95af9bc186f9["compiler-integration-test.js"]
  7ea1760e_9c01_71c9_3ba5_32a9a10a0ce4["utils.js"]
  df7cfb22_5a3b_8a9a_0fbe_95af9bc186f9 --> 7ea1760e_9c01_71c9_3ba5_32a9a10a0ce4
  style df7cfb22_5a3b_8a9a_0fbe_95af9bc186f9 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/**
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @flow
 */

import {getVersionedRenderImplementation} from './utils';

describe('CompilerIntegration', () => {
  global.IS_REACT_ACT_ENVIRONMENT = true;
  let React;
  let act;
  let useMemoCache;

  beforeEach(() => {
    React = require('react');
    require('react-dom');
    require('react-dom/client');
    useMemoCache = require('react/compiler-runtime').c;

    const utils = require('./utils');
    act = utils.act;
  });

  afterEach(() => {
    jest.restoreAllMocks();
  });

  const {render} = getVersionedRenderImplementation();

  // @reactVersion >= 18.2
  it('By default, component display names should not have Forget prefix', () => {
    const hook = global.__REACT_DEVTOOLS_GLOBAL_HOOK__;
    const reactDOMFiberRendererInterface = hook.rendererInterfaces.get(1);
    expect(reactDOMFiberRendererInterface).not.toBeFalsy();

    const Foo = () => {
      // eslint-disable-next-line no-unused-vars
      const [val, setVal] = React.useState(null);

      return (
        <div>
          <Bar />
        </div>
      );
    };
    const Bar = () => <div>Hi!</div>;

    act(() => render(<Foo />));

    expect(
      reactDOMFiberRendererInterface
        .getDisplayNameForElementID(2)
        .indexOf('Forget'),
    ).toBe(-1);
    expect(
      reactDOMFiberRendererInterface
        .getDisplayNameForElementID(3)
        .indexOf('Forget'),
    ).toBe(-1);
  });

  // For React 18.2, this will install uMC polyfill from react-compiler-runtime available on npm.
  // @reactVersion >= 18.2
  it('If useMemoCache used, the corresponding displayName for a component should have Forget prefix', () => {
    const hook = global.__REACT_DEVTOOLS_GLOBAL_HOOK__;
    const reactDOMFiberRendererInterface = hook.rendererInterfaces.get(1);
    expect(reactDOMFiberRendererInterface).not.toBeFalsy();

    const Foo = () => {
      // eslint-disable-next-line no-unused-vars
      const $ = useMemoCache(1);
      // eslint-disable-next-line no-unused-vars
      const [val, setVal] = React.useState(null);

      return (
        <div>
          <Bar />
        </div>
      );
    };
    const Bar = () => <div>Hi!</div>;

    act(() => render(<Foo />));

    // useMemoCache is only used by Foo component
    expect(
      reactDOMFiberRendererInterface
        .getDisplayNameForElementID(2)
        .indexOf('Forget'),
    ).toBe(0);
    expect(
      reactDOMFiberRendererInterface
        .getDisplayNameForElementID(3)
        .indexOf('Forget'),
    ).toBe(-1);
  });
});

Domain

Dependencies

Frequently Asked Questions

What does compiler-integration-test.js do?
compiler-integration-test.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain.
What does compiler-integration-test.js depend on?
compiler-integration-test.js imports 1 module(s): utils.js.
Where is compiler-integration-test.js in the architecture?
compiler-integration-test.js is located at packages/react-devtools-shared/src/__tests__/compiler-integration-test.js (domain: BabelCompiler, directory: packages/react-devtools-shared/src/__tests__).

Analyze Your Own Codebase

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

Try Supermodel Free