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

Decouple public and internal act implementation #19745

Merged
merged 1 commit into from
Sep 8, 2020

Commits on Sep 8, 2020

  1. Decouple public, internal act implementation

    In the next major release, we intend to drop support for using the `act`
    testing helper in production. (It already fires a warning.) The
    rationale is that, in order for `act` to work, you must either mock the
    testing environment or add extra logic at runtime. Mocking the testing
    environment isn't ideal because it requires extra set up for the user.
    Extra logic at runtime is fine only in development mode — we don't want
    to slow down the production builds.
    
    Since most people only run their tests in development mode, dropping
    support for production should be fine; if there's demand, we can add it
    back later using a special testing build that is identical to the
    production build except for the additional testing logic.
    
    One blocker for removing production support is that we currently use
    `act` to test React itself. We must test React in both development and
    production modes.
    
    So, the solution is to fork `act` into separate public and
    internal implementations:
    
    - *public implementation of `act`* – exposed to users, only works in
      development mode, uses special runtime logic, does not support partial
      rendering
    - *internal implementation of `act`* – private, works in both
      development and productionm modes, only used by the React Core test
      suite, uses no special runtime logic, supports partial rendering (i.e.
      `toFlushAndYieldThrough`)
    
    The internal implementation should mostly match the public
    implementation's behavior, but since it's a private API, it doesn't have
    to match exactly. It works by mocking the test environment: it uses a
    mock build of Scheduler to flush rendering tasks, and Jest's mock timers
    to flush Suspense placeholders.
    
    ---
    
    In this first commit, I've added the internal forks of `act` and
    migrated our tests to use them. The public `act` implementation is
    unaffected for now; I will leave refactoring/clean-up for a later step.
    acdlite committed Sep 8, 2020
    Configuration menu
    Copy the full SHA
    f9a1a9b View commit details
    Browse the repository at this point in the history