Skip to content

followup to #15763, fix failing test in ReactDOMTracing-test #15972

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

Merged
merged 2 commits into from
Jun 24, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 41 additions & 38 deletions packages/react/src/__tests__/ReactDOMTracing-test.internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,53 +538,56 @@ describe('ReactDOMTracing', () => {
const root = ReactDOM.unstable_createRoot(container);

let interaction;
SchedulerTracing.unstable_trace('initialization', 0, () => {
interaction = Array.from(SchedulerTracing.unstable_getCurrent())[0];
// This render is only CPU bound. Nothing suspends.
root.render(<App />);
});

expect(Scheduler).toFlushAndYieldThrough(['A']);
TestUtils.act(() => {
SchedulerTracing.unstable_trace('initialization', 0, () => {
interaction = Array.from(SchedulerTracing.unstable_getCurrent())[0];
// This render is only CPU bound. Nothing suspends.
root.render(<App />);
});

Scheduler.advanceTime(300);
jest.advanceTimersByTime(300);
expect(Scheduler).toFlushAndYieldThrough(['A']);

expect(Scheduler).toFlushAndYieldThrough(['B']);
Scheduler.advanceTime(300);
jest.advanceTimersByTime(300);

Scheduler.advanceTime(300);
jest.advanceTimersByTime(300);
expect(Scheduler).toFlushAndYieldThrough(['B']);

// Time has now elapsed for so long that we're just going to give up
// rendering the rest of the content. So that we can at least show
// something.
expect(Scheduler).toFlushAndYieldThrough([
'Loading C',
'Commit A',
'Commit B',
'Commit Loading C',
]);
Scheduler.advanceTime(300);
jest.advanceTimersByTime(300);

// Schedule an unrelated low priority update that shouldn't be included
// in the previous interaction. This is meant to ensure that we don't
// rely on the whole tree completing to cover up bugs.
Scheduler.unstable_runWithPriority(
Scheduler.unstable_IdlePriority,
() => root.render(<App />),
);
// Time has now elapsed for so long that we're just going to give up
// rendering the rest of the content. So that we can at least show
// something.
expect(Scheduler).toFlushAndYieldThrough([
'Loading C',
'Commit A',
'Commit B',
'Commit Loading C',
]);

expect(onInteractionTraced).toHaveBeenCalledTimes(1);
expect(onInteractionTraced).toHaveBeenLastNotifiedOfInteraction(
interaction,
);
expect(onInteractionScheduledWorkCompleted).not.toHaveBeenCalled();
// Schedule an unrelated low priority update that shouldn't be included
// in the previous interaction. This is meant to ensure that we don't
// rely on the whole tree completing to cover up bugs.
Scheduler.unstable_runWithPriority(
Scheduler.unstable_IdlePriority,
() => root.render(<App />),
);

// Then we do a second pass to commit the last item.
expect(Scheduler).toFlushAndYieldThrough(['C', 'Commit C']);
expect(onInteractionTraced).toHaveBeenCalledTimes(1);
expect(onInteractionTraced).toHaveBeenLastNotifiedOfInteraction(
interaction,
);
expect(onInteractionScheduledWorkCompleted).not.toHaveBeenCalled();

expect(onInteractionScheduledWorkCompleted).toHaveBeenCalledTimes(1);
expect(
onInteractionScheduledWorkCompleted,
).toHaveBeenLastNotifiedOfInteraction(interaction);
// Then we do a second pass to commit the last item.
expect(Scheduler).toFlushAndYieldThrough(['C', 'Commit C']);

expect(onInteractionScheduledWorkCompleted).toHaveBeenCalledTimes(1);
expect(
onInteractionScheduledWorkCompleted,
).toHaveBeenLastNotifiedOfInteraction(interaction);
});
});
});

Expand Down