Skip to content

Commit 97e28e0

Browse files
committed
chore: use versioned render in profilerStore test
1 parent e51cda5 commit 97e28e0

File tree

1 file changed

+20
-41
lines changed

1 file changed

+20
-41
lines changed

packages/react-devtools-shared/src/__tests__/profilerStore-test.js

+20-41
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,28 @@
99

1010
import type Store from 'react-devtools-shared/src/devtools/store';
1111

12+
import {getVersionedRenderImplementation} from './utils';
13+
1214
describe('ProfilerStore', () => {
1315
let React;
14-
let ReactDOM;
15-
let legacyRender;
1616
let store: Store;
1717
let utils;
1818

1919
beforeEach(() => {
2020
utils = require('./utils');
2121
utils.beforeEachProfiling();
2222

23-
legacyRender = utils.legacyRender;
24-
2523
store = global.store;
2624
store.collapseNodesByDefault = false;
2725
store.recordChangeDescriptions = true;
2826

2927
React = require('react');
30-
ReactDOM = require('react-dom');
3128
});
3229

30+
const {render, unmount} = getVersionedRenderImplementation();
31+
const {render: renderOther, unmount: unmountOther} =
32+
getVersionedRenderImplementation();
33+
3334
// @reactVersion >= 16.9
3435
it('should not remove profiling data when roots are unmounted', async () => {
3536
const Parent = ({count}) =>
@@ -38,32 +39,27 @@ describe('ProfilerStore', () => {
3839
.map((_, index) => <Child key={index} duration={index} />);
3940
const Child = () => <div>Hi!</div>;
4041

41-
const containerA = document.createElement('div');
42-
const containerB = document.createElement('div');
43-
4442
utils.act(() => {
45-
legacyRender(<Parent key="A" count={3} />, containerA);
46-
legacyRender(<Parent key="B" count={2} />, containerB);
43+
render(<Parent key="A" count={3} />);
44+
renderOther(<Parent key="B" count={2} />);
4745
});
4846

4947
utils.act(() => store.profilerStore.startProfiling());
5048

5149
utils.act(() => {
52-
legacyRender(<Parent key="A" count={4} />, containerA);
53-
legacyRender(<Parent key="B" count={1} />, containerB);
50+
render(<Parent key="A" count={4} />);
51+
renderOther(<Parent key="B" count={1} />);
5452
});
5553

5654
utils.act(() => store.profilerStore.stopProfiling());
5755

5856
const rootA = store.roots[0];
5957
const rootB = store.roots[1];
6058

61-
utils.act(() => ReactDOM.unmountComponentAtNode(containerB));
62-
59+
utils.act(() => unmountOther());
6360
expect(store.profilerStore.getDataForRoot(rootA)).not.toBeNull();
6461

65-
utils.act(() => ReactDOM.unmountComponentAtNode(containerA));
66-
62+
utils.act(() => unmount());
6763
expect(store.profilerStore.getDataForRoot(rootB)).not.toBeNull();
6864
});
6965

@@ -95,14 +91,9 @@ describe('ProfilerStore', () => {
9591
return <input ref={inputRef} value={name} onChange={handleChange} />;
9692
};
9793

98-
const container = document.createElement('div');
99-
100-
// This element has to be in the <body> for the event system to work.
101-
document.body.appendChild(container);
102-
10394
// It's important that this test uses legacy sync mode.
10495
// The root API does not trigger this particular failing case.
105-
legacyRender(<ControlledInput />, container);
96+
utils.act(() => render(<ControlledInput />));
10697

10798
utils.act(() => store.profilerStore.startProfiling());
10899

@@ -148,14 +139,9 @@ describe('ProfilerStore', () => {
148139
return <input ref={inputRef} onBlur={handleBlur} />;
149140
};
150141

151-
const container = document.createElement('div');
152-
153-
// This element has to be in the <body> for the event system to work.
154-
document.body.appendChild(container);
155-
156142
// It's important that this test uses legacy sync mode.
157143
// The root API does not trigger this particular failing case.
158-
legacyRender(<Example />, container);
144+
utils.act(() => render(<Example />));
159145

160146
expect(commitCount).toBe(1);
161147
commitCount = 0;
@@ -164,10 +150,10 @@ describe('ProfilerStore', () => {
164150

165151
// Focus and blur.
166152
const target = inputRef.current;
167-
target.focus();
168-
target.blur();
169-
target.focus();
170-
target.blur();
153+
utils.act(() => target.focus());
154+
utils.act(() => target.blur());
155+
utils.act(() => target.focus());
156+
utils.act(() => target.blur());
171157
expect(commitCount).toBe(1);
172158

173159
utils.act(() => store.profilerStore.stopProfiling());
@@ -204,14 +190,9 @@ describe('ProfilerStore', () => {
204190
return state.hasOwnProperty;
205191
};
206192

207-
const container = document.createElement('div');
208-
209-
// This element has to be in the <body> for the event system to work.
210-
document.body.appendChild(container);
211-
212193
// It's important that this test uses legacy sync mode.
213194
// The root API does not trigger this particular failing case.
214-
legacyRender(<ControlledInput />, container);
195+
utils.act(() => render(<ControlledInput />));
215196

216197
utils.act(() => store.profilerStore.startProfiling());
217198
utils.act(() =>
@@ -243,9 +224,7 @@ describe('ProfilerStore', () => {
243224
);
244225
};
245226

246-
const container = document.createElement('div');
247-
248-
utils.act(() => legacyRender(<App />, container));
227+
utils.act(() => render(<App />));
249228
utils.act(() => store.profilerStore.startProfiling());
250229
});
251230
});

0 commit comments

Comments
 (0)