@samitouri / QOS-React-2 / commits / 60182d64ca

Cleanup tests using runWithPriority. (#20958)

* Remove Scheduler.runWithPriority from some tests * Mark experimental test experimental

Ricky committed Mar 10, 2021 at 12:44 UTC 60182d64ca030ef28782c7e67be373eac81ae4c2
9 files changed +40 -88
packages/react-dom/src/__tests__/ReactDOMServerPartialHydration-test.internal.js
+6 -1
@@ -18,6 +18,11 @@ let Suspense;
18 let SuspenseList;
19 let act;
20
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 +
26 function dispatchMouseEvent(to, from) {
27 if (!to) {
28 to = null;
@@ -623,7 +628,7 @@ describe('ReactDOMServerPartialHydration', () => {
628 expect(span.textContent).toBe('Hello');
629
630 // Schedule an update at idle priority
626 - Scheduler.unstable_runWithPriority(Scheduler.unstable_IdlePriority, () => {
631 + ReactDOM.unstable_runWithPriority(IdleLanePriority, () => {
632 root.render(<App text="Hi" className="hi" />);
633 });
634
packages/react-dom/src/__tests__/ReactDOMServerSelectiveHydration-test.internal.js
+6 -1
@@ -19,6 +19,11 @@ let Scheduler;
19 let Suspense;
20 let act;
21
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 +
27 function dispatchMouseHoverEvent(to, from) {
28 if (!to) {
29 to = null;
@@ -96,7 +101,7 @@ function dispatchClickEvent(target) {
101 // and there's no native DOM event that maps to idle priority, so this is a
102 // temporary workaround. Need something like ReactDOM.unstable_IdleUpdates.
103 function TODO_scheduleIdleDOMSchedulerTask(fn) {
99 - Scheduler.unstable_runWithPriority(Scheduler.unstable_IdlePriority, () => {
104 + ReactDOM.unstable_runWithPriority(IdleLanePriority, () => {
105 const prevEvent = window.event;
106 window.event = {type: 'message'};
107 try {
packages/react-reconciler/src/__tests__/ReactExpiration-test.js
+1 -5
@@ -550,11 +550,7 @@ describe('ReactExpiration', () => {
550 function App() {
551 const [highPri, setHighPri] = useState(0);
552 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));
554 updateNormalPri = () => setNormalPri(n => n + 1);
555 return (
556 <>
packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.js
+1 -4
@@ -3166,10 +3166,7 @@ describe('ReactHooksWithNoopRenderer', () => {
3166 ]);
3167
3168 await act(async () => {
3169 - Scheduler.unstable_runWithPriority(
3170 - Scheduler.unstable_UserBlockingPriority,
3171 - transition,
3172 - );
3169 + transition();
3170
3171 expect(Scheduler).toFlushAndYield([
3172 'Before... Pending: true',
packages/react-reconciler/src/__tests__/ReactIncrementalUpdates-test.js
+4 -28
@@ -530,14 +530,8 @@ describe('ReactIncrementalUpdates', () => {
530 Scheduler.unstable_yieldValue('Committed: ' + log);
531 if (log === 'B') {
532 // Right after B commits, schedule additional updates.
533 - // TODO: Double wrapping is temporary while we remove Scheduler runWithPriority.
533 ReactNoop.unstable_runWithPriority(InputContinuousLanePriority, () =>
535 - Scheduler.unstable_runWithPriority(
536 - Scheduler.unstable_UserBlockingPriority,
537 - () => {
538 - pushToLog('C');
539 - },
540 - ),
534 + pushToLog('C'),
535 );
536 setLog(prevLog => prevLog + 'D');
537 }
@@ -556,14 +550,8 @@ describe('ReactIncrementalUpdates', () => {
550 await ReactNoop.act(async () => {
551 pushToLog('A');
552
559 - // TODO: Double wrapping is temporary while we remove Scheduler runWithPriority.
553 ReactNoop.unstable_runWithPriority(InputContinuousLanePriority, () =>
561 - Scheduler.unstable_runWithPriority(
562 - Scheduler.unstable_UserBlockingPriority,
563 - () => {
564 - pushToLog('B');
565 - },
566 - ),
554 + pushToLog('B'),
555 );
556 });
557 expect(Scheduler).toHaveYielded([
@@ -595,14 +583,8 @@ describe('ReactIncrementalUpdates', () => {
583 Scheduler.unstable_yieldValue('Committed: ' + this.state.log);
584 if (this.state.log === 'B') {
585 // Right after B commits, schedule additional updates.
598 - // TODO: Double wrapping is temporary while we remove Scheduler runWithPriority.
586 ReactNoop.unstable_runWithPriority(InputContinuousLanePriority, () =>
600 - Scheduler.unstable_runWithPriority(
601 - Scheduler.unstable_UserBlockingPriority,
602 - () => {
603 - this.pushToLog('C');
604 - },
605 - ),
587 + this.pushToLog('C'),
588 );
589 this.pushToLog('D');
590 }
@@ -622,14 +604,8 @@ describe('ReactIncrementalUpdates', () => {
604
605 await ReactNoop.act(async () => {
606 pushToLog('A');
625 - // TODO: Double wrapping is temporary while we remove Scheduler runWithPriority.
607 ReactNoop.unstable_runWithPriority(InputContinuousLanePriority, () =>
627 - Scheduler.unstable_runWithPriority(
628 - Scheduler.unstable_UserBlockingPriority,
629 - () => {
630 - pushToLog('B');
631 - },
632 - ),
608 + pushToLog('B'),
609 );
610 });
611 expect(Scheduler).toHaveYielded([
packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.js
+4 -16
@@ -1929,10 +1929,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
1929
1930 // TODO: assert toErrorDev() when the warning is implemented again.
1931 ReactNoop.act(() => {
1932 - Scheduler.unstable_runWithPriority(
1933 - Scheduler.unstable_UserBlockingPriority,
1934 - () => _setShow(true),
1935 - );
1932 + ReactNoop.flushSync(() => _setShow(true));
1933 });
1934 });
1935
@@ -1959,10 +1956,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
1956
1957 // TODO: assert toErrorDev() when the warning is implemented again.
1958 ReactNoop.act(() => {
1962 - Scheduler.unstable_runWithPriority(
1963 - Scheduler.unstable_UserBlockingPriority,
1964 - () => show(),
1965 - );
1959 + ReactNoop.flushSync(() => show());
1960 });
1961 });
1962
@@ -1991,10 +1985,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
1985 expect(ReactNoop).toMatchRenderedOutput('Loading...');
1986
1987 ReactNoop.act(() => {
1994 - Scheduler.unstable_runWithPriority(
1995 - Scheduler.unstable_UserBlockingPriority,
1996 - () => showB(),
1997 - );
1988 + ReactNoop.flushSync(() => showB());
1989 });
1990
1991 expect(Scheduler).toHaveYielded(['Suspend! [A]', 'Suspend! [B]']);
@@ -2025,10 +2016,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
2016
2017 // TODO: assert toErrorDev() when the warning is implemented again.
2018 ReactNoop.act(() => {
2028 - Scheduler.unstable_runWithPriority(
2029 - Scheduler.unstable_UserBlockingPriority,
2030 - () => _setShow(true),
2031 - );
2019 + ReactNoop.flushSync(() => _setShow(true));
2020 });
2021 },
2022 );
packages/react-reconciler/src/__tests__/useMutableSource-test.internal.js
+10 -19
@@ -1476,13 +1476,10 @@ describe('useMutableSource', () => {
1476 // read during render will happen to match the latest value. But it should
1477 // still entangle the updates to prevent the previous update (a1) from
1478 // 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 + });
1483 // Finish the current render
1484 expect(Scheduler).toFlushUntilNextPaint(['c']);
1485 // a0 will re-render because of the mutation update. But it should show
@@ -1601,12 +1598,9 @@ describe('useMutableSource', () => {
1598 // Mutate the config. This is at lower priority so that 1) to make sure
1599 // it doesn't happen to get batched with the in-progress render, and 2)
1600 // 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 + });
1604
1605 expect(Scheduler).toFlushAndYieldThrough([
1606 // The partial render completes
@@ -1698,12 +1692,9 @@ describe('useMutableSource', () => {
1692 expect(source.listenerCount).toBe(1);
1693
1694 // 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 + });
1698
1699 // Commit ComponentB -> notice the change and schedule an update for ComponentB
1700 expect(Scheduler).toFlushAndYield(['a:two', 'b:two']);
packages/react/src/__tests__/ReactDOMTracing-test.internal.js
+1 -5
@@ -246,12 +246,8 @@ describe('ReactDOMTracing', () => {
246 Scheduler.unstable_yieldValue('Child:update');
247 } else {
248 Scheduler.unstable_yieldValue('Child:mount');
249 - // TODO: Double wrapping is temporary while we remove Scheduler runWithPriority.
249 ReactDOM.unstable_runWithPriority(IdleLanePriority, () =>
251 - Scheduler.unstable_runWithPriority(
252 - Scheduler.unstable_IdlePriority,
253 - () => setDidMount(true),
254 - ),
250 + setDidMount(true),
251 );
252 }
253 }, [didMount]);
packages/react/src/__tests__/ReactProfiler-test.internal.js
+7 -9
@@ -748,6 +748,7 @@ describe('Profiler', () => {
748 expect(onRender.mock.calls[2][1]).toBe('update');
749 });
750
751 + // @gate experimental
752 it('is properly distinguish updates and nested-updates when there is more than sync remaining work', () => {
753 loadModules({
754 enableSchedulerTracing,
@@ -767,15 +768,12 @@ describe('Profiler', () => {
768 const onRender = jest.fn();
769
770 // 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 + ),
777 );
778
779 // Flush sync work with a nested update