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

chore: use versioned render in FastRefreshDevToolsIntegration test #28211

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
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,20 @@
* @flow
*/

import {getVersionedRenderImplementation} from './utils';

describe('Fast Refresh', () => {
let React;
let ReactFreshRuntime;
let act;
let babel;
let container;
let exportsObj;
let freshPlugin;
let legacyRender;
let store;
let withErrorsOrWarningsIgnored;

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

beforeEach(() => {
exportsObj = undefined;
container = document.createElement('div');

babel = require('@babel/core');
freshPlugin = require('react-refresh/babel');
Expand All @@ -39,10 +34,12 @@ describe('Fast Refresh', () => {

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

const {render: renderImplementation, getContainer} =
getVersionedRenderImplementation();

function execute(source) {
const compiled = babel.transform(source, {
babelrc: false,
Expand Down Expand Up @@ -73,7 +70,7 @@ describe('Fast Refresh', () => {
function render(source) {
const Component = execute(source);
act(() => {
legacyRender(<Component />, container);
renderImplementation(<Component />);
});
// Module initialization shouldn't be counted as a hot update.
expect(ReactFreshRuntime.performReactRefresh()).toBe(null);
Expand All @@ -98,7 +95,7 @@ describe('Fast Refresh', () => {
// Here, we'll just force a re-render using the newer type to emulate this.
const NextComponent = nextExports.default;
act(() => {
legacyRender(<NextComponent />, container);
renderImplementation(<NextComponent />);
});
}
act(() => {
Expand Down Expand Up @@ -142,8 +139,8 @@ describe('Fast Refresh', () => {
<Child key="A">
`);

let element = container.firstChild;
expect(container.firstChild).not.toBe(null);
let element = getContainer().firstChild;
expect(getContainer().firstChild).not.toBe(null);

patch(`
function Parent() {
Expand All @@ -163,8 +160,8 @@ describe('Fast Refresh', () => {
`);

// State is preserved; this verifies that Fast Refresh is wired up.
expect(container.firstChild).toBe(element);
element = container.firstChild;
expect(getContainer().firstChild).toBe(element);
element = getContainer().firstChild;

patch(`
function Parent() {
Expand All @@ -184,7 +181,7 @@ describe('Fast Refresh', () => {
`);

// State is reset because hooks changed.
expect(container.firstChild).not.toBe(element);
expect(getContainer().firstChild).not.toBe(element);
});

// @reactVersion >= 16.9
Expand Down