Skip to content

Commit

Permalink
Added DebugTracing tests for CPU bound suspense
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Oct 1, 2020
1 parent 83199cb commit efe5a9c
Showing 1 changed file with 85 additions and 0 deletions.
Expand Up @@ -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('<Example/>');
return null;
}

function Wrapper({children}) {
console.log('<Wrapper/>');
return children;
}

ReactTestRenderer.create(
<React.unstable_DebugTracingMode>
<Wrapper>
<React.Suspense fallback={null} unstable_expectedLoadTime={1}>
<Example />
</React.Suspense>
</Wrapper>
</React.unstable_DebugTracingMode>,
);

expect(logs).toEqual([
'group: ⚛️ render (0b0000000000000000000000000000001)',
'log: <Wrapper/>',
'groupEnd: ⚛️ render (0b0000000000000000000000000000001)',
]);

logs.splice(0);

expect(Scheduler).toFlushUntilNextPaint([]);

expect(logs).toEqual([
'group: ⚛️ render (0b0000010000000000000000000000000)',
'log: <Example/>',
'groupEnd: ⚛️ render (0b0000010000000000000000000000000)',
]);
});

// @gate experimental && build === 'development' && enableDebugTracing
it('should log concurrent render with suspense', async () => {
const fakeSuspensePromise = Promise.resolve(true);
Expand Down Expand Up @@ -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('<Example/>');
return null;
}

function Wrapper({children}) {
console.log('<Wrapper/>');
return children;
}

ReactTestRenderer.create(
<React.unstable_DebugTracingMode>
<Wrapper>
<React.Suspense fallback={null} unstable_expectedLoadTime={1}>
<Example />
</React.Suspense>
</Wrapper>
</React.unstable_DebugTracingMode>,
{unstable_isConcurrent: true},
);

expect(logs).toEqual([]);

logs.splice(0);

expect(Scheduler).toFlushUntilNextPaint([]);

expect(logs).toEqual([
'group: ⚛️ render (0b0000000000000000000001000000000)',
'log: <Wrapper/>',
'groupEnd: ⚛️ render (0b0000000000000000000001000000000)',
]);

logs.splice(0);

expect(Scheduler).toFlushUntilNextPaint([]);

expect(logs).toEqual([
'group: ⚛️ render (0b0000010000000000000000000000000)',
'log: <Example/>',
'groupEnd: ⚛️ render (0b0000010000000000000000000000000)',
]);
});

// @gate experimental && build === 'development' && enableDebugTracing
it('should log cascading class component updates', () => {
class Example extends React.Component {
Expand Down

0 comments on commit efe5a9c

Please sign in to comment.