Skip to content

Commit 60182d6

Browse files
authored
Cleanup tests using runWithPriority. (#20958)
* Remove Scheduler.runWithPriority from some tests * Mark experimental test experimental
1 parent ec372fa commit 60182d6

9 files changed

+40
-88
lines changed

Diff for: packages/react-dom/src/__tests__/ReactDOMServerPartialHydration-test.internal.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ let Suspense;
1818
let SuspenseList;
1919
let act;
2020

21+
// Copied from ReactFiberLanes. Don't do this!
22+
// This is hard coded directly to avoid needing to import, and
23+
// we'll remove this as we replace runWithPriority with React APIs.
24+
export const IdleLanePriority = 2;
25+
2126
function dispatchMouseEvent(to, from) {
2227
if (!to) {
2328
to = null;
@@ -623,7 +628,7 @@ describe('ReactDOMServerPartialHydration', () => {
623628
expect(span.textContent).toBe('Hello');
624629

625630
// Schedule an update at idle priority
626-
Scheduler.unstable_runWithPriority(Scheduler.unstable_IdlePriority, () => {
631+
ReactDOM.unstable_runWithPriority(IdleLanePriority, () => {
627632
root.render(<App text="Hi" className="hi" />);
628633
});
629634

Diff for: packages/react-dom/src/__tests__/ReactDOMServerSelectiveHydration-test.internal.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ let Scheduler;
1919
let Suspense;
2020
let act;
2121

22+
// Copied from ReactFiberLanes. Don't do this!
23+
// This is hard coded directly to avoid needing to import, and
24+
// we'll remove this as we replace runWithPriority with React APIs.
25+
export const IdleLanePriority = 2;
26+
2227
function dispatchMouseHoverEvent(to, from) {
2328
if (!to) {
2429
to = null;
@@ -96,7 +101,7 @@ function dispatchClickEvent(target) {
96101
// and there's no native DOM event that maps to idle priority, so this is a
97102
// temporary workaround. Need something like ReactDOM.unstable_IdleUpdates.
98103
function TODO_scheduleIdleDOMSchedulerTask(fn) {
99-
Scheduler.unstable_runWithPriority(Scheduler.unstable_IdlePriority, () => {
104+
ReactDOM.unstable_runWithPriority(IdleLanePriority, () => {
100105
const prevEvent = window.event;
101106
window.event = {type: 'message'};
102107
try {

Diff for: packages/react-reconciler/src/__tests__/ReactExpiration-test.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -550,11 +550,7 @@ describe('ReactExpiration', () => {
550550
function App() {
551551
const [highPri, setHighPri] = useState(0);
552552
const [normalPri, setNormalPri] = useState(0);
553-
updateHighPri = () =>
554-
Scheduler.unstable_runWithPriority(
555-
Scheduler.unstable_UserBlockingPriority,
556-
() => setHighPri(n => n + 1),
557-
);
553+
updateHighPri = () => ReactNoop.flushSync(() => setHighPri(n => n + 1));
558554
updateNormalPri = () => setNormalPri(n => n + 1);
559555
return (
560556
<>

Diff for: packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -3166,10 +3166,7 @@ describe('ReactHooksWithNoopRenderer', () => {
31663166
]);
31673167

31683168
await act(async () => {
3169-
Scheduler.unstable_runWithPriority(
3170-
Scheduler.unstable_UserBlockingPriority,
3171-
transition,
3172-
);
3169+
transition();
31733170

31743171
expect(Scheduler).toFlushAndYield([
31753172
'Before... Pending: true',

Diff for: packages/react-reconciler/src/__tests__/ReactIncrementalUpdates-test.js

+4-28
Original file line numberDiff line numberDiff line change
@@ -530,14 +530,8 @@ describe('ReactIncrementalUpdates', () => {
530530
Scheduler.unstable_yieldValue('Committed: ' + log);
531531
if (log === 'B') {
532532
// Right after B commits, schedule additional updates.
533-
// TODO: Double wrapping is temporary while we remove Scheduler runWithPriority.
534533
ReactNoop.unstable_runWithPriority(InputContinuousLanePriority, () =>
535-
Scheduler.unstable_runWithPriority(
536-
Scheduler.unstable_UserBlockingPriority,
537-
() => {
538-
pushToLog('C');
539-
},
540-
),
534+
pushToLog('C'),
541535
);
542536
setLog(prevLog => prevLog + 'D');
543537
}
@@ -556,14 +550,8 @@ describe('ReactIncrementalUpdates', () => {
556550
await ReactNoop.act(async () => {
557551
pushToLog('A');
558552

559-
// TODO: Double wrapping is temporary while we remove Scheduler runWithPriority.
560553
ReactNoop.unstable_runWithPriority(InputContinuousLanePriority, () =>
561-
Scheduler.unstable_runWithPriority(
562-
Scheduler.unstable_UserBlockingPriority,
563-
() => {
564-
pushToLog('B');
565-
},
566-
),
554+
pushToLog('B'),
567555
);
568556
});
569557
expect(Scheduler).toHaveYielded([
@@ -595,14 +583,8 @@ describe('ReactIncrementalUpdates', () => {
595583
Scheduler.unstable_yieldValue('Committed: ' + this.state.log);
596584
if (this.state.log === 'B') {
597585
// Right after B commits, schedule additional updates.
598-
// TODO: Double wrapping is temporary while we remove Scheduler runWithPriority.
599586
ReactNoop.unstable_runWithPriority(InputContinuousLanePriority, () =>
600-
Scheduler.unstable_runWithPriority(
601-
Scheduler.unstable_UserBlockingPriority,
602-
() => {
603-
this.pushToLog('C');
604-
},
605-
),
587+
this.pushToLog('C'),
606588
);
607589
this.pushToLog('D');
608590
}
@@ -622,14 +604,8 @@ describe('ReactIncrementalUpdates', () => {
622604

623605
await ReactNoop.act(async () => {
624606
pushToLog('A');
625-
// TODO: Double wrapping is temporary while we remove Scheduler runWithPriority.
626607
ReactNoop.unstable_runWithPriority(InputContinuousLanePriority, () =>
627-
Scheduler.unstable_runWithPriority(
628-
Scheduler.unstable_UserBlockingPriority,
629-
() => {
630-
pushToLog('B');
631-
},
632-
),
608+
pushToLog('B'),
633609
);
634610
});
635611
expect(Scheduler).toHaveYielded([

Diff for: packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.js

+4-16
Original file line numberDiff line numberDiff line change
@@ -1929,10 +1929,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
19291929

19301930
// TODO: assert toErrorDev() when the warning is implemented again.
19311931
ReactNoop.act(() => {
1932-
Scheduler.unstable_runWithPriority(
1933-
Scheduler.unstable_UserBlockingPriority,
1934-
() => _setShow(true),
1935-
);
1932+
ReactNoop.flushSync(() => _setShow(true));
19361933
});
19371934
});
19381935

@@ -1959,10 +1956,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
19591956

19601957
// TODO: assert toErrorDev() when the warning is implemented again.
19611958
ReactNoop.act(() => {
1962-
Scheduler.unstable_runWithPriority(
1963-
Scheduler.unstable_UserBlockingPriority,
1964-
() => show(),
1965-
);
1959+
ReactNoop.flushSync(() => show());
19661960
});
19671961
});
19681962

@@ -1991,10 +1985,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
19911985
expect(ReactNoop).toMatchRenderedOutput('Loading...');
19921986

19931987
ReactNoop.act(() => {
1994-
Scheduler.unstable_runWithPriority(
1995-
Scheduler.unstable_UserBlockingPriority,
1996-
() => showB(),
1997-
);
1988+
ReactNoop.flushSync(() => showB());
19981989
});
19991990

20001991
expect(Scheduler).toHaveYielded(['Suspend! [A]', 'Suspend! [B]']);
@@ -2025,10 +2016,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
20252016

20262017
// TODO: assert toErrorDev() when the warning is implemented again.
20272018
ReactNoop.act(() => {
2028-
Scheduler.unstable_runWithPriority(
2029-
Scheduler.unstable_UserBlockingPriority,
2030-
() => _setShow(true),
2031-
);
2019+
ReactNoop.flushSync(() => _setShow(true));
20322020
});
20332021
},
20342022
);

Diff for: packages/react-reconciler/src/__tests__/useMutableSource-test.internal.js

+10-19
Original file line numberDiff line numberDiff line change
@@ -1476,13 +1476,10 @@ describe('useMutableSource', () => {
14761476
// read during render will happen to match the latest value. But it should
14771477
// still entangle the updates to prevent the previous update (a1) from
14781478
// rendering by itself.
1479-
Scheduler.unstable_runWithPriority(
1480-
Scheduler.unstable_IdlePriority,
1481-
() => {
1482-
mutateA('a0');
1483-
mutateB('b0');
1484-
},
1485-
);
1479+
React.unstable_startTransition(() => {
1480+
mutateA('a0');
1481+
mutateB('b0');
1482+
});
14861483
// Finish the current render
14871484
expect(Scheduler).toFlushUntilNextPaint(['c']);
14881485
// a0 will re-render because of the mutation update. But it should show
@@ -1601,12 +1598,9 @@ describe('useMutableSource', () => {
16011598
// Mutate the config. This is at lower priority so that 1) to make sure
16021599
// it doesn't happen to get batched with the in-progress render, and 2)
16031600
// so it doesn't interrupt the in-progress render.
1604-
Scheduler.unstable_runWithPriority(
1605-
Scheduler.unstable_IdlePriority,
1606-
() => {
1607-
source.valueB = '3';
1608-
},
1609-
);
1601+
React.unstable_startTransition(() => {
1602+
source.valueB = '3';
1603+
});
16101604

16111605
expect(Scheduler).toFlushAndYieldThrough([
16121606
// The partial render completes
@@ -1698,12 +1692,9 @@ describe('useMutableSource', () => {
16981692
expect(source.listenerCount).toBe(1);
16991693

17001694
// Mutate -> schedule update for ComponentA
1701-
Scheduler.unstable_runWithPriority(
1702-
Scheduler.unstable_IdlePriority,
1703-
() => {
1704-
source.value = 'two';
1705-
},
1706-
);
1695+
React.unstable_startTransition(() => {
1696+
source.value = 'two';
1697+
});
17071698

17081699
// Commit ComponentB -> notice the change and schedule an update for ComponentB
17091700
expect(Scheduler).toFlushAndYield(['a:two', 'b:two']);

Diff for: packages/react/src/__tests__/ReactDOMTracing-test.internal.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,8 @@ describe('ReactDOMTracing', () => {
246246
Scheduler.unstable_yieldValue('Child:update');
247247
} else {
248248
Scheduler.unstable_yieldValue('Child:mount');
249-
// TODO: Double wrapping is temporary while we remove Scheduler runWithPriority.
250249
ReactDOM.unstable_runWithPriority(IdleLanePriority, () =>
251-
Scheduler.unstable_runWithPriority(
252-
Scheduler.unstable_IdlePriority,
253-
() => setDidMount(true),
254-
),
250+
setDidMount(true),
255251
);
256252
}
257253
}, [didMount]);

Diff for: packages/react/src/__tests__/ReactProfiler-test.internal.js

+7-9
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,7 @@ describe('Profiler', () => {
748748
expect(onRender.mock.calls[2][1]).toBe('update');
749749
});
750750

751+
// @gate experimental
751752
it('is properly distinguish updates and nested-updates when there is more than sync remaining work', () => {
752753
loadModules({
753754
enableSchedulerTracing,
@@ -767,15 +768,12 @@ describe('Profiler', () => {
767768
const onRender = jest.fn();
768769

769770
// Schedule low-priority work.
770-
Scheduler.unstable_runWithPriority(
771-
Scheduler.unstable_LowPriority,
772-
() => {
773-
ReactNoop.render(
774-
<React.Profiler id="root" onRender={onRender}>
775-
<Component />
776-
</React.Profiler>,
777-
);
778-
},
771+
React.unstable_startTransition(() =>
772+
ReactNoop.render(
773+
<React.Profiler id="root" onRender={onRender}>
774+
<Component />
775+
</React.Profiler>,
776+
),
779777
);
780778

781779
// Flush sync work with a nested update

0 commit comments

Comments
 (0)