@@ -232,32 +232,37 @@ function runPlaceholderTests(suiteLabel, loadReactNoop) {
232232
233233 describe ( 'profiler durations' , ( ) => {
234234 let App ;
235- let Fallback ;
236- let Suspending ;
237235 let onRender ;
238236
239237 beforeEach ( ( ) => {
240238 // Order of parameters: id, phase, actualDuration, treeBaseDuration
241239 onRender = jest . fn ( ) ;
242240
243- Fallback = ( ) => {
241+ const Fallback = ( ) => {
244242 ReactTestRenderer . unstable_yield ( 'Fallback' ) ;
245- advanceTimeBy ( 5 ) ;
243+ advanceTimeBy ( 10 ) ;
246244 return 'Loading...' ;
247245 } ;
248246
249- Suspending = ( ) => {
247+ const Suspending = ( ) => {
250248 ReactTestRenderer . unstable_yield ( 'Suspending' ) ;
251249 advanceTimeBy ( 2 ) ;
252250 return < AsyncText ms = { 1000 } text = "Loaded" fakeRenderDuration = { 1 } /> ;
253251 } ;
254252
253+ const NonSuspending = ( ) => {
254+ ReactTestRenderer . unstable_yield ( 'NonSuspending' ) ;
255+ advanceTimeBy ( 5 ) ;
256+ return 'NonSuspending' ;
257+ } ;
258+
255259 App = ( ) => {
256260 ReactTestRenderer . unstable_yield ( 'App' ) ;
257261 return (
258262 < Profiler id = "root" onRender = { onRender } >
259263 < Suspense maxDuration = { 500 } fallback = { < Fallback /> } >
260264 < Suspending />
265+ < NonSuspending />
261266 </ Suspense >
262267 </ Profiler >
263268 ) ;
@@ -266,30 +271,31 @@ function runPlaceholderTests(suiteLabel, loadReactNoop) {
266271
267272 it ( 'properly accounts for base durations when a suspended times out in a sync tree' , ( ) => {
268273 const root = ReactTestRenderer . create ( < App /> ) ;
269- expect ( root . toJSON ( ) ) . toEqual ( 'Loading...' ) ;
274+ expect ( root . toJSON ( ) ) . toEqual ( [ 'Loading...' ] ) ;
270275 expect ( onRender ) . toHaveBeenCalledTimes ( 2 ) ;
271276
272- // Initial mount should be 3ms–
273- // 2ms from Suspending, and 1ms from the AsyncText it renders.
274- expect ( onRender . mock . calls [ 0 ] [ 2 ] ) . toBe ( 3 ) ;
275- expect ( onRender . mock . calls [ 0 ] [ 3 ] ) . toBe ( 3 ) ;
277+ // Initial mount should be 8ms–
278+ // 2ms from Suspending, 1ms from the AsyncText it renders,
279+ // And 5ms from NonSuspending.
280+ expect ( onRender . mock . calls [ 0 ] [ 2 ] ) . toBe ( 8 ) ;
281+ expect ( onRender . mock . calls [ 0 ] [ 3 ] ) . toBe ( 8 ) ;
276282
277- // When the fallback UI is displayed, and the origina UI hidden,
278- // the baseDuration should only include the 5ms spent rendering Fallback,
279- // but the treeBaseDuration should include that and the 3ms spent in Suspending .
280- expect ( onRender . mock . calls [ 1 ] [ 2 ] ) . toBe ( 5 ) ;
281- expect ( onRender . mock . calls [ 1 ] [ 3 ] ) . toBe ( 8 ) ;
283+ // When the fallback UI is displayed, and the original UI is hidden,
284+ // the baseDuration should only include the 10ms spent rendering Fallback,
285+ // but the treeBaseDuration should include that and the 8ms spent in the hidden tree .
286+ expect ( onRender . mock . calls [ 1 ] [ 2 ] ) . toBe ( 10 ) ;
287+ expect ( onRender . mock . calls [ 1 ] [ 3 ] ) . toBe ( 18 ) ;
282288
283289 jest . advanceTimersByTime ( 1000 ) ;
284290
285- expect ( root . toJSON ( ) ) . toEqual ( 'Loaded' ) ;
291+ expect ( root . toJSON ( ) ) . toEqual ( [ 'Loaded' , 'NonSuspending' ] ) ;
286292 expect ( onRender ) . toHaveBeenCalledTimes ( 3 ) ;
287293
288294 // When the suspending data is resolved and our final UI is rendered,
289295 // the baseDuration should only include the 1ms re-rendering AsyncText,
290- // but the treeBaseDuration should include that and the 2ms spent rendering Suspending .
296+ // but the treeBaseDuration should include the full 8ms spent in the tree .
291297 expect ( onRender . mock . calls [ 2 ] [ 2 ] ) . toBe ( 1 ) ;
292- expect ( onRender . mock . calls [ 2 ] [ 3 ] ) . toBe ( 3 ) ;
298+ expect ( onRender . mock . calls [ 2 ] [ 3 ] ) . toBe ( 8 ) ;
293299 } ) ;
294300
295301 it ( 'properly accounts for base durations when a suspended times out in a concurrent tree' , ( ) => {
@@ -301,6 +307,7 @@ function runPlaceholderTests(suiteLabel, loadReactNoop) {
301307 'App' ,
302308 'Suspending' ,
303309 'Suspend! [Loaded]' ,
310+ 'NonSuspending' ,
304311 'Fallback' ,
305312 ] ) ;
306313 expect ( root ) . toMatchRenderedOutput ( null ) ;
@@ -312,19 +319,19 @@ function runPlaceholderTests(suiteLabel, loadReactNoop) {
312319 expect ( onRender ) . toHaveBeenCalledTimes ( 1 ) ;
313320
314321 // Initial mount only shows the "Loading..." Fallback.
315- // The treeBaseDuration then should be 5ms spent rendering Fallback,
316- // but the actualDuration should include that and the 3ms spent in Suspending .
317- expect ( onRender . mock . calls [ 0 ] [ 2 ] ) . toBe ( 8 ) ;
318- expect ( onRender . mock . calls [ 0 ] [ 3 ] ) . toBe ( 5 ) ;
322+ // The treeBaseDuration then should be 10ms spent rendering Fallback,
323+ // but the actualDuration should also include the 8ms spent rendering the hidden tree .
324+ expect ( onRender . mock . calls [ 0 ] [ 2 ] ) . toBe ( 18 ) ;
325+ expect ( onRender . mock . calls [ 0 ] [ 3 ] ) . toBe ( 10 ) ;
319326
320- expect ( root ) . toFlushAndYield ( [ 'Suspending' , 'Loaded' ] ) ;
321- expect ( root ) . toMatchRenderedOutput ( 'Loaded ' ) ;
327+ expect ( root ) . toFlushAndYield ( [ 'Suspending' , 'Loaded' , 'NonSuspending' ] ) ;
328+ expect ( root ) . toMatchRenderedOutput ( 'LoadedNonSuspending ' ) ;
322329 expect ( onRender ) . toHaveBeenCalledTimes ( 2 ) ;
323330
324331 // When the suspending data is resolved and our final UI is rendered,
325- // both times should include the 3ms re-rendering Suspending and AsyncText.
326- expect ( onRender . mock . calls [ 1 ] [ 2 ] ) . toBe ( 3 ) ;
327- expect ( onRender . mock . calls [ 1 ] [ 3 ] ) . toBe ( 3 ) ;
332+ // both times should include the 8ms re-rendering Suspending and AsyncText.
333+ expect ( onRender . mock . calls [ 1 ] [ 2 ] ) . toBe ( 8 ) ;
334+ expect ( onRender . mock . calls [ 1 ] [ 3 ] ) . toBe ( 8 ) ;
328335 } ) ;
329336 } ) ;
330337 } ) ;
0 commit comments