9
9
10
10
import type Store from 'react-devtools-shared/src/devtools/store' ;
11
11
12
+ import { getVersionedRenderImplementation } from './utils' ;
13
+
12
14
describe ( 'ProfilerStore' , ( ) => {
13
15
let React ;
14
16
let ReactDOM ;
15
- let legacyRender ;
16
17
let store : Store ;
17
18
let utils ;
18
19
19
20
beforeEach ( ( ) => {
20
21
utils = require ( './utils' ) ;
21
22
utils . beforeEachProfiling ( ) ;
22
23
23
- legacyRender = utils . legacyRender ;
24
-
25
24
store = global . store ;
26
25
store . collapseNodesByDefault = false ;
27
26
store . recordChangeDescriptions = true ;
@@ -30,6 +29,10 @@ describe('ProfilerStore', () => {
30
29
ReactDOM = require ( 'react-dom' ) ;
31
30
} ) ;
32
31
32
+ const { render, unmount} = getVersionedRenderImplementation ( ) ;
33
+ const { render : renderOther , unmount : unmountOther } =
34
+ getVersionedRenderImplementation ( ) ;
35
+
33
36
// @reactVersion >= 16.9
34
37
it ( 'should not remove profiling data when roots are unmounted' , async ( ) => {
35
38
const Parent = ( { count} ) =>
@@ -38,32 +41,27 @@ describe('ProfilerStore', () => {
38
41
. map ( ( _ , index ) => < Child key = { index } duration = { index } /> ) ;
39
42
const Child = ( ) => < div > Hi!</ div > ;
40
43
41
- const containerA = document . createElement ( 'div' ) ;
42
- const containerB = document . createElement ( 'div' ) ;
43
-
44
44
utils . act ( ( ) => {
45
- legacyRender ( < Parent key = "A" count = { 3 } /> , containerA ) ;
46
- legacyRender ( < Parent key = "B" count = { 2 } /> , containerB ) ;
45
+ render ( < Parent key = "A" count = { 3 } /> ) ;
46
+ renderOther ( < Parent key = "B" count = { 2 } /> ) ;
47
47
} ) ;
48
48
49
49
utils . act ( ( ) => store . profilerStore . startProfiling ( ) ) ;
50
50
51
51
utils . act ( ( ) => {
52
- legacyRender ( < Parent key = "A" count = { 4 } /> , containerA ) ;
53
- legacyRender ( < Parent key = "B" count = { 1 } /> , containerB ) ;
52
+ render ( < Parent key = "A" count = { 4 } /> ) ;
53
+ renderOther ( < Parent key = "B" count = { 1 } /> ) ;
54
54
} ) ;
55
55
56
56
utils . act ( ( ) => store . profilerStore . stopProfiling ( ) ) ;
57
57
58
58
const rootA = store . roots [ 0 ] ;
59
59
const rootB = store . roots [ 1 ] ;
60
60
61
- utils . act ( ( ) => ReactDOM . unmountComponentAtNode ( containerB ) ) ;
62
-
61
+ utils . act ( ( ) => unmountOther ( ) ) ;
63
62
expect ( store . profilerStore . getDataForRoot ( rootA ) ) . not . toBeNull ( ) ;
64
63
65
- utils . act ( ( ) => ReactDOM . unmountComponentAtNode ( containerA ) ) ;
66
-
64
+ utils . act ( ( ) => unmount ( ) ) ;
67
65
expect ( store . profilerStore . getDataForRoot ( rootB ) ) . not . toBeNull ( ) ;
68
66
} ) ;
69
67
@@ -95,14 +93,9 @@ describe('ProfilerStore', () => {
95
93
return < input ref = { inputRef } value = { name } onChange = { handleChange } /> ;
96
94
} ;
97
95
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
-
103
96
// It's important that this test uses legacy sync mode.
104
97
// The root API does not trigger this particular failing case.
105
- legacyRender ( < ControlledInput /> , container ) ;
98
+ utils . act ( ( ) => render ( < ControlledInput /> ) ) ;
106
99
107
100
utils . act ( ( ) => store . profilerStore . startProfiling ( ) ) ;
108
101
@@ -148,14 +141,9 @@ describe('ProfilerStore', () => {
148
141
return < input ref = { inputRef } onBlur = { handleBlur } /> ;
149
142
} ;
150
143
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
-
156
144
// It's important that this test uses legacy sync mode.
157
145
// The root API does not trigger this particular failing case.
158
- legacyRender ( < Example /> , container ) ;
146
+ utils . act ( ( ) => render ( < Example /> ) ) ;
159
147
160
148
expect ( commitCount ) . toBe ( 1 ) ;
161
149
commitCount = 0 ;
@@ -164,10 +152,10 @@ describe('ProfilerStore', () => {
164
152
165
153
// Focus and blur.
166
154
const target = inputRef . current ;
167
- target . focus ( ) ;
168
- target . blur ( ) ;
169
- target . focus ( ) ;
170
- target . blur ( ) ;
155
+ utils . act ( ( ) => target . focus ( ) ) ;
156
+ utils . act ( ( ) => target . blur ( ) ) ;
157
+ utils . act ( ( ) => target . focus ( ) ) ;
158
+ utils . act ( ( ) => target . blur ( ) ) ;
171
159
expect ( commitCount ) . toBe ( 1 ) ;
172
160
173
161
utils . act ( ( ) => store . profilerStore . stopProfiling ( ) ) ;
@@ -204,14 +192,9 @@ describe('ProfilerStore', () => {
204
192
return state . hasOwnProperty ;
205
193
} ;
206
194
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
-
212
195
// It's important that this test uses legacy sync mode.
213
196
// The root API does not trigger this particular failing case.
214
- legacyRender ( < ControlledInput /> , container ) ;
197
+ utils . act ( ( ) => render ( < ControlledInput /> ) ) ;
215
198
216
199
utils . act ( ( ) => store . profilerStore . startProfiling ( ) ) ;
217
200
utils . act ( ( ) =>
@@ -243,9 +226,7 @@ describe('ProfilerStore', () => {
243
226
) ;
244
227
} ;
245
228
246
- const container = document . createElement ( 'div' ) ;
247
-
248
- utils . act ( ( ) => legacyRender ( < App /> , container ) ) ;
229
+ utils . act ( ( ) => render ( < App /> ) ) ;
249
230
utils . act ( ( ) => store . profilerStore . startProfiling ( ) ) ;
250
231
} ) ;
251
232
} ) ;
0 commit comments