Fix more tests

This commit is contained in:
Tianyu Yao
2023-01-20 19:46:45 -08:00
parent 556ddbf89d
commit 5a98cd288d
8 changed files with 22 additions and 76 deletions
@@ -508,13 +508,9 @@ describe('ReactExpiration', () => {
// First demonstrate what happens when there's no starvation
await act(async () => {
if (gate(flags => flags.enableSyncDefaultUpdates)) {
React.startTransition(() => {
updateNormalPri();
});
} else {
React.startTransition(() => {
updateNormalPri();
}
});
expect(Scheduler).toFlushAndYieldThrough(['Sync pri: 0']);
updateSyncPri();
expect(Scheduler).toHaveYielded(['Sync pri: 1', 'Normal pri: 0']);
@@ -532,13 +528,9 @@ describe('ReactExpiration', () => {
// Do the same thing, but starve the first update
await act(async () => {
if (gate(flags => flags.enableSyncDefaultUpdates)) {
React.startTransition(() => {
updateNormalPri();
});
} else {
React.startTransition(() => {
updateNormalPri();
}
});
expect(Scheduler).toFlushAndYieldThrough(['Sync pri: 1']);
// This time, a lot of time has elapsed since the normal pri update
@@ -171,15 +171,10 @@ describe('ReactHooksWithNoopRenderer', () => {
// Schedule some updates
act(() => {
if (gate(flags => flags.enableSyncDefaultUpdates)) {
React.startTransition(() => {
counter.current.updateCount(1);
counter.current.updateCount(count => count + 10);
});
} else {
React.startTransition(() => {
counter.current.updateCount(1);
counter.current.updateCount(count => count + 10);
}
});
// Partially flush without committing
expect(Scheduler).toFlushAndYieldThrough(['Count: 11']);
@@ -815,13 +810,9 @@ describe('ReactHooksWithNoopRenderer', () => {
ReactNoop.discreteUpdates(() => {
setRow(5);
});
if (gate(flags => flags.enableSyncDefaultUpdates)) {
React.startTransition(() => {
setRow(20);
});
} else {
React.startTransition(() => {
setRow(20);
}
});
});
expect(Scheduler).toHaveYielded(['Up', 'Down']);
expect(root).toMatchRenderedOutput(<span prop="Down" />);
@@ -215,17 +215,7 @@ describe('ReactIncremental', () => {
ReactNoop.render(<Foo />);
expect(Scheduler).toFlushWithoutYielding();
if (gate(flags => flags.enableSyncDefaultUpdates)) {
React.startTransition(() => {
inst.setState(
() => {
Scheduler.unstable_yieldValue('setState1');
return {text: 'bar'};
},
() => Scheduler.unstable_yieldValue('callback1'),
);
});
} else {
React.startTransition(() => {
inst.setState(
() => {
Scheduler.unstable_yieldValue('setState1');
@@ -233,24 +223,14 @@ describe('ReactIncremental', () => {
},
() => Scheduler.unstable_yieldValue('callback1'),
);
}
});
// Flush part of the work
expect(Scheduler).toFlushAndYieldThrough(['setState1']);
// This will abort the previous work and restart
ReactNoop.flushSync(() => ReactNoop.render(<Foo />));
if (gate(flags => flags.enableSyncDefaultUpdates)) {
React.startTransition(() => {
inst.setState(
() => {
Scheduler.unstable_yieldValue('setState2');
return {text2: 'baz'};
},
() => Scheduler.unstable_yieldValue('callback2'),
);
});
} else {
React.startTransition(() => {
inst.setState(
() => {
Scheduler.unstable_yieldValue('setState2');
@@ -258,7 +238,7 @@ describe('ReactIncremental', () => {
},
() => Scheduler.unstable_yieldValue('callback2'),
);
}
});
// Flush the rest of the work which now includes the low priority
expect(Scheduler).toFlushAndYield([
@@ -2549,13 +2549,9 @@ describe('ReactSuspenseList', () => {
await act(async () => {
// Add a few items at the end.
if (gate(flags => flags.enableSyncDefaultUpdates)) {
React.startTransition(() => {
updateLowPri(true);
});
} else {
React.startTransition(() => {
updateLowPri(true);
}
});
// Flush partially through.
expect(Scheduler).toFlushAndYieldThrough(['B', 'C']);
@@ -3796,7 +3796,6 @@ describe('ReactSuspenseWithNoopRenderer', () => {
});
// @gate enableLegacyCache
// @gate !enableSyncDefaultUpdates
it('regression: ping at high priority causes update to be dropped', async () => {
const {useState, useTransition} = React;
@@ -3863,10 +3862,9 @@ describe('ReactSuspenseWithNoopRenderer', () => {
});
expect(Scheduler).toFlushAndYield([
'B',
'Suspend! [A1]',
'Loading...',
'B',
'Suspend! [A2]',
'Loading...',
'Suspend! [B2]',
@@ -3882,6 +3880,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
await resolveText('A1');
expect(Scheduler).toFlushAndYield([
'A1',
'B',
'Suspend! [A2]',
'Loading...',
'Suspend! [B2]',
@@ -454,13 +454,9 @@ describe('useMutableSource', () => {
// Changing values should schedule an update with React.
// Start working on this update but don't finish it.
if (gate(flags => flags.enableSyncDefaultUpdates)) {
React.startTransition(() => {
source.value = 'two';
});
} else {
React.startTransition(() => {
source.value = 'two';
}
});
expect(Scheduler).toFlushAndYieldThrough(['a:two']);
// Re-renders that occur before the update is processed
@@ -1065,13 +1065,9 @@ describe(`onRender`, () => {
// Render a partially update, but don't finish.
// This partial render will take 10ms of actual render time.
if (gate(flags => flags.enableSyncDefaultUpdates)) {
React.startTransition(() => {
first.setState({renderTime: 10});
});
} else {
React.startTransition(() => {
first.setState({renderTime: 10});
}
});
expect(Scheduler).toFlushAndYieldThrough(['FirstComponent:10']);
expect(callback).toHaveBeenCalledTimes(0);
@@ -439,13 +439,9 @@ describe('useSubscription', () => {
// Start React update, but don't finish
act(() => {
if (gate(flags => flags.enableSyncDefaultUpdates)) {
React.startTransition(() => {
renderer.update(<Parent observed={observableB} />);
});
} else {
React.startTransition(() => {
renderer.update(<Parent observed={observableB} />);
}
});
expect(Scheduler).toFlushAndYieldThrough(['Child: b-0']);
expect(log).toEqual([]);