Skip to content

Commit

Permalink
chore: use versioned render in FastRefreshDevToolsIntegration test
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxyq committed Feb 2, 2024
1 parent e51cda5 commit 631bb9e
Showing 1 changed file with 12 additions and 15 deletions.
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

0 comments on commit 631bb9e

Please sign in to comment.