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

[Flight] Update test to reset modules instead of using private state #24055

Merged
merged 1 commit into from
Mar 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions packages/react-client/src/__tests__/ReactFlight-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ let ReactNoopFlightClient;
let ErrorBoundary;
let NoErrorExpected;
let Scheduler;
let ContextRegistry;

describe('ReactFlight', () => {
beforeEach(() => {
Expand All @@ -30,9 +29,6 @@ describe('ReactFlight', () => {
ReactNoopFlightClient = require('react-noop-renderer/flight-client');
act = require('jest-react').act;
Scheduler = require('scheduler');
const ReactSharedInternals =
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
ContextRegistry = ReactSharedInternals.ContextRegistry;

ErrorBoundary = class extends React.Component {
state = {hasError: false, error: null};
Expand Down Expand Up @@ -429,8 +425,6 @@ describe('ReactFlight', () => {

const transport = ReactNoopFlightServer.render(<Foo />);
act(() => {
ServerContext._currentRenderer = null;
ServerContext._currentRenderer2 = null;
Copy link
Collaborator Author

@sebmarkbage sebmarkbage Mar 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note sure what this was testing exactly or if it was just left over.

ReactNoop.render(ReactNoopFlightClient.read(transport));
});

Expand Down Expand Up @@ -631,14 +625,26 @@ describe('ReactFlight', () => {
const transport = ReactNoopFlightServer.render(<ServerApp />);

expect(ClientContext).toBe(undefined);

// Reset all modules, except flight-modules which keeps the registry of client components
const flightModules = require('react-noop-renderer/flight-modules');
jest.resetModules();
jest.mock('react-noop-renderer/flight-modules', () => flightModules);

React = require('react');
ReactNoop = require('react-noop-renderer');
ReactNoopFlightServer = require('react-noop-renderer/flight-server');
ReactNoopFlightClient = require('react-noop-renderer/flight-client');
act = require('jest-react').act;
Scheduler = require('scheduler');

act(() => {
delete ContextRegistry.ServerContext;
ServerContext._currentRenderer = null;
ServerContext._currentRenderer2 = null;
const serverModel = ReactNoopFlightClient.read(transport);
ReactNoop.render(<ClientApp serverModel={serverModel} />);
});

expect(ClientContext).not.toBe(ServerContext);

expect(ReactNoop).toMatchRenderedOutput(
<>
<article>
Expand Down