Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace flushExpired (mostly) #20975

Merged
merged 1 commit into from Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
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
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
Expand Up @@ -414,6 +414,7 @@ function cancelHostTimeout(): void {

function shouldYieldToHost(): boolean {
if (
(expectedNumberOfYields === 0 && yieldedValues === null) ||
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this about?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do

expect(Scheduler).toFlushAndYieldThrough([]);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yieldedValues === null doesn't seem necessary

(expectedNumberOfYields !== -1 &&
yieldedValues !== null &&
yieldedValues.length >= expectedNumberOfYields) ||
Expand Down