Skip to content

Commit

Permalink
Replace some flushExpired callsites (#20975)
Browse files Browse the repository at this point in the history
  • Loading branch information
rickhanlonii authored Mar 22, 2021
1 parent 1fafac0 commit ca99ae9
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ describe('ReactSuspense', () => {

await LazyClass;

expect(Scheduler).toFlushExpired(['Hi', 'Did mount: Hi']);
expect(Scheduler).toFlushUntilNextPaint(['Hi', 'Did mount: Hi']);
expect(root).toMatchRenderedOutput('Hi');
});

Expand Down Expand Up @@ -729,7 +729,7 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(100);

expect(Scheduler).toHaveYielded(['Promise resolved [B:1]']);
expect(Scheduler).toFlushExpired([
expect(Scheduler).toFlushUntilNextPaint([
'B:1',
'Unmount [Loading...]',
// Should be a mount, not an update
Expand All @@ -748,7 +748,7 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(100);

expect(Scheduler).toHaveYielded(['Promise resolved [B:2]']);
expect(Scheduler).toFlushExpired([
expect(Scheduler).toFlushUntilNextPaint([
'B:2',
'Unmount [Loading...]',
'Update [B:2]',
Expand Down Expand Up @@ -786,7 +786,7 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [A]']);
expect(Scheduler).toFlushExpired(['A']);
expect(Scheduler).toFlushUntilNextPaint(['A']);
expect(root).toMatchRenderedOutput('Stateful: 1A');

root.update(<App text="B" />);
Expand All @@ -804,7 +804,7 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [B]']);
expect(Scheduler).toFlushExpired(['B']);
expect(Scheduler).toFlushUntilNextPaint(['B']);
expect(root).toMatchRenderedOutput('Stateful: 2B');
});

Expand Down Expand Up @@ -846,7 +846,7 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [A]']);
expect(Scheduler).toFlushExpired(['A']);
expect(Scheduler).toFlushUntilNextPaint(['A']);
expect(root).toMatchRenderedOutput('Stateful: 1A');

root.update(<App text="B" />);
Expand All @@ -871,7 +871,7 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [B]']);
expect(Scheduler).toFlushExpired(['B']);
expect(Scheduler).toFlushUntilNextPaint(['B']);
expect(root).toMatchRenderedOutput('Stateful: 2B');
});

Expand Down Expand Up @@ -951,7 +951,7 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(500);

expect(Scheduler).toHaveYielded(['Promise resolved [A]']);
expect(Scheduler).toFlushExpired(['A', 'Did commit: A']);
expect(Scheduler).toFlushUntilNextPaint(['A', 'Did commit: A']);
});

it('retries when an update is scheduled on a timed out tree', () => {
Expand Down Expand Up @@ -1038,7 +1038,7 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [Child 1]']);
expect(Scheduler).toFlushExpired([
expect(Scheduler).toFlushUntilNextPaint([
'Child 1',
'Suspend! [Child 2]',
'Suspend! [Child 3]',
Expand All @@ -1047,12 +1047,15 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [Child 2]']);
expect(Scheduler).toFlushExpired(['Child 2', 'Suspend! [Child 3]']);
expect(Scheduler).toFlushUntilNextPaint([
'Child 2',
'Suspend! [Child 3]',
]);

jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [Child 3]']);
expect(Scheduler).toFlushExpired(['Child 3']);
expect(Scheduler).toFlushUntilNextPaint(['Child 3']);
expect(root).toMatchRenderedOutput(
['Child 1', 'Child 2', 'Child 3'].join(''),
);
Expand Down Expand Up @@ -1113,7 +1116,7 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [Tab: 0]']);
expect(Scheduler).toFlushExpired(['Tab: 0']);
expect(Scheduler).toFlushUntilNextPaint(['Tab: 0']);
expect(root).toMatchRenderedOutput('Tab: 0 + sibling');

act(() => setTab(1));
Expand All @@ -1126,7 +1129,7 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [Tab: 1]']);
expect(Scheduler).toFlushExpired(['Tab: 1']);
expect(Scheduler).toFlushUntilNextPaint(['Tab: 1']);
expect(root).toMatchRenderedOutput('Tab: 1 + sibling');

act(() => setTab(2));
Expand All @@ -1139,7 +1142,7 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [Tab: 2]']);
expect(Scheduler).toFlushExpired(['Tab: 2']);
expect(Scheduler).toFlushUntilNextPaint(['Tab: 2']);
expect(root).toMatchRenderedOutput('Tab: 2 + sibling');
});

Expand Down Expand Up @@ -1177,7 +1180,7 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [A:0]']);
expect(Scheduler).toFlushExpired(['A:0']);
expect(Scheduler).toFlushUntilNextPaint(['A:0']);
expect(root).toMatchRenderedOutput('A:0');

act(() => setStep(1));
Expand Down Expand Up @@ -1215,7 +1218,7 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [A]']);
expect(Scheduler).toFlushExpired([
expect(Scheduler).toFlushUntilNextPaint([
'A',
// The promises for B and C have now been thrown twice
'Suspend! [B]',
Expand All @@ -1226,7 +1229,7 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [B]']);
expect(Scheduler).toFlushExpired([
expect(Scheduler).toFlushUntilNextPaint([
// Even though the promise for B was thrown twice, we should only
// re-render once.
'B',
Expand All @@ -1238,7 +1241,7 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [C]']);
expect(Scheduler).toFlushExpired([
expect(Scheduler).toFlushUntilNextPaint([
// Even though the promise for C was thrown three times, we should only
// re-render once.
'C',
Expand Down Expand Up @@ -1280,7 +1283,7 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [A]']);
expect(Scheduler).toFlushExpired([
expect(Scheduler).toFlushUntilNextPaint([
'A',
// The promises for B and C have now been thrown twice
'Suspend! [B]',
Expand All @@ -1291,7 +1294,7 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [B]']);
expect(Scheduler).toFlushExpired([
expect(Scheduler).toFlushUntilNextPaint([
// Even though the promise for B was thrown twice, we should only
// re-render once.
'B',
Expand Down Expand Up @@ -1393,15 +1396,15 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [default]']);
expect(Scheduler).toFlushExpired(['default']);
expect(Scheduler).toFlushUntilNextPaint(['default']);
expect(root).toMatchRenderedOutput('default');

act(() => setValue('new value'));
expect(Scheduler).toHaveYielded(['Suspend! [new value]', 'Loading...']);
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [new value]']);
expect(Scheduler).toFlushExpired(['new value']);
expect(Scheduler).toFlushUntilNextPaint(['new value']);
expect(root).toMatchRenderedOutput('new value');
});

Expand Down Expand Up @@ -1450,15 +1453,15 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [default]']);
expect(Scheduler).toFlushExpired(['default']);
expect(Scheduler).toFlushUntilNextPaint(['default']);
expect(root).toMatchRenderedOutput('default');

act(() => setValue('new value'));
expect(Scheduler).toHaveYielded(['Suspend! [new value]', 'Loading...']);
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [new value]']);
expect(Scheduler).toFlushExpired(['new value']);
expect(Scheduler).toFlushUntilNextPaint(['new value']);
expect(root).toMatchRenderedOutput('new value');
});

Expand Down Expand Up @@ -1506,15 +1509,15 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [default]']);
expect(Scheduler).toFlushExpired(['default']);
expect(Scheduler).toFlushUntilNextPaint(['default']);
expect(root).toMatchRenderedOutput('default');

act(() => setValue('new value'));
expect(Scheduler).toHaveYielded(['Suspend! [new value]', 'Loading...']);
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [new value]']);
expect(Scheduler).toFlushExpired(['new value']);
expect(Scheduler).toFlushUntilNextPaint(['new value']);
expect(root).toMatchRenderedOutput('new value');
});

Expand Down Expand Up @@ -1558,15 +1561,15 @@ describe('ReactSuspense', () => {
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [default]']);
expect(Scheduler).toFlushExpired(['default']);
expect(Scheduler).toFlushUntilNextPaint(['default']);
expect(root).toMatchRenderedOutput('default');

act(() => setValue('new value'));
expect(Scheduler).toHaveYielded(['Suspend! [new value]', 'Loading...']);
jest.advanceTimersByTime(1000);

expect(Scheduler).toHaveYielded(['Promise resolved [new value]']);
expect(Scheduler).toFlushExpired(['new value']);
expect(Scheduler).toFlushUntilNextPaint(['new value']);
expect(root).toMatchRenderedOutput('new value');
});
});
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/__tests__/ReactProfiler-test.internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4306,7 +4306,7 @@ describe('Profiler', () => {
await resourcePromise;

expect(Scheduler).toHaveYielded(['Promise resolved [loaded]']);
expect(Scheduler).toFlushExpired([
expect(Scheduler).toFlushUntilNextPaint([
'onPostCommit',
'AsyncText [loaded]',
]);
Expand Down Expand Up @@ -4370,7 +4370,7 @@ describe('Profiler', () => {
await resourcePromise;

expect(Scheduler).toHaveYielded(['Promise resolved [loaded]']);
expect(Scheduler).toFlushExpired(['onPostCommit', 'render']);
expect(Scheduler).toFlushUntilNextPaint(['onPostCommit', 'render']);

expect(onInteractionScheduledWorkCompleted).not.toHaveBeenCalled();

Expand Down Expand Up @@ -4575,7 +4575,7 @@ describe('Profiler', () => {
await originalPromise;

expect(Scheduler).toHaveYielded(['Promise resolved [loaded]']);
expect(Scheduler).toFlushExpired(['AsyncText [loaded]']);
expect(Scheduler).toFlushUntilNextPaint(['AsyncText [loaded]']);
expect(renderer.toJSON()).toEqual(['loaded', 'updated']);
expect(Scheduler).toFlushAndYield(['onPostCommit']);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ describe('ReactProfiler DevTools integration', () => {
root.update(<Text text="B" />);

// Update B should not instantly expire.
expect(Scheduler).toFlushExpired([]);
expect(Scheduler).toFlushAndYieldThrough([]);

expect(Scheduler).toFlushAndYield(['B']);
expect(root).toMatchRenderedOutput('B');
Expand Down
4 changes: 2 additions & 2 deletions packages/scheduler/src/__tests__/SchedulerMock-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ describe('Scheduler', () => {

// Advance by just a bit more to expire the user blocking callbacks
Scheduler.unstable_advanceTime(1);
expect(Scheduler).toFlushExpired([
expect(Scheduler).toFlushAndYieldThrough([
'B (did timeout: true)',
'C (did timeout: true)',
]);

// Expire A
Scheduler.unstable_advanceTime(4600);
expect(Scheduler).toFlushExpired(['A (did timeout: true)']);
expect(Scheduler).toFlushAndYieldThrough(['A (did timeout: true)']);

// Flush the rest without expiring
expect(Scheduler).toFlushAndYield([
Expand Down
1 change: 1 addition & 0 deletions packages/scheduler/src/forks/SchedulerMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ function cancelHostTimeout(): void {

function shouldYieldToHost(): boolean {
if (
(expectedNumberOfYields === 0 && yieldedValues === null) ||
(expectedNumberOfYields !== -1 &&
yieldedValues !== null &&
yieldedValues.length >= expectedNumberOfYields) ||
Expand Down

0 comments on commit ca99ae9

Please sign in to comment.