Skip to content

Commit

Permalink
Remove flushExpired
Browse files Browse the repository at this point in the history
  • Loading branch information
rickhanlonii committed Mar 10, 2021
1 parent 60182d6 commit c979a04
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ describe('ReactDOMNativeEventHeuristic-test', () => {

// 3s should be enough to expire the updates
Scheduler.unstable_advanceTime(3000);
expect(Scheduler).toFlushExpired([]);
expect(Scheduler).toFlushWithoutYielding();
expect(container.textContent).toEqual('hovered');
});
});
Expand Down Expand Up @@ -282,7 +282,7 @@ describe('ReactDOMNativeEventHeuristic-test', () => {

// 3s should be enough to expire the updates
Scheduler.unstable_advanceTime(3000);
expect(Scheduler).toFlushExpired([]);
expect(Scheduler).toFlushWithoutYielding();
expect(container.textContent).toEqual('hovered');
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ describe('ChangeEventPlugin', () => {

// 3s should be enough to expire the updates
Scheduler.unstable_advanceTime(3000);
expect(Scheduler).toFlushExpired([]);
expect(Scheduler).toFlushWithoutYielding();
expect(container.textContent).toEqual('hovered');
});
});
Expand Down
11 changes: 5 additions & 6 deletions packages/react-reconciler/src/__tests__/ReactExpiration-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ describe('ReactExpiration', () => {

Scheduler.unstable_advanceTime(10000);

expect(Scheduler).toFlushExpired(['D', 'E']);
expect(Scheduler).toFlushUntilNextPaint(['D', 'E']);
expect(root).toMatchRenderedOutput('ABCDE');
});

Expand Down Expand Up @@ -351,7 +351,7 @@ describe('ReactExpiration', () => {

Scheduler.unstable_advanceTime(10000);

expect(Scheduler).toFlushExpired(['D', 'E']);
expect(Scheduler).toFlushUntilNextPaint(['D', 'E']);
expect(root).toMatchRenderedOutput('ABCDE');
});

Expand All @@ -373,12 +373,12 @@ describe('ReactExpiration', () => {
ReactNoop.render('Hi');

// The update should not have expired yet.
expect(Scheduler).toFlushExpired([]);
expect(Scheduler).toFlushAndYieldThrough([]);
expect(ReactNoop).toMatchRenderedOutput(null);

// Advance the time some more to expire the update.
Scheduler.unstable_advanceTime(10000);
expect(Scheduler).toFlushExpired([]);
expect(Scheduler).toFlushWithoutYielding();
expect(ReactNoop).toMatchRenderedOutput('Hi');
});

Expand All @@ -391,15 +391,14 @@ describe('ReactExpiration', () => {
Scheduler.unstable_advanceTime(10000);

ReactNoop.render('Hi');
expect(Scheduler).toFlushExpired([]);
expect(ReactNoop).toMatchRenderedOutput(null);

// Advancing by ~5 seconds should be sufficient to expire the update. (I
// used a slightly larger number to allow for possible rounding.)
Scheduler.unstable_advanceTime(6000);

ReactNoop.render('Hi');
expect(Scheduler).toFlushExpired([]);
expect(Scheduler).toFlushAndYieldThrough([]);
expect(ReactNoop).toMatchRenderedOutput('Hi');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ describe('ReactIncrementalUpdates', () => {

ReactNoop.act(() => {
ReactNoop.render(<App />);
expect(Scheduler).toFlushExpired([]);
expect(Scheduler).toFlushAndYieldThrough([]);
expect(Scheduler).toFlushAndYield([
'Render: 0',
'Commit: 0',
Expand All @@ -479,7 +479,9 @@ describe('ReactIncrementalUpdates', () => {
Scheduler.unstable_advanceTime(10000);

setCount(2);
expect(Scheduler).toFlushExpired([]);
expect(Scheduler).toFlushAndYieldThrough([]);
expect(Scheduler).toFlushAndYield([]);
// TODO
});
});

Expand All @@ -497,7 +499,11 @@ describe('ReactIncrementalUpdates', () => {
Scheduler.unstable_advanceTime(10000);

ReactNoop.render(<Text text="B" />);
expect(Scheduler).toFlushExpired([]);

// Nothing has expired.
expect(Scheduler).toFlushAndYieldThrough([]);

expect(Scheduler).toFlushAndYield(['B']);
});

it('regression: does not expire soon due to previous expired work', () => {
Expand All @@ -508,12 +514,12 @@ describe('ReactIncrementalUpdates', () => {

ReactNoop.render(<Text text="A" />);
Scheduler.unstable_advanceTime(10000);
expect(Scheduler).toFlushExpired(['A']);
expect(Scheduler).toFlushAndYieldThrough(['A']);

Scheduler.unstable_advanceTime(10000);

ReactNoop.render(<Text text="B" />);
expect(Scheduler).toFlushExpired([]);
expect(Scheduler).toFlushUntilNextPaint([]);
});

it('when rebasing, does not exclude updates that were already committed, regardless of priority', async () => {
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
Scheduler.unstable_advanceTime(10000);
jest.advanceTimersByTime(10000);

expect(Scheduler).toFlushExpired([
expect(Scheduler).toFlushUntilNextPaint([
'Suspend! [goodbye]',
'Loading...',
'Commit: goodbye',
Expand Down
Loading

0 comments on commit c979a04

Please sign in to comment.