Skip to content

Commit

Permalink
Improved Profiler commit hooks test (#20053)
Browse files Browse the repository at this point in the history
Previously the tests didn't ensure that time spent during cascading render was not included in duration reported by commit hooks.
  • Loading branch information
Brian Vaughn authored Oct 19, 2020
1 parent dfb6a40 commit 7b6cac9
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions packages/react/src/__tests__/ReactProfiler-test.internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -1400,6 +1400,7 @@ describe('Profiler', () => {

const ComponentWithEffects = ({shouldCascade}) => {
const [didCascade, setDidCascade] = React.useState(false);
Scheduler.unstable_advanceTime(100000000);
React.useLayoutEffect(() => {
if (shouldCascade && !didCascade) {
setDidCascade(true);
Expand All @@ -1426,6 +1427,7 @@ describe('Profiler', () => {
}
}
render() {
Scheduler.unstable_advanceTime(1000000000);
return null;
}
}
Expand All @@ -1447,7 +1449,7 @@ describe('Profiler', () => {
expect(call[0]).toBe('mount-test');
expect(call[1]).toBe('mount');
expect(call[2]).toBe(1010); // durations
expect(call[3]).toBe(1); // commit start time (before mutations or effects)
expect(call[3]).toBe(1100000001); // commit start time (before mutations or effects)
expect(call[4]).toEqual(enableSchedulerTracing ? new Set() : undefined); // interaction events

call = callback.mock.calls[1];
Expand All @@ -1456,7 +1458,7 @@ describe('Profiler', () => {
expect(call[0]).toBe('mount-test');
expect(call[1]).toBe('update');
expect(call[2]).toBe(130); // durations
expect(call[3]).toBe(1011); // commit start time (before mutations or effects)
expect(call[3]).toBe(1200001011); // commit start time (before mutations or effects)
expect(call[4]).toEqual(enableSchedulerTracing ? new Set() : undefined); // interaction events

Scheduler.unstable_advanceTime(1);
Expand All @@ -1476,7 +1478,7 @@ describe('Profiler', () => {
expect(call[0]).toBe('update-test');
expect(call[1]).toBe('update');
expect(call[2]).toBe(10130); // durations
expect(call[3]).toBe(1142); // commit start time (before mutations or effects)
expect(call[3]).toBe(2300001142); // commit start time (before mutations or effects)
expect(call[4]).toEqual(enableSchedulerTracing ? new Set() : undefined); // interaction events

call = callback.mock.calls[3];
Expand All @@ -1485,7 +1487,7 @@ describe('Profiler', () => {
expect(call[0]).toBe('update-test');
expect(call[1]).toBe('update');
expect(call[2]).toBe(10000); // durations
expect(call[3]).toBe(11272); // commit start time (before mutations or effects)
expect(call[3]).toBe(3300011272); // commit start time (before mutations or effects)
expect(call[4]).toEqual(enableSchedulerTracing ? new Set() : undefined); // interaction events
});

Expand Down Expand Up @@ -1966,6 +1968,7 @@ describe('Profiler', () => {

const ComponentWithEffects = () => {
const [didMount, setDidMount] = React.useState(false);
Scheduler.unstable_advanceTime(1000);
React.useEffect(() => {
if (!didMount) {
setDidMount(true);
Expand Down Expand Up @@ -1996,7 +1999,7 @@ describe('Profiler', () => {
expect(call[0]).toBe('mount-test');
expect(call[1]).toBe('mount');
expect(call[2]).toBe(10); // durations
expect(call[3]).toBe(1); // commit start time (before mutations or effects)
expect(call[3]).toBe(1001); // commit start time (before mutations or effects)
expect(call[4]).toEqual(enableSchedulerTracing ? new Set() : undefined); // interaction events

call = callback.mock.calls[1];
Expand All @@ -2005,7 +2008,7 @@ describe('Profiler', () => {
expect(call[0]).toBe('mount-test');
expect(call[1]).toBe('update');
expect(call[2]).toBe(130); // durations
expect(call[3]).toBe(11); // commit start time (before mutations or effects)
expect(call[3]).toBe(2011); // commit start time (before mutations or effects)
expect(call[4]).toEqual(enableSchedulerTracing ? new Set() : undefined); // interaction events
});

Expand Down

0 comments on commit 7b6cac9

Please sign in to comment.