chore: use versioned render in FastRefreshDevToolsIntegration test (#28211)
Ruslan Lesiutin committed
Feb 5, 2024 at 17:09 UTC
f3a70990a5a03bb26e6a71e43c204849392d2b07
1 file changed
+12
-15
packages/react-devtools-shared/src/__tests__/FastRefreshDevToolsIntegration-test.js
+12
-15
@@ -7,25 +7,20 @@
7
* @flow
8
*/
9
10
+import {getVersionedRenderImplementation} from './utils';
11
+
12
describe('Fast Refresh', () => {
13
let React;
14
let ReactFreshRuntime;
15
let act;
16
let babel;
15
- let container;
17
let exportsObj;
18
let freshPlugin;
18
- let legacyRender;
19
let store;
20
let withErrorsOrWarningsIgnored;
21
22
- afterEach(() => {
23
- jest.resetModules();
24
- });
25
-
22
beforeEach(() => {
23
exportsObj = undefined;
28
- container = document.createElement('div');
24
25
babel = require('@babel/core');
26
freshPlugin = require('react-refresh/babel');
@@ -39,10 +34,12 @@ describe('Fast Refresh', () => {
34
35
const utils = require('./utils');
36
act = utils.act;
42
- legacyRender = utils.legacyRender;
37
withErrorsOrWarningsIgnored = utils.withErrorsOrWarningsIgnored;
38
});
39
40
+ const {render: renderImplementation, getContainer} =
41
+ getVersionedRenderImplementation();
42
+
43
function execute(source) {
44
const compiled = babel.transform(source, {
45
babelrc: false,
@@ -73,7 +70,7 @@ describe('Fast Refresh', () => {
70
function render(source) {
71
const Component = execute(source);
72
act(() => {
76
- legacyRender(<Component />, container);
73
+ renderImplementation(<Component />);
74
});
75
// Module initialization shouldn't be counted as a hot update.
76
expect(ReactFreshRuntime.performReactRefresh()).toBe(null);
@@ -98,7 +95,7 @@ describe('Fast Refresh', () => {
95
// Here, we'll just force a re-render using the newer type to emulate this.
96
const NextComponent = nextExports.default;
97
act(() => {
101
- legacyRender(<NextComponent />, container);
98
+ renderImplementation(<NextComponent />);
99
});
100
}
101
act(() => {
@@ -142,8 +139,8 @@ describe('Fast Refresh', () => {
139
<Child key="A">
140
`);
141
145
- let element = container.firstChild;
146
- expect(container.firstChild).not.toBe(null);
142
+ let element = getContainer().firstChild;
143
+ expect(getContainer().firstChild).not.toBe(null);
144
145
patch(`
146
function Parent() {
@@ -163,8 +160,8 @@ describe('Fast Refresh', () => {
160
`);
161
162
// State is preserved; this verifies that Fast Refresh is wired up.
166
- expect(container.firstChild).toBe(element);
167
- element = container.firstChild;
163
+ expect(getContainer().firstChild).toBe(element);
164
+ element = getContainer().firstChild;
165
166
patch(`
167
function Parent() {
@@ -184,7 +181,7 @@ describe('Fast Refresh', () => {
181
`);
182
183
// State is reset because hooks changed.
187
- expect(container.firstChild).not.toBe(element);
184
+ expect(getContainer().firstChild).not.toBe(element);
185
});
186
187
// @reactVersion >= 16.9