From efe5a9c475ad4c250f0969bea08f38ecad679416 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Thu, 1 Oct 2020 10:09:23 -0400 Subject: [PATCH] Added DebugTracing tests for CPU bound suspense --- .../__tests__/DebugTracing-test.internal.js | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/packages/react-reconciler/src/__tests__/DebugTracing-test.internal.js b/packages/react-reconciler/src/__tests__/DebugTracing-test.internal.js index 9ee4271dfbca8..2df04c8c88544 100644 --- a/packages/react-reconciler/src/__tests__/DebugTracing-test.internal.js +++ b/packages/react-reconciler/src/__tests__/DebugTracing-test.internal.js @@ -96,6 +96,45 @@ describe('DebugTracing', () => { expect(logs).toEqual(['log: ⚛️ Example resolved']); }); + // @gate experimental && build === 'development' && enableDebugTracing + it('should log sync render with CPU suspense', () => { + function Example() { + console.log(''); + return null; + } + + function Wrapper({children}) { + console.log(''); + return children; + } + + ReactTestRenderer.create( + + + + + + + , + ); + + expect(logs).toEqual([ + 'group: ⚛️ render (0b0000000000000000000000000000001)', + 'log: ', + 'groupEnd: ⚛️ render (0b0000000000000000000000000000001)', + ]); + + logs.splice(0); + + expect(Scheduler).toFlushUntilNextPaint([]); + + expect(logs).toEqual([ + 'group: ⚛️ render (0b0000010000000000000000000000000)', + 'log: ', + 'groupEnd: ⚛️ render (0b0000010000000000000000000000000)', + ]); + }); + // @gate experimental && build === 'development' && enableDebugTracing it('should log concurrent render with suspense', async () => { const fakeSuspensePromise = Promise.resolve(true); @@ -130,6 +169,52 @@ describe('DebugTracing', () => { expect(logs).toEqual(['log: ⚛️ Example resolved']); }); + // @gate experimental && build === 'development' && enableDebugTracing + it('should log concurrent render with CPU suspense', () => { + function Example() { + console.log(''); + return null; + } + + function Wrapper({children}) { + console.log(''); + return children; + } + + ReactTestRenderer.create( + + + + + + + , + {unstable_isConcurrent: true}, + ); + + expect(logs).toEqual([]); + + logs.splice(0); + + expect(Scheduler).toFlushUntilNextPaint([]); + + expect(logs).toEqual([ + 'group: ⚛️ render (0b0000000000000000000001000000000)', + 'log: ', + 'groupEnd: ⚛️ render (0b0000000000000000000001000000000)', + ]); + + logs.splice(0); + + expect(Scheduler).toFlushUntilNextPaint([]); + + expect(logs).toEqual([ + 'group: ⚛️ render (0b0000010000000000000000000000000)', + 'log: ', + 'groupEnd: ⚛️ render (0b0000010000000000000000000000000)', + ]); + }); + // @gate experimental && build === 'development' && enableDebugTracing it('should log cascading class component updates', () => { class Example extends React.Component {