From 69060e1da6061af845162dcf6854a5d9af28350a Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Thu, 28 Feb 2019 12:54:47 -0800 Subject: [PATCH] Swap expect(ReactNoop) for expect(Scheduler) (#14971) * Swap expect(ReactNoop) for expect(Scheduler) In the previous commits, I upgraded our custom Jest matchers for the noop and test renderers to use Scheduler under the hood. Now that all these matchers are using Scheduler, we can drop support for passing ReactNoop and test roots and always pass Scheduler directly. * Externalize Scheduler in noop and test bundles I also noticed we don't need to regenerator runtime in noop anymore. --- .../createSubscription-test.internal.js | 58 +-- packages/jest-react/src/JestReact.js | 48 --- .../react-art/src/__tests__/ReactART-test.js | 5 +- .../src/__tests__/ReactCache-test.internal.js | 56 +-- .../ReactExpiration-test.internal.js | 22 +- .../src/__tests__/ReactFragment-test.js | 106 +++--- .../src/__tests__/ReactHooks-test.internal.js | 85 ++--- ...eactHooksWithNoopRenderer-test.internal.js | 346 +++++++++--------- .../ReactIncremental-test.internal.js | 205 ++++++----- ...tIncrementalErrorHandling-test.internal.js | 118 +++--- .../ReactIncrementalErrorLogging-test.js | 10 +- .../ReactIncrementalErrorReplay-test.js | 6 +- .../ReactIncrementalPerf-test.internal.js | 64 ++-- ...eactIncrementalReflection-test.internal.js | 30 +- ...eactIncrementalScheduling-test.internal.js | 38 +- ...actIncrementalSideEffects-test.internal.js | 124 ++++--- .../ReactIncrementalUpdates-test.internal.js | 84 ++--- .../src/__tests__/ReactLazy-test.internal.js | 104 +++--- .../src/__tests__/ReactMemo-test.internal.js | 60 +-- .../ReactNewContext-test.internal.js | 143 ++++---- .../src/__tests__/ReactPersistent-test.js | 20 +- .../__tests__/ReactSuspense-test.internal.js | 150 ++++---- .../ReactSuspensePlaceholder-test.internal.js | 66 ++-- ...tSuspenseWithNoopRenderer-test.internal.js | 180 ++++----- .../__tests__/ReactTopLevelFragment-test.js | 22 +- .../src/__tests__/ReactTopLevelText-test.js | 6 +- .../ReactTestRenderer-test.internal.js | 3 +- .../__tests__/ReactTestRendererAsync-test.js | 56 +-- .../__tests__/ReactProfiler-test.internal.js | 94 +++-- .../src/__tests__/forwardRef-test.internal.js | 18 +- .../react/src/__tests__/forwardRef-test.js | 42 ++- scripts/error-codes/codes.json | 4 +- scripts/jest/matchers/reactTestMatchers.js | 38 +- scripts/rollup/bundles.js | 49 +-- scripts/rollup/modules.js | 1 + 35 files changed, 1184 insertions(+), 1277 deletions(-) diff --git a/packages/create-subscription/src/__tests__/createSubscription-test.internal.js b/packages/create-subscription/src/__tests__/createSubscription-test.internal.js index 39969ac4bd9d4..338b30cfa1087 100644 --- a/packages/create-subscription/src/__tests__/createSubscription-test.internal.js +++ b/packages/create-subscription/src/__tests__/createSubscription-test.internal.js @@ -14,6 +14,7 @@ let BehaviorSubject; let ReactFeatureFlags; let React; let ReactNoop; +let Scheduler; let ReplaySubject; describe('createSubscription', () => { @@ -24,6 +25,7 @@ describe('createSubscription', () => { ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false; React = require('react'); ReactNoop = require('react-noop-renderer'); + Scheduler = require('scheduler'); BehaviorSubject = require('rxjs/BehaviorSubject').BehaviorSubject; ReplaySubject = require('rxjs/ReplaySubject').ReplaySubject; @@ -65,16 +67,16 @@ describe('createSubscription', () => { ); // Updates while subscribed should re-render the child component - expect(ReactNoop).toFlushAndYield(['default']); + expect(Scheduler).toFlushAndYield(['default']); observable.next(123); - expect(ReactNoop).toFlushAndYield([123]); + expect(Scheduler).toFlushAndYield([123]); observable.next('abc'); - expect(ReactNoop).toFlushAndYield(['abc']); + expect(Scheduler).toFlushAndYield(['abc']); // Unmounting the subscriber should remove listeners ReactNoop.render(
); observable.next(456); - expect(ReactNoop).toFlushAndYield([]); + expect(Scheduler).toFlushAndYield([]); }); it('should support observable types like RxJS ReplaySubject', () => { @@ -102,13 +104,13 @@ describe('createSubscription', () => { const observable = createReplaySubject('initial'); ReactNoop.render({render}); - expect(ReactNoop).toFlushAndYield(['initial']); + expect(Scheduler).toFlushAndYield(['initial']); observable.next('updated'); - expect(ReactNoop).toFlushAndYield(['updated']); + expect(Scheduler).toFlushAndYield(['updated']); // Unsetting the subscriber prop should reset subscribed values ReactNoop.render({render}); - expect(ReactNoop).toFlushAndYield(['default']); + expect(Scheduler).toFlushAndYield(['default']); }); describe('Promises', () => { @@ -141,19 +143,19 @@ describe('createSubscription', () => { // Test a promise that resolves after render ReactNoop.render({render}); - expect(ReactNoop).toFlushAndYield(['loading']); + expect(Scheduler).toFlushAndYield(['loading']); resolveA(true); await promiseA; - expect(ReactNoop).toFlushAndYield(['finished']); + expect(Scheduler).toFlushAndYield(['finished']); // Test a promise that resolves before render // Note that this will require an extra render anyway, // Because there is no way to synchronously get a Promise's value rejectB(false); ReactNoop.render({render}); - expect(ReactNoop).toFlushAndYield(['loading']); + expect(Scheduler).toFlushAndYield(['loading']); await promiseB.catch(() => true); - expect(ReactNoop).toFlushAndYield(['failed']); + expect(Scheduler).toFlushAndYield(['failed']); }); it('should still work if unsubscription is managed incorrectly', async () => { @@ -177,9 +179,9 @@ describe('createSubscription', () => { // Subscribe first to Promise A then Promise B ReactNoop.render({render}); - expect(ReactNoop).toFlushAndYield(['default']); + expect(Scheduler).toFlushAndYield(['default']); ReactNoop.render({render}); - expect(ReactNoop).toFlushAndYield(['default']); + expect(Scheduler).toFlushAndYield(['default']); // Resolve both Promises resolveB(123); @@ -187,7 +189,7 @@ describe('createSubscription', () => { await Promise.all([promiseA, promiseB]); // Ensure that only Promise B causes an update - expect(ReactNoop).toFlushAndYield([123]); + expect(Scheduler).toFlushAndYield([123]); }); it('should not call setState for a Promise that resolves after unmount', async () => { @@ -211,11 +213,11 @@ describe('createSubscription', () => { }); ReactNoop.render({render}); - expect(ReactNoop).toFlushAndYield(['rendered']); + expect(Scheduler).toFlushAndYield(['rendered']); // Unmount ReactNoop.render(null); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); // Resolve Promise should not trigger a setState warning resolvePromise(true); @@ -245,21 +247,21 @@ describe('createSubscription', () => { ); // Updates while subscribed should re-render the child component - expect(ReactNoop).toFlushAndYield(['a-0']); + expect(Scheduler).toFlushAndYield(['a-0']); // Unsetting the subscriber prop should reset subscribed values ReactNoop.render( {render}, ); - expect(ReactNoop).toFlushAndYield(['b-0']); + expect(Scheduler).toFlushAndYield(['b-0']); // Updates to the old subscribable should not re-render the child component observableA.next('a-1'); - expect(ReactNoop).toFlushAndYield([]); + expect(Scheduler).toFlushAndYield([]); // Updates to the bew subscribable should re-render the child component observableB.next('b-1'); - expect(ReactNoop).toFlushAndYield(['b-1']); + expect(Scheduler).toFlushAndYield(['b-1']); }); it('should ignore values emitted by a new subscribable until the commit phase', () => { @@ -315,12 +317,12 @@ describe('createSubscription', () => { const observableB = createBehaviorSubject('b-0'); ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['Subscriber: a-0', 'Child: a-0']); + expect(Scheduler).toFlushAndYield(['Subscriber: a-0', 'Child: a-0']); expect(log).toEqual(['Parent.componentDidMount']); // Start React update, but don't finish ReactNoop.render(); - expect(ReactNoop).toFlushAndYieldThrough(['Subscriber: b-0']); + expect(Scheduler).toFlushAndYieldThrough(['Subscriber: b-0']); expect(log).toEqual(['Parent.componentDidMount']); // Emit some updates from the uncommitted subscribable @@ -335,7 +337,7 @@ describe('createSubscription', () => { // We expect the last emitted update to be rendered (because of the commit phase value check) // But the intermediate ones should be ignored, // And the final rendered output should be the higher-priority observable. - expect(ReactNoop).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ 'Child: b-0', 'Subscriber: b-3', 'Child: b-3', @@ -402,12 +404,12 @@ describe('createSubscription', () => { const observableB = createBehaviorSubject('b-0'); ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['Subscriber: a-0', 'Child: a-0']); + expect(Scheduler).toFlushAndYield(['Subscriber: a-0', 'Child: a-0']); expect(log).toEqual(['Parent.componentDidMount']); // Start React update, but don't finish ReactNoop.render(); - expect(ReactNoop).toFlushAndYieldThrough(['Subscriber: b-0']); + expect(Scheduler).toFlushAndYieldThrough(['Subscriber: b-0']); expect(log).toEqual(['Parent.componentDidMount']); // Emit some updates from the old subscribable @@ -420,7 +422,7 @@ describe('createSubscription', () => { // Flush everything and ensure that the correct subscribable is used // We expect the new subscribable to finish rendering, // But then the updated values from the old subscribable should be used. - expect(ReactNoop).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ 'Child: b-0', 'Subscriber: a-2', 'Child: a-2', @@ -433,7 +435,7 @@ describe('createSubscription', () => { // Updates from the new subscribable should be ignored. observableB.next('b-1'); - expect(ReactNoop).toFlushAndYield([]); + expect(Scheduler).toFlushAndYield([]); expect(log).toEqual([ 'Parent.componentDidMount', 'Parent.componentDidUpdate', @@ -479,7 +481,7 @@ describe('createSubscription', () => { {value => null}, ); - expect(ReactNoop).toFlushAndThrow( + expect(Scheduler).toFlushAndThrow( 'A subscription must return an unsubscribe function.', ); }); diff --git a/packages/jest-react/src/JestReact.js b/packages/jest-react/src/JestReact.js index af228abdbd874..26d116a7f97a8 100644 --- a/packages/jest-react/src/JestReact.js +++ b/packages/jest-react/src/JestReact.js @@ -35,54 +35,6 @@ function assertYieldsWereCleared(root) { ); } -export function unstable_toFlushAndYield(root, expectedYields) { - assertYieldsWereCleared(root); - const actualYields = root.unstable_flushAll(); - return captureAssertion(() => { - expect(actualYields).toEqual(expectedYields); - }); -} - -export function unstable_toFlushAndYieldThrough(root, expectedYields) { - assertYieldsWereCleared(root); - const actualYields = root.unstable_flushNumberOfYields(expectedYields.length); - return captureAssertion(() => { - expect(actualYields).toEqual(expectedYields); - }); -} - -export function unstable_toFlushWithoutYielding(root) { - return unstable_toFlushAndYield(root, []); -} - -export function unstable_toHaveYielded(ReactTestRenderer, expectedYields) { - return captureAssertion(() => { - if ( - ReactTestRenderer === null || - typeof ReactTestRenderer !== 'object' || - typeof ReactTestRenderer.unstable_setNowImplementation !== 'function' - ) { - invariant( - false, - 'The matcher `unstable_toHaveYielded` expects an instance of React Test ' + - 'Renderer.\n\nTry: ' + - 'expect(ReactTestRenderer).unstable_toHaveYielded(expectedYields)', - ); - } - const actualYields = ReactTestRenderer.unstable_clearYields(); - expect(actualYields).toEqual(expectedYields); - }); -} - -export function unstable_toFlushAndThrow(root, ...rest) { - assertYieldsWereCleared(root); - return captureAssertion(() => { - expect(() => { - root.unstable_flushAll(); - }).toThrow(...rest); - }); -} - export function unstable_toMatchRenderedOutput(root, expectedJSX) { assertYieldsWereCleared(root); const actualJSON = root.toJSON(); diff --git a/packages/react-art/src/__tests__/ReactART-test.js b/packages/react-art/src/__tests__/ReactART-test.js index f7115c556c0d5..90ff5927adb18 100644 --- a/packages/react-art/src/__tests__/ReactART-test.js +++ b/packages/react-art/src/__tests__/ReactART-test.js @@ -31,6 +31,7 @@ const Wedge = require('react-art/Wedge'); // Isolate the noop renderer jest.resetModules(); const ReactNoop = require('react-noop-renderer'); +const Scheduler = require('scheduler'); let Group; let Shape; @@ -385,7 +386,7 @@ describe('ReactART', () => { , ); - expect(ReactNoop).toFlushAndYieldThrough(['A']); + expect(Scheduler).toFlushAndYieldThrough(['A']); ReactDOM.render( @@ -400,7 +401,7 @@ describe('ReactART', () => { expect(ops).toEqual([null, 'ART']); ops = []; - expect(ReactNoop).toFlushAndYield(['B', 'C']); + expect(Scheduler).toFlushAndYield(['B', 'C']); expect(ops).toEqual(['Test']); }); diff --git a/packages/react-cache/src/__tests__/ReactCache-test.internal.js b/packages/react-cache/src/__tests__/ReactCache-test.internal.js index 4532602dd5314..f8a599b360dcd 100644 --- a/packages/react-cache/src/__tests__/ReactCache-test.internal.js +++ b/packages/react-cache/src/__tests__/ReactCache-test.internal.js @@ -107,15 +107,15 @@ describe('ReactCache', () => { ); } - const root = ReactTestRenderer.create(, { + ReactTestRenderer.create(, { unstable_isConcurrent: true, }); - expect(root).toFlushAndYield(['Suspend! [Hi]', 'Loading...']); + expect(Scheduler).toFlushAndYield(['Suspend! [Hi]', 'Loading...']); jest.advanceTimersByTime(100); - expect(ReactTestRenderer).toHaveYielded(['Promise resolved [Hi]']); - expect(root).toFlushAndYield(['Hi']); + expect(Scheduler).toHaveYielded(['Promise resolved [Hi]']); + expect(Scheduler).toFlushAndYield(['Hi']); }); it('throws an error on the subsequent read if the promise is rejected', async () => { @@ -131,19 +131,19 @@ describe('ReactCache', () => { unstable_isConcurrent: true, }); - expect(root).toFlushAndYield(['Suspend! [Hi]', 'Loading...']); + expect(Scheduler).toFlushAndYield(['Suspend! [Hi]', 'Loading...']); textResourceShouldFail = true; jest.advanceTimersByTime(100); - expect(ReactTestRenderer).toHaveYielded(['Promise rejected [Hi]']); + expect(Scheduler).toHaveYielded(['Promise rejected [Hi]']); - expect(root).toFlushAndThrow('Failed to load: Hi'); - expect(ReactTestRenderer).toHaveYielded(['Error! [Hi]', 'Error! [Hi]']); + expect(Scheduler).toFlushAndThrow('Failed to load: Hi'); + expect(Scheduler).toHaveYielded(['Error! [Hi]', 'Error! [Hi]']); // Should throw again on a subsequent read root.update(); - expect(root).toFlushAndThrow('Failed to load: Hi'); - expect(ReactTestRenderer).toHaveYielded(['Error! [Hi]', 'Error! [Hi]']); + expect(Scheduler).toFlushAndThrow('Failed to load: Hi'); + expect(Scheduler).toHaveYielded(['Error! [Hi]', 'Error! [Hi]']); }); it('warns if non-primitive key is passed to a resource without a hash function', () => { @@ -160,7 +160,7 @@ describe('ReactCache', () => { return BadTextResource.read(['Hi', 100]); } - const root = ReactTestRenderer.create( + ReactTestRenderer.create( }> , @@ -171,7 +171,7 @@ describe('ReactCache', () => { if (__DEV__) { expect(() => { - expect(root).toFlushAndYield(['App', 'Loading...']); + expect(Scheduler).toFlushAndYield(['App', 'Loading...']); }).toWarnDev( [ 'Invalid key type. Expected a string, number, symbol, or ' + @@ -182,7 +182,7 @@ describe('ReactCache', () => { {withoutStack: true}, ); } else { - expect(root).toFlushAndYield(['App', 'Loading...']); + expect(Scheduler).toFlushAndYield(['App', 'Loading...']); } }); @@ -200,19 +200,19 @@ describe('ReactCache', () => { unstable_isConcurrent: true, }, ); - expect(root).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ 'Suspend! [1]', 'Suspend! [2]', 'Suspend! [3]', 'Loading...', ]); jest.advanceTimersByTime(100); - expect(ReactTestRenderer).toHaveYielded([ + expect(Scheduler).toHaveYielded([ 'Promise resolved [1]', 'Promise resolved [2]', 'Promise resolved [3]', ]); - expect(root).toFlushAndYield([1, 2, 3]); + expect(Scheduler).toFlushAndYield([1, 2, 3]); expect(root).toMatchRenderedOutput('123'); // Render 1, 4, 5 @@ -224,18 +224,18 @@ describe('ReactCache', () => { , ); - expect(root).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ 1, 'Suspend! [4]', 'Suspend! [5]', 'Loading...', ]); jest.advanceTimersByTime(100); - expect(ReactTestRenderer).toHaveYielded([ + expect(Scheduler).toHaveYielded([ 'Promise resolved [4]', 'Promise resolved [5]', ]); - expect(root).toFlushAndYield([1, 4, 5]); + expect(Scheduler).toFlushAndYield([1, 4, 5]); expect(root).toMatchRenderedOutput('145'); // We've now rendered values 1, 2, 3, 4, 5, over our limit of 3. The least @@ -249,7 +249,7 @@ describe('ReactCache', () => { , ); - expect(root).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ // 1 is still cached 1, // 2 and 3 suspend because they were evicted from the cache @@ -258,11 +258,11 @@ describe('ReactCache', () => { 'Loading...', ]); jest.advanceTimersByTime(100); - expect(ReactTestRenderer).toHaveYielded([ + expect(Scheduler).toHaveYielded([ 'Promise resolved [2]', 'Promise resolved [3]', ]); - expect(root).toFlushAndYield([1, 2, 3]); + expect(Scheduler).toFlushAndYield([1, 2, 3]); expect(root).toMatchRenderedOutput('123'); }); @@ -283,14 +283,14 @@ describe('ReactCache', () => { }, ); - expect(root).toFlushAndYield(['Loading...']); + expect(Scheduler).toFlushAndYield(['Loading...']); jest.advanceTimersByTime(1000); - expect(ReactTestRenderer).toHaveYielded([ + expect(Scheduler).toHaveYielded([ 'Promise resolved [B]', 'Promise resolved [A]', ]); - expect(root).toFlushAndYield(['Result']); + expect(Scheduler).toFlushAndYield(['Result']); expect(root).toMatchRenderedOutput('Result'); }); @@ -342,7 +342,7 @@ describe('ReactCache', () => { }, ); - expect(root).toFlushAndYield(['Suspend! [Hi]', 'Loading...']); + expect(Scheduler).toFlushAndYield(['Suspend! [Hi]', 'Loading...']); resolveThenable('Hi'); // This thenable improperly resolves twice. We should not update the @@ -358,8 +358,8 @@ describe('ReactCache', () => { }, ); - expect(ReactTestRenderer).toHaveYielded([]); - expect(root).toFlushAndYield(['Hi']); + expect(Scheduler).toHaveYielded([]); + expect(Scheduler).toFlushAndYield(['Hi']); expect(root).toMatchRenderedOutput('Hi'); }); diff --git a/packages/react-reconciler/src/__tests__/ReactExpiration-test.internal.js b/packages/react-reconciler/src/__tests__/ReactExpiration-test.internal.js index b69592a0c7c64..6d7104638895c 100644 --- a/packages/react-reconciler/src/__tests__/ReactExpiration-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactExpiration-test.internal.js @@ -74,7 +74,7 @@ describe('ReactExpiration', () => { // Advance the timer. Scheduler.advanceTime(2000); // Partially flush the the first update, then interrupt it. - expect(ReactNoop).toFlushAndYieldThrough(['A [render]']); + expect(Scheduler).toFlushAndYieldThrough(['A [render]']); interrupt(); // Don't advance time by enough to expire the first update. @@ -89,7 +89,7 @@ describe('ReactExpiration', () => { // batch these two updates together. The fact that they aren't batched // is an implementation detail. The important part of this unit test is that // they are batched if it's possible that they happened in the same event. - expect(ReactNoop).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ 'A [render]', 'A [commit]', 'B [render]', @@ -101,13 +101,13 @@ describe('ReactExpiration', () => { // between the two updates. ReactNoop.render(); Scheduler.advanceTime(2000); - expect(ReactNoop).toHaveYielded([]); + expect(Scheduler).toHaveYielded([]); expect(ReactNoop.getChildren()).toEqual([span('B')]); // Schedule another update. ReactNoop.render(); // The updates should flush in the same batch, since as far as the scheduler // knows, they may have occurred inside the same event. - expect(ReactNoop).toFlushAndYield(['B [render]', 'B [commit]']); + expect(Scheduler).toFlushAndYield(['B [render]', 'B [commit]']); }); it( @@ -139,7 +139,7 @@ describe('ReactExpiration', () => { // Advance the timer. Scheduler.advanceTime(2000); // Partially flush the the first update, then interrupt it. - expect(ReactNoop).toFlushAndYieldThrough(['A [render]']); + expect(Scheduler).toFlushAndYieldThrough(['A [render]']); interrupt(); // Don't advance time by enough to expire the first update. @@ -154,7 +154,7 @@ describe('ReactExpiration', () => { // batch these two updates together. The fact that they aren't batched // is an implementation detail. The important part of this unit test is that // they are batched if it's possible that they happened in the same event. - expect(ReactNoop).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ 'A [render]', 'A [commit]', 'B [render]', @@ -166,7 +166,7 @@ describe('ReactExpiration', () => { // between the two updates. ReactNoop.render(); Scheduler.advanceTime(2000); - expect(ReactNoop).toHaveYielded([]); + expect(Scheduler).toHaveYielded([]); expect(ReactNoop.getChildren()).toEqual([span('B')]); // Perform some synchronous work. The scheduler must assume we're inside @@ -177,7 +177,7 @@ describe('ReactExpiration', () => { ReactNoop.render(); // The updates should flush in the same batch, since as far as the scheduler // knows, they may have occurred inside the same event. - expect(ReactNoop).toFlushAndYield(['B [render]', 'B [commit]']); + expect(Scheduler).toFlushAndYield(['B [render]', 'B [commit]']); }, ); @@ -212,7 +212,7 @@ describe('ReactExpiration', () => { // Initial mount ReactNoop.render(); - expect(ReactNoop).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ 'initial [A] [render]', 'initial [B] [render]', 'initial [C] [render]', @@ -225,7 +225,7 @@ describe('ReactExpiration', () => { // Partial update subscribers.forEach(s => s.setState({text: '1'})); - expect(ReactNoop).toFlushAndYieldThrough([ + expect(Scheduler).toFlushAndYieldThrough([ '1 [A] [render]', '1 [B] [render]', ]); @@ -234,7 +234,7 @@ describe('ReactExpiration', () => { // advanced, this update should be given a different expiration time than // the currently rendering one. So, C and D should render with 1, not 2. subscribers.forEach(s => s.setState({text: '2'})); - expect(ReactNoop).toFlushAndYieldThrough([ + expect(Scheduler).toFlushAndYieldThrough([ '1 [C] [render]', '1 [D] [render]', ]); diff --git a/packages/react-reconciler/src/__tests__/ReactFragment-test.js b/packages/react-reconciler/src/__tests__/ReactFragment-test.js index c72b395eb27c3..5b6030da64cb6 100644 --- a/packages/react-reconciler/src/__tests__/ReactFragment-test.js +++ b/packages/react-reconciler/src/__tests__/ReactFragment-test.js @@ -11,6 +11,7 @@ let React; let ReactNoop; +let Scheduler; describe('ReactFragment', () => { beforeEach(function() { @@ -18,6 +19,7 @@ describe('ReactFragment', () => { React = require('react'); ReactNoop = require('react-noop-renderer'); + Scheduler = require('scheduler'); }); function div(...children) { @@ -43,7 +45,7 @@ describe('ReactFragment', () => { ); ReactNoop.render(element); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren()).toEqual([span()]); }); @@ -52,7 +54,7 @@ describe('ReactFragment', () => { const element = ; ReactNoop.render(element); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren()).toEqual([]); }); @@ -65,7 +67,7 @@ describe('ReactFragment', () => { ); ReactNoop.render(element); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren()).toEqual([text('hello '), span()]); }); @@ -78,7 +80,7 @@ describe('ReactFragment', () => { ); ReactNoop.render(element); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren()).toEqual([span(), span()]); }); @@ -108,16 +110,16 @@ describe('ReactFragment', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual(['Update Stateful']); expect(ReactNoop.getChildren()).toEqual([div(), div()]); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual(['Update Stateful', 'Update Stateful']); expect(ReactNoop.getChildren()).toEqual([div()]); @@ -149,16 +151,16 @@ describe('ReactFragment', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual(['Update Stateful']); expect(ReactNoop.getChildren()).toEqual([div()]); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual(['Update Stateful', 'Update Stateful']); expect(ReactNoop.getChildren()).toEqual([div()]); @@ -199,16 +201,16 @@ describe('ReactFragment', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual(['Update Stateful']); expect(ReactNoop.getChildren()).toEqual([div(), div()]); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual(['Update Stateful', 'Update Stateful']); expect(ReactNoop.getChildren()).toEqual([div()]); @@ -242,16 +244,16 @@ describe('ReactFragment', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual([]); expect(ReactNoop.getChildren()).toEqual([div()]); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual([]); expect(ReactNoop.getChildren()).toEqual([div()]); @@ -283,16 +285,16 @@ describe('ReactFragment', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual([]); expect(ReactNoop.getChildren()).toEqual([div()]); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual([]); expect(ReactNoop.getChildren()).toEqual([div()]); @@ -325,16 +327,16 @@ describe('ReactFragment', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual([]); expect(ReactNoop.getChildren()).toEqual([div(), div()]); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual([]); expect(ReactNoop.getChildren()).toEqual([div()]); @@ -364,16 +366,16 @@ describe('ReactFragment', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual(['Update Stateful']); expect(ReactNoop.getChildren()).toEqual([div()]); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual(['Update Stateful', 'Update Stateful']); expect(ReactNoop.getChildren()).toEqual([div()]); @@ -403,16 +405,16 @@ describe('ReactFragment', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual(['Update Stateful']); expect(ReactNoop.getChildren()).toEqual([div()]); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual(['Update Stateful', 'Update Stateful']); expect(ReactNoop.getChildren()).toEqual([div()]); @@ -444,16 +446,16 @@ describe('ReactFragment', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual([]); expect(ReactNoop.getChildren()).toEqual([div()]); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual([]); expect(ReactNoop.getChildren()).toEqual([div()]); @@ -481,16 +483,16 @@ describe('ReactFragment', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual([]); expect(ReactNoop.getChildren()).toEqual([div()]); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual([]); expect(ReactNoop.getChildren()).toEqual([div()]); @@ -522,16 +524,16 @@ describe('ReactFragment', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual(['Update Stateful']); expect(ReactNoop.getChildren()).toEqual([div()]); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual(['Update Stateful', 'Update Stateful']); expect(ReactNoop.getChildren()).toEqual([div()]); @@ -564,16 +566,16 @@ describe('ReactFragment', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual([]); expect(ReactNoop.getChildren()).toEqual([div(), span()]); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual([]); expect(ReactNoop.getChildren()).toEqual([div()]); @@ -605,16 +607,16 @@ describe('ReactFragment', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual([]); expect(ReactNoop.getChildren()).toEqual([div()]); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual([]); expect(ReactNoop.getChildren()).toEqual([div()]); @@ -658,16 +660,16 @@ describe('ReactFragment', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual(['Update Stateful']); expect(ReactNoop.getChildren()).toEqual([div(span(), div(div()), span())]); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual(['Update Stateful', 'Update Stateful']); expect(ReactNoop.getChildren()).toEqual([div(span(), div(div()), span())]); @@ -705,10 +707,10 @@ describe('ReactFragment', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); ReactNoop.render(); - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev( + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev( 'Each child in a list should have a unique "key" prop.', ); @@ -716,7 +718,7 @@ describe('ReactFragment', () => { expect(ReactNoop.getChildren()).toEqual([div(div(), span())]); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual([]); expect(ReactNoop.getChildren()).toEqual([div(div(), span())]); @@ -752,12 +754,12 @@ describe('ReactFragment', () => { } ReactNoop.render(); - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev( + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev( 'Each child in a list should have a unique "key" prop.', ); ReactNoop.render(); - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev( + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev( 'Each child in a list should have a unique "key" prop.', ); @@ -765,7 +767,7 @@ describe('ReactFragment', () => { expect(ReactNoop.getChildren()).toEqual([span(), div()]); ReactNoop.render(); - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev( + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev( 'Each child in a list should have a unique "key" prop.', ); diff --git a/packages/react-reconciler/src/__tests__/ReactHooks-test.internal.js b/packages/react-reconciler/src/__tests__/ReactHooks-test.internal.js index b88676e77baaf..b960406504925 100644 --- a/packages/react-reconciler/src/__tests__/ReactHooks-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactHooks-test.internal.js @@ -77,7 +77,7 @@ describe('ReactHooks', () => { const root = ReactTestRenderer.create(null, {unstable_isConcurrent: true}); root.update(); - expect(root).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ 'Parent: 0, 0', 'Child: 0, 0', 'Effect: 0, 0', @@ -90,7 +90,7 @@ describe('ReactHooks', () => { setCounter2(1); }); - expect(root).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ 'Parent: 1, 1', 'Child: 1, 1', 'Effect: 1, 1', @@ -98,7 +98,7 @@ describe('ReactHooks', () => { // Update that bails out. act(() => setCounter1(1)); - expect(root).toFlushAndYield(['Parent: 1, 1']); + expect(Scheduler).toFlushAndYield(['Parent: 1, 1']); // This time, one of the state updates but the other one doesn't. So we // can't bail out. @@ -107,7 +107,7 @@ describe('ReactHooks', () => { setCounter2(2); }); - expect(root).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ 'Parent: 1, 2', 'Child: 1, 2', 'Effect: 1, 2', @@ -125,14 +125,14 @@ describe('ReactHooks', () => { // Because the final values are the same as the current values, the // component bails out. - expect(root).toFlushAndYield(['Parent: 1, 2']); + expect(Scheduler).toFlushAndYield(['Parent: 1, 2']); // prepare to check SameValue act(() => { setCounter1(0 / -1); setCounter2(NaN); }); - expect(root).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ 'Parent: 0, NaN', 'Child: 0, NaN', 'Effect: 0, NaN', @@ -146,13 +146,13 @@ describe('ReactHooks', () => { setCounter2(NaN); }); - expect(root).toFlushAndYield(['Parent: 0, NaN']); + expect(Scheduler).toFlushAndYield(['Parent: 0, NaN']); // check if changing negative 0 to positive 0 does not bail out act(() => { setCounter1(0); }); - expect(root).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ 'Parent: 0, NaN', 'Child: 0, NaN', 'Effect: 0, NaN', @@ -184,7 +184,7 @@ describe('ReactHooks', () => { const root = ReactTestRenderer.create(null, {unstable_isConcurrent: true}); root.update(); - expect(root).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ 'Parent: 0, 0 (light)', 'Child: 0, 0 (light)', ]); @@ -196,14 +196,14 @@ describe('ReactHooks', () => { setCounter2(1); }); - expect(root).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ 'Parent: 1, 1 (light)', 'Child: 1, 1 (light)', ]); // Update that bails out. act(() => setCounter1(1)); - expect(root).toFlushAndYield(['Parent: 1, 1 (light)']); + expect(Scheduler).toFlushAndYield(['Parent: 1, 1 (light)']); // This time, one of the state updates but the other one doesn't. So we // can't bail out. @@ -212,7 +212,7 @@ describe('ReactHooks', () => { setCounter2(2); }); - expect(root).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ 'Parent: 1, 2 (light)', 'Child: 1, 2 (light)', ]); @@ -225,7 +225,10 @@ describe('ReactHooks', () => { }); root.update(); - expect(root).toFlushAndYield(['Parent: 1, 2 (dark)', 'Child: 1, 2 (dark)']); + expect(Scheduler).toFlushAndYield([ + 'Parent: 1, 2 (dark)', + 'Child: 1, 2 (dark)', + ]); // Both props and state bail out act(() => { @@ -234,7 +237,7 @@ describe('ReactHooks', () => { }); root.update(); - expect(root).toFlushAndYield(['Parent: 1, 2 (dark)']); + expect(Scheduler).toFlushAndYield(['Parent: 1, 2 (dark)']); }); it('warns about setState second argument', () => { @@ -251,7 +254,7 @@ describe('ReactHooks', () => { const root = ReactTestRenderer.create(null, {unstable_isConcurrent: true}); root.update(); - expect(root).toFlushAndYield(['Count: 0']); + expect(Scheduler).toFlushAndYield(['Count: 0']); expect(root).toMatchRenderedOutput('0'); expect(() => { @@ -267,7 +270,7 @@ describe('ReactHooks', () => { 'declare it in the component body with useEffect().', {withoutStack: true}, ); - expect(root).toFlushAndYield(['Count: 1']); + expect(Scheduler).toFlushAndYield(['Count: 1']); expect(root).toMatchRenderedOutput('1'); }); @@ -285,7 +288,7 @@ describe('ReactHooks', () => { const root = ReactTestRenderer.create(null, {unstable_isConcurrent: true}); root.update(); - expect(root).toFlushAndYield(['Count: 0']); + expect(Scheduler).toFlushAndYield(['Count: 0']); expect(root).toMatchRenderedOutput('0'); expect(() => { @@ -301,7 +304,7 @@ describe('ReactHooks', () => { 'declare it in the component body with useEffect().', {withoutStack: true}, ); - expect(root).toFlushAndYield(['Count: 1']); + expect(Scheduler).toFlushAndYield(['Count: 1']); expect(root).toMatchRenderedOutput('1'); }); @@ -346,7 +349,7 @@ describe('ReactHooks', () => { , ); - expect(root).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ 'Theme: light', 'Parent: 0 (light)', 'Child: 0 (light)', @@ -357,12 +360,12 @@ describe('ReactHooks', () => { // Updating the theme to the same value doesn't cause the consumers // to re-render. setTheme('light'); - expect(root).toFlushAndYield([]); + expect(Scheduler).toFlushAndYield([]); expect(root).toMatchRenderedOutput('0 (light)'); // Normal update act(() => setCounter(1)); - expect(root).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ 'Parent: 1 (light)', 'Child: 1 (light)', 'Effect: 1 (light)', @@ -371,7 +374,7 @@ describe('ReactHooks', () => { // Update that doesn't change state, so it bails out act(() => setCounter(1)); - expect(root).toFlushAndYield(['Parent: 1 (light)']); + expect(Scheduler).toFlushAndYield(['Parent: 1 (light)']); expect(root).toMatchRenderedOutput('1 (light)'); // Update that doesn't change state, but the context changes, too, so it @@ -381,7 +384,7 @@ describe('ReactHooks', () => { setTheme('dark'); }); - expect(root).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ 'Theme: dark', 'Parent: 1 (dark)', 'Child: 1 (dark)', @@ -411,12 +414,12 @@ describe('ReactHooks', () => { const root = ReactTestRenderer.create(null, {unstable_isConcurrent: true}); root.update(); - expect(root).toFlushAndYield(['Parent: 0', 'Child: 0', 'Effect: 0']); + expect(Scheduler).toFlushAndYield(['Parent: 0', 'Child: 0', 'Effect: 0']); expect(root).toMatchRenderedOutput('0'); // Normal update act(() => setCounter(1)); - expect(root).toFlushAndYield(['Parent: 1', 'Child: 1', 'Effect: 1']); + expect(Scheduler).toFlushAndYield(['Parent: 1', 'Child: 1', 'Effect: 1']); expect(root).toMatchRenderedOutput('1'); // Update to the same state. React doesn't know if the queue is empty @@ -424,25 +427,25 @@ describe('ReactHooks', () => { // enter the render phase before we can bail out. But we bail out before // rendering the child, and we don't fire any effects. act(() => setCounter(1)); - expect(root).toFlushAndYield(['Parent: 1']); + expect(Scheduler).toFlushAndYield(['Parent: 1']); expect(root).toMatchRenderedOutput('1'); // Update to the same state again. This times, neither fiber has pending // update priority, so we can bail out before even entering the render phase. act(() => setCounter(1)); - expect(root).toFlushAndYield([]); + expect(Scheduler).toFlushAndYield([]); expect(root).toMatchRenderedOutput('1'); // This changes the state to something different so it renders normally. act(() => setCounter(2)); - expect(root).toFlushAndYield(['Parent: 2', 'Child: 2', 'Effect: 2']); + expect(Scheduler).toFlushAndYield(['Parent: 2', 'Child: 2', 'Effect: 2']); expect(root).toMatchRenderedOutput('2'); // prepare to check SameValue act(() => { setCounter(0); }); - expect(root).toFlushAndYield(['Parent: 0', 'Child: 0', 'Effect: 0']); + expect(Scheduler).toFlushAndYield(['Parent: 0', 'Child: 0', 'Effect: 0']); expect(root).toMatchRenderedOutput('0'); // Update to the same state for the first time to flush the queue @@ -450,21 +453,21 @@ describe('ReactHooks', () => { setCounter(0); }); - expect(root).toFlushAndYield(['Parent: 0']); + expect(Scheduler).toFlushAndYield(['Parent: 0']); expect(root).toMatchRenderedOutput('0'); // Update again to the same state. Should bail out. act(() => { setCounter(0); }); - expect(root).toFlushAndYield([]); + expect(Scheduler).toFlushAndYield([]); expect(root).toMatchRenderedOutput('0'); // Update to a different state (positive 0 to negative 0) act(() => { setCounter(0 / -1); }); - expect(root).toFlushAndYield(['Parent: 0', 'Child: 0', 'Effect: 0']); + expect(Scheduler).toFlushAndYield(['Parent: 0', 'Child: 0', 'Effect: 0']); expect(root).toMatchRenderedOutput('0'); }); @@ -486,7 +489,7 @@ describe('ReactHooks', () => { const root = ReactTestRenderer.create(null, {unstable_isConcurrent: true}); root.update(); - expect(root).toFlushAndYield(['Parent: 0', 'Child: 0']); + expect(Scheduler).toFlushAndYield(['Parent: 0', 'Child: 0']); expect(root).toMatchRenderedOutput('0'); const update = value => { @@ -504,7 +507,7 @@ describe('ReactHooks', () => { update(3); }); - expect(ReactTestRenderer).toHaveYielded([ + expect(Scheduler).toHaveYielded([ // The first four updates were eagerly computed, because the queue is // empty before each one. 'Compute state (0 -> 0)', @@ -516,7 +519,7 @@ describe('ReactHooks', () => { ]); // Now let's enter the render phase - expect(root).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ // We don't need to re-compute the first four updates. Only the final two. 'Compute state (1 -> 2)', 'Compute state (2 -> 3)', @@ -544,7 +547,7 @@ describe('ReactHooks', () => { const root = ReactTestRenderer.create(null, {unstable_isConcurrent: true}); root.update(); - expect(root).toFlushAndYield(['Parent: 1', 'Child: 1']); + expect(Scheduler).toFlushAndYield(['Parent: 1', 'Child: 1']); expect(root).toMatchRenderedOutput('1'); const update = compute => { @@ -559,13 +562,13 @@ describe('ReactHooks', () => { act(() => update(n => n * 100)); // The new state is eagerly computed. - expect(ReactTestRenderer).toHaveYielded(['Compute state (1 -> 100)']); + expect(Scheduler).toHaveYielded(['Compute state (1 -> 100)']); // but before it's flushed, a higher priority update interrupts it. root.unstable_flushSync(() => { update(n => n + 5); }); - expect(ReactTestRenderer).toHaveYielded([ + expect(Scheduler).toHaveYielded([ // The eagerly computed state was completely skipped 'Compute state (1 -> 6)', 'Parent: 6', @@ -576,7 +579,7 @@ describe('ReactHooks', () => { // Now when we finish the first update, the second update is rebased on top. // Notice we didn't have to recompute the first update even though it was // skipped in the previous render. - expect(root).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ 'Compute state (100 -> 105)', 'Parent: 105', 'Child: 105', @@ -593,7 +596,7 @@ describe('ReactHooks', () => { return props.dependencies; } const root = ReactTestRenderer.create(); - expect(ReactTestRenderer).toHaveYielded(['Did commit: A']); + expect(Scheduler).toHaveYielded(['Did commit: A']); expect(() => { root.update(); }).toWarnDev([ @@ -617,7 +620,7 @@ describe('ReactHooks', () => { const root = ReactTestRenderer.create(null); root.update(); - expect(ReactTestRenderer).toHaveYielded(['Compute']); + expect(Scheduler).toHaveYielded(['Compute']); expect(root).toMatchRenderedOutput('HELLO'); expect(() => { diff --git a/packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.internal.js b/packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.internal.js index 568d9e0872bbd..8b3c3d14e98e1 100644 --- a/packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.internal.js @@ -76,7 +76,7 @@ describe('ReactHooksWithNoopRenderer', () => { // Initial mount const counter = React.createRef(null); ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['Count: 0']); + expect(Scheduler).toFlushAndYield(['Count: 0']); expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]); // Schedule some updates @@ -86,17 +86,17 @@ describe('ReactHooksWithNoopRenderer', () => { }); // Partially flush without committing - expect(ReactNoop).toFlushAndYieldThrough(['Count: 11']); + expect(Scheduler).toFlushAndYieldThrough(['Count: 11']); expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]); // Interrupt with a high priority update ReactNoop.flushSync(() => { ReactNoop.render(); }); - expect(ReactNoop).toHaveYielded(['Total: 0']); + expect(Scheduler).toHaveYielded(['Total: 0']); // Resume rendering - expect(ReactNoop).toFlushAndYield(['Total: 11']); + expect(Scheduler).toFlushAndYield(['Total: 11']); expect(ReactNoop.getChildren()).toEqual([span('Total: 11')]); }); @@ -109,7 +109,7 @@ describe('ReactHooksWithNoopRenderer', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushAndThrow( + expect(Scheduler).toFlushAndThrow( 'Hooks can only be called inside the body of a function component.', ); @@ -119,7 +119,7 @@ describe('ReactHooksWithNoopRenderer', () => { return ; } ReactNoop.render(); - expect(ReactNoop).toFlushAndYield([10]); + expect(Scheduler).toFlushAndYield([10]); }); it('throws inside module-style components', () => { @@ -132,7 +132,7 @@ describe('ReactHooksWithNoopRenderer', () => { }; } ReactNoop.render(); - expect(ReactNoop).toFlushAndThrow( + expect(Scheduler).toFlushAndThrow( 'Hooks can only be called inside the body of a function component.', ); @@ -142,7 +142,7 @@ describe('ReactHooksWithNoopRenderer', () => { return ; } ReactNoop.render(); - expect(ReactNoop).toFlushAndYield([10]); + expect(Scheduler).toFlushAndYield([10]); }); it('throws when called outside the render phase', () => { @@ -161,15 +161,15 @@ describe('ReactHooksWithNoopRenderer', () => { Counter = forwardRef(Counter); const counter = React.createRef(null); ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['Count: 0']); + expect(Scheduler).toFlushAndYield(['Count: 0']); expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]); act(() => counter.current.updateCount(1)); - expect(ReactNoop).toFlushAndYield(['Count: 1']); + expect(Scheduler).toFlushAndYield(['Count: 1']); expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]); act(() => counter.current.updateCount(count => count + 10)); - expect(ReactNoop).toFlushAndYield(['Count: 11']); + expect(Scheduler).toFlushAndYield(['Count: 11']); expect(ReactNoop.getChildren()).toEqual([span('Count: 11')]); }); @@ -185,11 +185,11 @@ describe('ReactHooksWithNoopRenderer', () => { Counter = forwardRef(Counter); const counter = React.createRef(null); ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['getInitialState', 'Count: 42']); + expect(Scheduler).toFlushAndYield(['getInitialState', 'Count: 42']); expect(ReactNoop.getChildren()).toEqual([span('Count: 42')]); act(() => counter.current.updateCount(7)); - expect(ReactNoop).toFlushAndYield(['Count: 7']); + expect(Scheduler).toFlushAndYield(['Count: 7']); expect(ReactNoop.getChildren()).toEqual([span('Count: 7')]); }); @@ -203,14 +203,14 @@ describe('ReactHooksWithNoopRenderer', () => { Counter = forwardRef(Counter); const counter = React.createRef(null); ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['Count: 0']); + expect(Scheduler).toFlushAndYield(['Count: 0']); expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]); act(() => counter.current.updateCount(7)); - expect(ReactNoop).toFlushAndYield(['Count: 7']); + expect(Scheduler).toFlushAndYield(['Count: 7']); act(() => counter.current.updateLabel('Total')); - expect(ReactNoop).toFlushAndYield(['Total: 7']); + expect(Scheduler).toFlushAndYield(['Total: 7']); }); it('returns the same updater function every time', () => { @@ -221,15 +221,15 @@ describe('ReactHooksWithNoopRenderer', () => { return ; } ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['Count: 0']); + expect(Scheduler).toFlushAndYield(['Count: 0']); expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]); act(() => updaters[0](1)); - expect(ReactNoop).toFlushAndYield(['Count: 1']); + expect(Scheduler).toFlushAndYield(['Count: 1']); expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]); act(() => updaters[0](count => count + 10)); - expect(ReactNoop).toFlushAndYield(['Count: 11']); + expect(Scheduler).toFlushAndYield(['Count: 11']); expect(ReactNoop.getChildren()).toEqual([span('Count: 11')]); expect(updaters).toEqual([updaters[0], updaters[0], updaters[0]]); @@ -244,9 +244,9 @@ describe('ReactHooksWithNoopRenderer', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); ReactNoop.render(null); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(() => act(() => _updateCount(1))).toWarnDev( "Warning: Can't perform a React state update on an unmounted " + 'component. This is a no-op, but it indicates a memory leak in your ' + @@ -266,15 +266,15 @@ describe('ReactHooksWithNoopRenderer', () => { Counter = memo(Counter); ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['Count: 0']); + expect(Scheduler).toFlushAndYield(['Count: 0']); expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]); ReactNoop.render(); - expect(ReactNoop).toFlushAndYield([]); + expect(Scheduler).toFlushAndYield([]); expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]); act(() => _updateCount(1)); - expect(ReactNoop).toFlushAndYield(['Count: 1']); + expect(Scheduler).toFlushAndYield(['Count: 1']); expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]); }); }); @@ -295,27 +295,27 @@ describe('ReactHooksWithNoopRenderer', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['Scrolling down: false']); + expect(Scheduler).toFlushAndYield(['Scrolling down: false']); expect(ReactNoop.getChildren()).toEqual([span('Scrolling down: false')]); ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['Scrolling down: true']); + expect(Scheduler).toFlushAndYield(['Scrolling down: true']); expect(ReactNoop.getChildren()).toEqual([span('Scrolling down: true')]); ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['Scrolling down: true']); + expect(Scheduler).toFlushAndYield(['Scrolling down: true']); expect(ReactNoop.getChildren()).toEqual([span('Scrolling down: true')]); ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['Scrolling down: true']); + expect(Scheduler).toFlushAndYield(['Scrolling down: true']); expect(ReactNoop.getChildren()).toEqual([span('Scrolling down: true')]); ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['Scrolling down: false']); + expect(Scheduler).toFlushAndYield(['Scrolling down: false']); expect(ReactNoop.getChildren()).toEqual([span('Scrolling down: false')]); ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['Scrolling down: false']); + expect(Scheduler).toFlushAndYield(['Scrolling down: false']); expect(ReactNoop.getChildren()).toEqual([span('Scrolling down: false')]); }); @@ -330,7 +330,7 @@ describe('ReactHooksWithNoopRenderer', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ 'Render: 0', 'Render: 1', 'Render: 2', @@ -353,7 +353,7 @@ describe('ReactHooksWithNoopRenderer', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ // Should increase by three each time 'Render: 0', 'Render: 3', @@ -373,7 +373,7 @@ describe('ReactHooksWithNoopRenderer', () => { return ; } ReactNoop.render(); - expect(ReactNoop).toFlushAndThrow( + expect(Scheduler).toFlushAndThrow( 'Too many re-renders. React limits the number of renders to prevent ' + 'an infinite loop.', ); @@ -393,7 +393,7 @@ describe('ReactHooksWithNoopRenderer', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ 'Render: 0', 'Render: 1', 'Render: 2', @@ -443,7 +443,7 @@ describe('ReactHooksWithNoopRenderer', () => { Counter = forwardRef(Counter); const counter = React.createRef(null); ReactNoop.render(); - expect(ReactNoop).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ // The count should increase by alternating amounts of 10 and 1 // until we reach 21. 'Render: 0', @@ -460,7 +460,7 @@ describe('ReactHooksWithNoopRenderer', () => { counter.current.dispatch('reset'); }); ReactNoop.render(); - expect(ReactNoop).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ 'Render: 0', 'Render: 1', 'Render: 11', @@ -496,11 +496,11 @@ describe('ReactHooksWithNoopRenderer', () => { Counter = forwardRef(Counter); const counter = React.createRef(null); ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['Count: 0']); + expect(Scheduler).toFlushAndYield(['Count: 0']); expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]); act(() => counter.current.dispatch(INCREMENT)); - expect(ReactNoop).toFlushAndYield(['Count: 1']); + expect(Scheduler).toFlushAndYield(['Count: 1']); expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]); act(() => { counter.current.dispatch(DECREMENT); @@ -508,7 +508,7 @@ describe('ReactHooksWithNoopRenderer', () => { counter.current.dispatch(DECREMENT); }); - expect(ReactNoop).toFlushAndYield(['Count: -2']); + expect(Scheduler).toFlushAndYield(['Count: -2']); expect(ReactNoop.getChildren()).toEqual([span('Count: -2')]); }); @@ -538,11 +538,11 @@ describe('ReactHooksWithNoopRenderer', () => { Counter = forwardRef(Counter); const counter = React.createRef(null); ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['Init', 'Count: 10']); + expect(Scheduler).toFlushAndYield(['Init', 'Count: 10']); expect(ReactNoop.getChildren()).toEqual([span('Count: 10')]); act(() => counter.current.dispatch(INCREMENT)); - expect(ReactNoop).toFlushAndYield(['Count: 11']); + expect(Scheduler).toFlushAndYield(['Count: 11']); expect(ReactNoop.getChildren()).toEqual([span('Count: 11')]); act(() => { @@ -551,7 +551,7 @@ describe('ReactHooksWithNoopRenderer', () => { counter.current.dispatch(DECREMENT); }); - expect(ReactNoop).toFlushAndYield(['Count: 8']); + expect(Scheduler).toFlushAndYield(['Count: 8']); expect(ReactNoop.getChildren()).toEqual([span('Count: 8')]); }); @@ -573,7 +573,7 @@ describe('ReactHooksWithNoopRenderer', () => { const counter = React.createRef(null); ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['Count: 0']); + expect(Scheduler).toFlushAndYield(['Count: 0']); expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]); act(() => { @@ -585,10 +585,10 @@ describe('ReactHooksWithNoopRenderer', () => { ReactNoop.flushSync(() => { counter.current.dispatch(INCREMENT); }); - expect(ReactNoop).toHaveYielded(['Count: 1']); + expect(Scheduler).toHaveYielded(['Count: 1']); expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]); - expect(ReactNoop).toFlushAndYield(['Count: 4']); + expect(Scheduler).toFlushAndYield(['Count: 4']); expect(ReactNoop.getChildren()).toEqual([span('Count: 4')]); }); }); @@ -604,18 +604,18 @@ describe('ReactHooksWithNoopRenderer', () => { ReactNoop.render(, () => ReactNoop.yield('Sync effect'), ); - expect(ReactNoop).toFlushAndYieldThrough(['Count: 0', 'Sync effect']); + expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']); expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]); // Effects are deferred until after the commit - expect(ReactNoop).toFlushAndYield(['Passive effect [0]']); + expect(Scheduler).toFlushAndYield(['Passive effect [0]']); ReactNoop.render(, () => ReactNoop.yield('Sync effect'), ); - expect(ReactNoop).toFlushAndYieldThrough(['Count: 1', 'Sync effect']); + expect(Scheduler).toFlushAndYieldThrough(['Count: 1', 'Sync effect']); expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]); // Effects are deferred until after the commit - expect(ReactNoop).toFlushAndYield(['Passive effect [1]']); + expect(Scheduler).toFlushAndYield(['Passive effect [1]']); }); it('flushes passive effects even with sibling deletions', () => { @@ -633,7 +633,7 @@ describe('ReactHooksWithNoopRenderer', () => { } let passive = ; ReactNoop.render([, passive]); - expect(ReactNoop).toFlushAndYieldThrough([ + expect(Scheduler).toFlushAndYieldThrough([ 'Layout', 'Passive', 'Layout effect', @@ -646,13 +646,13 @@ describe('ReactHooksWithNoopRenderer', () => { // Destroying the first child shouldn't prevent the passive effect from // being executed ReactNoop.render([passive]); - expect(ReactNoop).toHaveYielded(['Passive effect']); - expect(ReactNoop).toFlushAndYield([]); + expect(Scheduler).toHaveYielded(['Passive effect']); + expect(Scheduler).toFlushAndYield([]); expect(ReactNoop.getChildren()).toEqual([span('Passive')]); // (No effects are left to flush.) ReactNoop.flushPassiveEffects(); - expect(ReactNoop).toHaveYielded([]); + expect(Scheduler).toHaveYielded([]); }); it('flushes passive effects even if siblings schedule an update', () => { @@ -677,7 +677,7 @@ describe('ReactHooksWithNoopRenderer', () => { ReactNoop.render([, ]); act(() => { - expect(ReactNoop).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ 'Passive', 'Layout', 'Layout effect 0', @@ -709,7 +709,7 @@ describe('ReactHooksWithNoopRenderer', () => { return ; } ReactNoop.render([, ]); - expect(ReactNoop).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ 'Passive', 'Layout', 'Layout effect', @@ -745,22 +745,22 @@ describe('ReactHooksWithNoopRenderer', () => { ReactNoop.render(, () => ReactNoop.yield('Sync effect'), ); - expect(ReactNoop).toFlushAndYieldThrough([0, 'Sync effect']); + expect(Scheduler).toFlushAndYieldThrough([0, 'Sync effect']); expect(ReactNoop.getChildren()).toEqual([span(0)]); // Before the effects have a chance to flush, schedule another update ReactNoop.render(, () => ReactNoop.yield('Sync effect'), ); - expect(ReactNoop).toHaveYielded([ + expect(Scheduler).toHaveYielded([ // The previous effect flushes before the reconciliation 'Committed state when effect was fired: 0', ]); - expect(ReactNoop).toFlushAndYieldThrough([1, 'Sync effect']); + expect(Scheduler).toFlushAndYieldThrough([1, 'Sync effect']); expect(ReactNoop.getChildren()).toEqual([span(1)]); ReactNoop.flushPassiveEffects(); - expect(ReactNoop).toHaveYielded([ + expect(Scheduler).toHaveYielded([ 'Committed state when effect was fired: 1', ]); }, @@ -781,23 +781,23 @@ describe('ReactHooksWithNoopRenderer', () => { ReactNoop.render(, () => ReactNoop.yield('Sync effect'), ); - expect(ReactNoop).toFlushAndYieldThrough([ + expect(Scheduler).toFlushAndYieldThrough([ 'Count: (empty)', 'Sync effect', ]); expect(ReactNoop.getChildren()).toEqual([span('Count: (empty)')]); ReactNoop.flushPassiveEffects(); - expect(ReactNoop).toHaveYielded(['Schedule update [0]']); - expect(ReactNoop).toFlushAndYield(['Count: 0']); + expect(Scheduler).toHaveYielded(['Schedule update [0]']); + expect(Scheduler).toFlushAndYield(['Count: 0']); ReactNoop.render(, () => ReactNoop.yield('Sync effect'), ); - expect(ReactNoop).toFlushAndYieldThrough(['Count: 0', 'Sync effect']); + expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']); expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]); ReactNoop.flushPassiveEffects(); - expect(ReactNoop).toHaveYielded(['Schedule update [1]']); - expect(ReactNoop).toFlushAndYield(['Count: 1']); + expect(Scheduler).toHaveYielded(['Schedule update [1]']); + expect(Scheduler).toFlushAndYield(['Count: 1']); }); it('updates have async priority even if effects are flushed early', () => { @@ -815,7 +815,7 @@ describe('ReactHooksWithNoopRenderer', () => { ReactNoop.render(, () => ReactNoop.yield('Sync effect'), ); - expect(ReactNoop).toFlushAndYieldThrough([ + expect(Scheduler).toFlushAndYieldThrough([ 'Count: (empty)', 'Sync effect', ]); @@ -825,16 +825,16 @@ describe('ReactHooksWithNoopRenderer', () => { ReactNoop.render(, () => ReactNoop.yield('Sync effect'), ); - expect(ReactNoop).toHaveYielded(['Schedule update [0]']); - expect(ReactNoop).toFlushAndYieldThrough(['Count: 0']); + expect(Scheduler).toHaveYielded(['Schedule update [0]']); + expect(Scheduler).toFlushAndYieldThrough(['Count: 0']); expect(ReactNoop.getChildren()).toEqual([span('Count: (empty)')]); - expect(ReactNoop).toFlushAndYieldThrough(['Sync effect']); + expect(Scheduler).toFlushAndYieldThrough(['Sync effect']); expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]); ReactNoop.flushPassiveEffects(); - expect(ReactNoop).toHaveYielded(['Schedule update [1]']); - expect(ReactNoop).toFlushAndYield(['Count: 1']); + expect(Scheduler).toHaveYielded(['Schedule update [1]']); + expect(Scheduler).toFlushAndYield(['Count: 1']); expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]); }); @@ -853,14 +853,14 @@ describe('ReactHooksWithNoopRenderer', () => { ReactNoop.render(, () => ReactNoop.yield('Sync effect'), ); - expect(ReactNoop).toFlushAndYieldThrough(['Count: 0', 'Sync effect']); + expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']); expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]); // Enqueuing this update forces the passive effect to be flushed -- // updateCount(1) happens first, so 2 wins. act(() => _updateCount(2)); - expect(ReactNoop).toHaveYielded(['Will set count to 1']); - expect(ReactNoop).toFlushAndYield(['Count: 2']); + expect(Scheduler).toHaveYielded(['Will set count to 1']); + expect(Scheduler).toFlushAndYield(['Count: 2']); expect(ReactNoop.getChildren()).toEqual([span('Count: 2')]); }); @@ -900,7 +900,7 @@ describe('ReactHooksWithNoopRenderer', () => { ); }, ); - expect(ReactNoop).toFlushAndYieldThrough(['Count: 0', 'Sync effect']); + expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']); expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]); expect(onInteractionScheduledWorkCompleted).toHaveBeenCalledTimes(0); @@ -908,8 +908,8 @@ describe('ReactHooksWithNoopRenderer', () => { // Enqueuing this update forces the passive effect to be flushed -- // updateCount(1) happens first, so 2 wins. act(() => _updateCount(2)); - expect(ReactNoop).toHaveYielded(['Will set count to 1']); - expect(ReactNoop).toFlushAndYield(['Count: 2']); + expect(Scheduler).toHaveYielded(['Will set count to 1']); + expect(Scheduler).toFlushAndYield(['Count: 2']); expect(ReactNoop.getChildren()).toEqual([span('Count: 2')]); expect(onInteractionScheduledWorkCompleted).toHaveBeenCalledTimes(1); @@ -939,13 +939,13 @@ describe('ReactHooksWithNoopRenderer', () => { } ReactNoop.renderLegacySyncRoot(); // Even in sync mode, effects are deferred until after paint - expect(ReactNoop).toHaveYielded(['Count: (empty)']); + expect(Scheduler).toHaveYielded(['Count: (empty)']); expect(ReactNoop.getChildren()).toEqual([span('Count: (empty)')]); // Now fire the effects ReactNoop.flushPassiveEffects(); // There were multiple updates, but there should only be a // single render - expect(ReactNoop).toHaveYielded(['Count: 0']); + expect(Scheduler).toHaveYielded(['Count: 0']); expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]); }, ); @@ -967,7 +967,7 @@ describe('ReactHooksWithNoopRenderer', () => { ReactNoop.render(, () => ReactNoop.yield('Sync effect'), ); - expect(ReactNoop).toFlushAndYieldThrough([ + expect(Scheduler).toFlushAndYieldThrough([ 'Count: (empty)', 'Sync effect', ]); @@ -991,18 +991,18 @@ describe('ReactHooksWithNoopRenderer', () => { ReactNoop.render(, () => ReactNoop.yield('Sync effect'), ); - expect(ReactNoop).toFlushAndYieldThrough(['Count: 0', 'Sync effect']); + expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']); expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]); ReactNoop.flushPassiveEffects(); - expect(ReactNoop).toHaveYielded(['Did create [0]']); + expect(Scheduler).toHaveYielded(['Did create [0]']); ReactNoop.render(, () => ReactNoop.yield('Sync effect'), ); - expect(ReactNoop).toFlushAndYieldThrough(['Count: 1', 'Sync effect']); + expect(Scheduler).toFlushAndYieldThrough(['Count: 1', 'Sync effect']); expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]); ReactNoop.flushPassiveEffects(); - expect(ReactNoop).toHaveYielded(['Did destroy [0]', 'Did create [1]']); + expect(Scheduler).toHaveYielded(['Did destroy [0]', 'Did create [1]']); }); it('unmounts on deletion', () => { @@ -1018,13 +1018,13 @@ describe('ReactHooksWithNoopRenderer', () => { ReactNoop.render(, () => ReactNoop.yield('Sync effect'), ); - expect(ReactNoop).toFlushAndYieldThrough(['Count: 0', 'Sync effect']); + expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']); expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]); ReactNoop.flushPassiveEffects(); - expect(ReactNoop).toHaveYielded(['Did create [0]']); + expect(Scheduler).toHaveYielded(['Did create [0]']); ReactNoop.render(null); - expect(ReactNoop).toFlushAndYield(['Did destroy [0]']); + expect(Scheduler).toFlushAndYield(['Did destroy [0]']); expect(ReactNoop.getChildren()).toEqual([]); }); @@ -1041,21 +1041,21 @@ describe('ReactHooksWithNoopRenderer', () => { ReactNoop.render(, () => ReactNoop.yield('Sync effect'), ); - expect(ReactNoop).toFlushAndYieldThrough(['Count: 0', 'Sync effect']); + expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']); expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]); ReactNoop.flushPassiveEffects(); - expect(ReactNoop).toHaveYielded(['Did create [0]']); + expect(Scheduler).toHaveYielded(['Did create [0]']); ReactNoop.render(, () => ReactNoop.yield('Sync effect'), ); - expect(ReactNoop).toFlushAndYieldThrough(['Count: 1', 'Sync effect']); + expect(Scheduler).toFlushAndYieldThrough(['Count: 1', 'Sync effect']); expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]); ReactNoop.flushPassiveEffects(); - expect(ReactNoop).toHaveYielded([]); + expect(Scheduler).toHaveYielded([]); ReactNoop.render(null); - expect(ReactNoop).toFlushAndYield(['Did destroy [0]']); + expect(Scheduler).toFlushAndYield(['Did destroy [0]']); expect(ReactNoop.getChildren()).toEqual([]); }); @@ -1073,21 +1073,21 @@ describe('ReactHooksWithNoopRenderer', () => { ReactNoop.render(, () => ReactNoop.yield('Sync effect'), ); - expect(ReactNoop).toFlushAndYieldThrough(['Count: 0', 'Sync effect']); + expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']); expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]); ReactNoop.flushPassiveEffects(); - expect(ReactNoop).toHaveYielded(['Did create']); + expect(Scheduler).toHaveYielded(['Did create']); ReactNoop.render(, () => ReactNoop.yield('Sync effect'), ); - expect(ReactNoop).toFlushAndYieldThrough(['Count: 1', 'Sync effect']); + expect(Scheduler).toFlushAndYieldThrough(['Count: 1', 'Sync effect']); expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]); ReactNoop.flushPassiveEffects(); - expect(ReactNoop).toHaveYielded(['Did destroy', 'Did create']); + expect(Scheduler).toHaveYielded(['Did destroy', 'Did create']); ReactNoop.render(null); - expect(ReactNoop).toFlushAndYield(['Did destroy']); + expect(Scheduler).toFlushAndYield(['Did destroy']); expect(ReactNoop.getChildren()).toEqual([]); }); @@ -1108,19 +1108,19 @@ describe('ReactHooksWithNoopRenderer', () => { ReactNoop.render(, () => ReactNoop.yield('Sync effect'), ); - expect(ReactNoop).toFlushAndYieldThrough(['Count: 0', 'Sync effect']); + expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']); ReactNoop.flushPassiveEffects(); - expect(ReactNoop).toHaveYielded(['Did create [Count: 0]']); + expect(Scheduler).toHaveYielded(['Did create [Count: 0]']); expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]); ReactNoop.render(, () => ReactNoop.yield('Sync effect'), ); // Count changed - expect(ReactNoop).toFlushAndYieldThrough(['Count: 1', 'Sync effect']); + expect(Scheduler).toFlushAndYieldThrough(['Count: 1', 'Sync effect']); expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]); ReactNoop.flushPassiveEffects(); - expect(ReactNoop).toHaveYielded([ + expect(Scheduler).toHaveYielded([ 'Did destroy [Count: 0]', 'Did create [Count: 1]', ]); @@ -1129,19 +1129,19 @@ describe('ReactHooksWithNoopRenderer', () => { ReactNoop.yield('Sync effect'), ); // Nothing changed, so no effect should have fired - expect(ReactNoop).toFlushAndYieldThrough(['Count: 1', 'Sync effect']); + expect(Scheduler).toFlushAndYieldThrough(['Count: 1', 'Sync effect']); ReactNoop.flushPassiveEffects(); - expect(ReactNoop).toHaveYielded([]); + expect(Scheduler).toHaveYielded([]); expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]); ReactNoop.render(, () => ReactNoop.yield('Sync effect'), ); // Label changed - expect(ReactNoop).toFlushAndYieldThrough(['Total: 1', 'Sync effect']); + expect(Scheduler).toFlushAndYieldThrough(['Total: 1', 'Sync effect']); expect(ReactNoop.getChildren()).toEqual([span('Total: 1')]); ReactNoop.flushPassiveEffects(); - expect(ReactNoop).toHaveYielded([ + expect(Scheduler).toHaveYielded([ 'Did destroy [Count: 1]', 'Did create [Total: 1]', ]); @@ -1160,18 +1160,18 @@ describe('ReactHooksWithNoopRenderer', () => { ReactNoop.render(, () => ReactNoop.yield('Sync effect'), ); - expect(ReactNoop).toFlushAndYieldThrough(['Count: 0', 'Sync effect']); + expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']); expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]); ReactNoop.flushPassiveEffects(); - expect(ReactNoop).toHaveYielded(['Did commit 1 [0]', 'Did commit 2 [0]']); + expect(Scheduler).toHaveYielded(['Did commit 1 [0]', 'Did commit 2 [0]']); ReactNoop.render(, () => ReactNoop.yield('Sync effect'), ); - expect(ReactNoop).toFlushAndYieldThrough(['Count: 1', 'Sync effect']); + expect(Scheduler).toFlushAndYieldThrough(['Count: 1', 'Sync effect']); expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]); ReactNoop.flushPassiveEffects(); - expect(ReactNoop).toHaveYielded(['Did commit 1 [1]', 'Did commit 2 [1]']); + expect(Scheduler).toHaveYielded(['Did commit 1 [1]', 'Did commit 2 [1]']); }); it('unmounts all previous effects before creating any new ones', () => { @@ -1193,18 +1193,18 @@ describe('ReactHooksWithNoopRenderer', () => { ReactNoop.render(, () => ReactNoop.yield('Sync effect'), ); - expect(ReactNoop).toFlushAndYieldThrough(['Count: 0', 'Sync effect']); + expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']); expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]); ReactNoop.flushPassiveEffects(); - expect(ReactNoop).toHaveYielded(['Mount A [0]', 'Mount B [0]']); + expect(Scheduler).toHaveYielded(['Mount A [0]', 'Mount B [0]']); ReactNoop.render(, () => ReactNoop.yield('Sync effect'), ); - expect(ReactNoop).toFlushAndYieldThrough(['Count: 1', 'Sync effect']); + expect(Scheduler).toFlushAndYieldThrough(['Count: 1', 'Sync effect']); expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]); ReactNoop.flushPassiveEffects(); - expect(ReactNoop).toHaveYielded([ + expect(Scheduler).toHaveYielded([ 'Unmount A [0]', 'Unmount B [0]', 'Mount A [1]', @@ -1234,10 +1234,10 @@ describe('ReactHooksWithNoopRenderer', () => { ReactNoop.render(, () => ReactNoop.yield('Sync effect'), ); - expect(ReactNoop).toFlushAndYieldThrough(['Count: 0', 'Sync effect']); + expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']); expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]); expect(() => ReactNoop.flushPassiveEffects()).toThrow('Oops'); - expect(ReactNoop).toHaveYielded([ + expect(Scheduler).toHaveYielded([ 'Mount A [0]', 'Oops!', // Clean up effect A. There's no effect B to clean-up, because it @@ -1270,19 +1270,19 @@ describe('ReactHooksWithNoopRenderer', () => { ReactNoop.render(, () => ReactNoop.yield('Sync effect'), ); - expect(ReactNoop).toFlushAndYieldThrough(['Count: 0', 'Sync effect']); + expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']); expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]); ReactNoop.flushPassiveEffects(); - expect(ReactNoop).toHaveYielded(['Mount A [0]', 'Mount B [0]']); + expect(Scheduler).toHaveYielded(['Mount A [0]', 'Mount B [0]']); // This update will trigger an errror ReactNoop.render(, () => ReactNoop.yield('Sync effect'), ); - expect(ReactNoop).toFlushAndYieldThrough(['Count: 1', 'Sync effect']); + expect(Scheduler).toFlushAndYieldThrough(['Count: 1', 'Sync effect']); expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]); expect(() => ReactNoop.flushPassiveEffects()).toThrow('Oops'); - expect(ReactNoop).toHaveYielded([ + expect(Scheduler).toHaveYielded([ 'Unmount A [0]', 'Unmount B [0]', 'Mount A [1]', @@ -1316,19 +1316,19 @@ describe('ReactHooksWithNoopRenderer', () => { ReactNoop.render(, () => ReactNoop.yield('Sync effect'), ); - expect(ReactNoop).toFlushAndYieldThrough(['Count: 0', 'Sync effect']); + expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']); expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]); ReactNoop.flushPassiveEffects(); - expect(ReactNoop).toHaveYielded(['Mount A [0]', 'Mount B [0]']); + expect(Scheduler).toHaveYielded(['Mount A [0]', 'Mount B [0]']); // This update will trigger an errror ReactNoop.render(, () => ReactNoop.yield('Sync effect'), ); - expect(ReactNoop).toFlushAndYieldThrough(['Count: 1', 'Sync effect']); + expect(Scheduler).toFlushAndYieldThrough(['Count: 1', 'Sync effect']); expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]); expect(() => ReactNoop.flushPassiveEffects()).toThrow('Oops'); - expect(ReactNoop).toHaveYielded([ + expect(Scheduler).toHaveYielded([ 'Oops!', // B unmounts even though an error was thrown in the previous effect 'Unmount B [0]', @@ -1349,7 +1349,7 @@ describe('ReactHooksWithNoopRenderer', () => { ReactNoop.render(, () => ReactNoop.yield('Sync effect'), ); - expect(ReactNoop).toFlushAndYieldThrough([ + expect(Scheduler).toFlushAndYieldThrough([ 'Count: 0', 'Mount: 0', 'Sync effect', @@ -1359,7 +1359,7 @@ describe('ReactHooksWithNoopRenderer', () => { ReactNoop.render(, () => ReactNoop.yield('Sync effect'), ); - expect(ReactNoop).toFlushAndYieldThrough([ + expect(Scheduler).toFlushAndYieldThrough([ 'Count: 1', 'Unmount: 0', 'Mount: 1', @@ -1368,7 +1368,7 @@ describe('ReactHooksWithNoopRenderer', () => { expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]); ReactNoop.render(null); - expect(ReactNoop).toFlushAndYieldThrough(['Unmount: 1']); + expect(Scheduler).toFlushAndYieldThrough(['Unmount: 1']); expect(ReactNoop.getChildren()).toEqual([]); }); }); @@ -1395,7 +1395,7 @@ describe('ReactHooksWithNoopRenderer', () => { ReactNoop.render(, () => ReactNoop.yield('Sync effect'), ); - expect(ReactNoop).toFlushAndYieldThrough([ + expect(Scheduler).toFlushAndYieldThrough([ [0], 'Current: 0', 'Sync effect', @@ -1405,7 +1405,7 @@ describe('ReactHooksWithNoopRenderer', () => { ReactNoop.render(, () => ReactNoop.yield('Sync effect'), ); - expect(ReactNoop).toFlushAndYieldThrough([ + expect(Scheduler).toFlushAndYieldThrough([ [1], 'Current: 1', 'Sync effect', @@ -1439,7 +1439,7 @@ describe('ReactHooksWithNoopRenderer', () => { ReactNoop.render(, () => ReactNoop.yield('Sync effect'), ); - expect(ReactNoop).toFlushAndYieldThrough([ + expect(Scheduler).toFlushAndYieldThrough([ 'Mount layout [current: 0]', 'Sync effect', ]); @@ -1448,8 +1448,8 @@ describe('ReactHooksWithNoopRenderer', () => { ReactNoop.render(, () => ReactNoop.yield('Sync effect'), ); - expect(ReactNoop).toHaveYielded(['Mount normal [current: 0]']); - expect(ReactNoop).toFlushAndYieldThrough([ + expect(Scheduler).toHaveYielded(['Mount normal [current: 0]']); + expect(Scheduler).toFlushAndYieldThrough([ 'Unmount layout [current: 0]', 'Mount layout [current: 1]', 'Sync effect', @@ -1457,7 +1457,7 @@ describe('ReactHooksWithNoopRenderer', () => { expect(committedText).toEqual('1'); ReactNoop.flushPassiveEffects(); - expect(ReactNoop).toHaveYielded([ + expect(Scheduler).toHaveYielded([ 'Unmount normal [current: 1]', 'Mount normal [current: 1]', ]); @@ -1490,14 +1490,14 @@ describe('ReactHooksWithNoopRenderer', () => { const button = React.createRef(null); ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['Increment', 'Count: 0']); + expect(Scheduler).toFlushAndYield(['Increment', 'Count: 0']); expect(ReactNoop.getChildren()).toEqual([ span('Increment'), span('Count: 0'), ]); act(button.current.increment); - expect(ReactNoop).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ // Button should not re-render, because its props haven't changed // 'Increment', 'Count: 1', @@ -1509,7 +1509,7 @@ describe('ReactHooksWithNoopRenderer', () => { // Increase the increment amount ReactNoop.render(); - expect(ReactNoop).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ // Inputs did change this time 'Increment', 'Count: 1', @@ -1521,7 +1521,7 @@ describe('ReactHooksWithNoopRenderer', () => { // Callback should have updated act(button.current.increment); - expect(ReactNoop).toFlushAndYield(['Count: 11']); + expect(Scheduler).toFlushAndYield(['Count: 11']); expect(ReactNoop.getChildren()).toEqual([ span('Increment'), span('Count: 11'), @@ -1544,19 +1544,19 @@ describe('ReactHooksWithNoopRenderer', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(["Capitalize 'hello'", 'HELLO']); + expect(Scheduler).toFlushAndYield(["Capitalize 'hello'", 'HELLO']); expect(ReactNoop.getChildren()).toEqual([span('HELLO')]); ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(["Capitalize 'hi'", 'HI']); + expect(Scheduler).toFlushAndYield(["Capitalize 'hi'", 'HI']); expect(ReactNoop.getChildren()).toEqual([span('HI')]); ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['HI']); + expect(Scheduler).toFlushAndYield(['HI']); expect(ReactNoop.getChildren()).toEqual([span('HI')]); ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(["Capitalize 'goodbye'", 'GOODBYE']); + expect(Scheduler).toFlushAndYield(["Capitalize 'goodbye'", 'GOODBYE']); expect(ReactNoop.getChildren()).toEqual([span('GOODBYE')]); }); @@ -1577,16 +1577,16 @@ describe('ReactHooksWithNoopRenderer', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['compute A', 'A']); + expect(Scheduler).toFlushAndYield(['compute A', 'A']); ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['compute A', 'A']); + expect(Scheduler).toFlushAndYield(['compute A', 'A']); ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['compute A', 'A']); + expect(Scheduler).toFlushAndYield(['compute A', 'A']); ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['compute B', 'B']); + expect(Scheduler).toFlushAndYield(['compute B', 'B']); }); it('should not invoke memoized function during re-renders unless inputs change', () => { @@ -1607,13 +1607,13 @@ describe('ReactHooksWithNoopRenderer', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['compute A', 'A']); + expect(Scheduler).toFlushAndYield(['compute A', 'A']); ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['A']); + expect(Scheduler).toFlushAndYield(['A']); ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['compute B', 'B']); + expect(Scheduler).toFlushAndYield(['compute B', 'B']); }); }); @@ -1651,17 +1651,17 @@ describe('ReactHooksWithNoopRenderer', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushAndYield([]); + expect(Scheduler).toFlushAndYield([]); ping(1); ping(2); ping(3); - expect(ReactNoop).toHaveYielded([]); + expect(Scheduler).toHaveYielded([]); jest.advanceTimersByTime(100); - expect(ReactNoop).toHaveYielded(['ping: 3']); + expect(Scheduler).toHaveYielded(['ping: 3']); ping(4); jest.advanceTimersByTime(20); @@ -1669,10 +1669,10 @@ describe('ReactHooksWithNoopRenderer', () => { ping(6); jest.advanceTimersByTime(80); - expect(ReactNoop).toHaveYielded([]); + expect(Scheduler).toHaveYielded([]); jest.advanceTimersByTime(20); - expect(ReactNoop).toHaveYielded(['ping: 6']); + expect(Scheduler).toHaveYielded(['ping: 6']); }); it('should return the same ref during re-renders', () => { @@ -1693,10 +1693,10 @@ describe('ReactHooksWithNoopRenderer', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['val']); + expect(Scheduler).toFlushAndYield(['val']); ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['val']); + expect(Scheduler).toFlushAndYield(['val']); }); }); @@ -1717,14 +1717,14 @@ describe('ReactHooksWithNoopRenderer', () => { Counter = forwardRef(Counter); const counter = React.createRef(null); ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['Count: 0']); + expect(Scheduler).toFlushAndYield(['Count: 0']); expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]); expect(counter.current.count).toBe(0); act(() => { counter.current.dispatch(INCREMENT); }); - expect(ReactNoop).toFlushAndYield(['Count: 1']); + expect(Scheduler).toFlushAndYield(['Count: 1']); expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]); // Intentionally not updated because of [] deps: expect(counter.current.count).toBe(0); @@ -1747,14 +1747,14 @@ describe('ReactHooksWithNoopRenderer', () => { Counter = forwardRef(Counter); const counter = React.createRef(null); ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['Count: 0']); + expect(Scheduler).toFlushAndYield(['Count: 0']); expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]); expect(counter.current.count).toBe(0); act(() => { counter.current.dispatch(INCREMENT); }); - expect(ReactNoop).toFlushAndYield(['Count: 1']); + expect(Scheduler).toFlushAndYield(['Count: 1']); expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]); expect(counter.current.count).toBe(1); }); @@ -1783,7 +1783,7 @@ describe('ReactHooksWithNoopRenderer', () => { Counter = forwardRef(Counter); const counter = React.createRef(null); ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['Count: 0']); + expect(Scheduler).toFlushAndYield(['Count: 0']); expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]); expect(counter.current.count).toBe(0); expect(totalRefUpdates).toBe(1); @@ -1791,14 +1791,14 @@ describe('ReactHooksWithNoopRenderer', () => { act(() => { counter.current.dispatch(INCREMENT); }); - expect(ReactNoop).toFlushAndYield(['Count: 1']); + expect(Scheduler).toFlushAndYield(['Count: 1']); expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]); expect(counter.current.count).toBe(1); expect(totalRefUpdates).toBe(2); // Update that doesn't change the ref dependencies ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['Count: 1']); + expect(Scheduler).toFlushAndYield(['Count: 1']); expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]); expect(counter.current.count).toBe(1); expect(totalRefUpdates).toBe(2); // Should not increase since last time @@ -1828,7 +1828,7 @@ describe('ReactHooksWithNoopRenderer', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['A: 0, B: 0, C: [not loaded]']); + expect(Scheduler).toFlushAndYield(['A: 0, B: 0, C: [not loaded]']); expect(ReactNoop.getChildren()).toEqual([ span('A: 0, B: 0, C: [not loaded]'), ]); @@ -1838,7 +1838,7 @@ describe('ReactHooksWithNoopRenderer', () => { updateB(3); }); - expect(ReactNoop).toFlushAndYield(['A: 2, B: 3, C: [not loaded]']); + expect(Scheduler).toFlushAndYield(['A: 2, B: 3, C: [not loaded]']); expect(ReactNoop.getChildren()).toEqual([ span('A: 2, B: 3, C: [not loaded]'), ]); @@ -1846,7 +1846,7 @@ describe('ReactHooksWithNoopRenderer', () => { ReactNoop.render(); expect(() => { expect(() => { - expect(ReactNoop).toFlushAndYield(['A: 2, B: 3, C: 0']); + expect(Scheduler).toFlushAndYield(['A: 2, B: 3, C: 0']); }).toThrow('Rendered more hooks than during the previous render'); }).toWarnDev([ 'Warning: React has detected a change in the order of Hooks called by App. ' + @@ -1864,7 +1864,7 @@ describe('ReactHooksWithNoopRenderer', () => { // expect(ReactNoop.getChildren()).toEqual([span('A: 2, B: 3, C: 0')]); // updateC(4); - // expect(ReactNoop).toFlushAndYield(['A: 2, B: 3, C: 4']); + // expect(Scheduler).toFlushAndYield(['A: 2, B: 3, C: 4']); // expect(ReactNoop.getChildren()).toEqual([span('A: 2, B: 3, C: 4')]); }); @@ -1892,17 +1892,17 @@ describe('ReactHooksWithNoopRenderer', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['A: 0, B: 0, C: 0']); + expect(Scheduler).toFlushAndYield(['A: 0, B: 0, C: 0']); expect(ReactNoop.getChildren()).toEqual([span('A: 0, B: 0, C: 0')]); act(() => { updateA(2); updateB(3); updateC(4); }); - expect(ReactNoop).toFlushAndYield(['A: 2, B: 3, C: 4']); + expect(Scheduler).toFlushAndYield(['A: 2, B: 3, C: 4']); expect(ReactNoop.getChildren()).toEqual([span('A: 2, B: 3, C: 4')]); ReactNoop.render(); - expect(ReactNoop).toFlushAndThrow( + expect(Scheduler).toFlushAndThrow( 'Rendered fewer hooks than expected. This may be caused by an ' + 'accidental early return statement.', ); @@ -1932,14 +1932,14 @@ describe('ReactHooksWithNoopRenderer', () => { ReactNoop.render(, () => ReactNoop.yield('Sync effect'), ); - expect(ReactNoop).toFlushAndYieldThrough(['Sync effect']); + expect(Scheduler).toFlushAndYieldThrough(['Sync effect']); ReactNoop.flushPassiveEffects(); - expect(ReactNoop).toHaveYielded(['Mount A']); + expect(Scheduler).toHaveYielded(['Mount A']); ReactNoop.render(); expect(() => { expect(() => { - expect(ReactNoop).toFlushAndYield([]); + expect(Scheduler).toFlushAndYield([]); }).toThrow('Rendered more hooks than during the previous render'); }).toWarnDev([ 'Warning: React has detected a change in the order of Hooks called by App. ' + @@ -1954,10 +1954,10 @@ describe('ReactHooksWithNoopRenderer', () => { // Uncomment if/when we support this again // ReactNoop.flushPassiveEffects(); - // expect(ReactNoop).toHaveYielded(['Mount B']); + // expect(Scheduler).toHaveYielded(['Mount B']); // ReactNoop.render(); - // expect(ReactNoop).toFlushAndThrow( + // expect(Scheduler).toFlushAndThrow( // 'Rendered fewer hooks than expected. This may be caused by an ' + // 'accidental early return statement.', // ); diff --git a/packages/react-reconciler/src/__tests__/ReactIncremental-test.internal.js b/packages/react-reconciler/src/__tests__/ReactIncremental-test.internal.js index 586400acd3cc7..cd620d1e21fd3 100644 --- a/packages/react-reconciler/src/__tests__/ReactIncremental-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactIncremental-test.internal.js @@ -13,6 +13,7 @@ let React; let ReactFeatureFlags; let ReactNoop; +let Scheduler; let PropTypes; describe('ReactIncremental', () => { @@ -22,6 +23,7 @@ describe('ReactIncremental', () => { ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false; React = require('react'); ReactNoop = require('react-noop-renderer'); + Scheduler = require('scheduler'); PropTypes = require('prop-types'); }); @@ -35,7 +37,7 @@ describe('ReactIncremental', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); }); it('should render a simple component, in steps if needed', () => { @@ -58,7 +60,7 @@ describe('ReactIncremental', () => { expect(ReactNoop.flushNextYield()).toEqual(['Foo']); // Do the rest of the work. - expect(ReactNoop).toFlushAndYield(['Bar', 'Bar', 'callback']); + expect(Scheduler).toFlushAndYield(['Bar', 'Bar', 'callback']); }); it('updates a previous render', () => { @@ -96,7 +98,7 @@ describe('ReactIncremental', () => { ReactNoop.render(, () => ops.push('renderCallbackCalled'), ); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual([ 'Foo', @@ -114,7 +116,7 @@ describe('ReactIncremental', () => { ReactNoop.render(, () => ops.push('secondRenderCallbackCalled'), ); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); // TODO: Test bail out of host components. This is currently unobservable. @@ -146,21 +148,21 @@ describe('ReactIncremental', () => { // Init ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['Foo', 'Bar', 'Bar']); + expect(Scheduler).toFlushAndYield(['Foo', 'Bar', 'Bar']); ReactNoop.render(); // Flush part of the work - expect(ReactNoop).toFlushAndYieldThrough(['Foo', 'Bar']); + expect(Scheduler).toFlushAndYieldThrough(['Foo', 'Bar']); // This will abort the previous work and restart ReactNoop.flushSync(() => ReactNoop.render(null)); ReactNoop.render(); // Flush part of the new work - expect(ReactNoop).toFlushAndYieldThrough(['Foo', 'Bar']); + expect(Scheduler).toFlushAndYieldThrough(['Foo', 'Bar']); // Flush the rest of the work which now includes the low priority - expect(ReactNoop).toFlushAndYield(['Bar']); + expect(Scheduler).toFlushAndYield(['Bar']); }); it('should call callbacks even if updates are aborted', () => { @@ -186,7 +188,7 @@ describe('ReactIncremental', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); inst.setState( () => { @@ -197,7 +199,7 @@ describe('ReactIncremental', () => { ); // Flush part of the work - expect(ReactNoop).toFlushAndYieldThrough(['setState1']); + expect(Scheduler).toFlushAndYieldThrough(['setState1']); // This will abort the previous work and restart ReactNoop.flushSync(() => ReactNoop.render()); @@ -210,7 +212,7 @@ describe('ReactIncremental', () => { ); // Flush the rest of the work which now includes the low priority - expect(ReactNoop).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ 'setState1', 'setState2', 'callback1', @@ -248,7 +250,7 @@ describe('ReactIncremental', () => { // Init ReactNoop.render(); - expect(ReactNoop).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ 'Foo', 'Bar', 'Bar', @@ -259,9 +261,9 @@ describe('ReactIncremental', () => { // Render part of the work. This should be enough to flush everything except // the middle which has lower priority. ReactNoop.render(); - expect(ReactNoop).toFlushAndYieldThrough(['Foo', 'Bar', 'Bar']); + expect(Scheduler).toFlushAndYieldThrough(['Foo', 'Bar', 'Bar']); // Flush only the remaining work - expect(ReactNoop).toFlushAndYield(['Middle', 'Middle']); + expect(Scheduler).toFlushAndYield(['Middle', 'Middle']); }); it('can deprioritize a tree from without dropping work', () => { @@ -297,7 +299,7 @@ describe('ReactIncremental', () => { ReactNoop.flushSync(() => { ReactNoop.render(); }); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual(['Foo', 'Bar', 'Bar', 'Middle', 'Middle']); ops = []; @@ -312,7 +314,7 @@ describe('ReactIncremental', () => { // The hidden content was deprioritized from high to low priority. A low // priority callback should have been scheduled. Flush it now. - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual(['Middle', 'Middle']); }); @@ -375,7 +377,7 @@ describe('ReactIncremental', () => { ops = []; // Flush the rest to make sure that the bailout didn't block this work. - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual(['Middle']); }); @@ -455,7 +457,7 @@ describe('ReactIncremental', () => { // as a single batch. Therefore, it is correct that Middle should be in the // middle. If it occurs after the two "Bar" components then it was flushed // after them which is not correct. - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual(['Bar', 'Middle', 'Bar']); ops = []; @@ -473,7 +475,7 @@ describe('ReactIncremental', () => { // it. If the priority levels aren't down-prioritized correctly this may // abort rendering of the down-prioritized content. ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual(['Foo', 'Bar', 'Bar']); }); @@ -514,7 +516,7 @@ describe('ReactIncremental', () => { foo.setState({value: 'bar'}); ops = []; - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual(['Foo', 'Bar']); }); @@ -577,7 +579,7 @@ describe('ReactIncremental', () => { foo.setState({value: 'bar'}); ops = []; - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(constructorCount).toEqual(1); expect(ops).toEqual([ 'componentWillMount: foo', @@ -639,7 +641,7 @@ describe('ReactIncremental', () => { // Interrupt the rendering with a quick update. This should not touch the // middle content. ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); // We've now rendered the entire tree but we didn't have to redo the work // done by the first Middle and Bar already. @@ -674,7 +676,7 @@ describe('ReactIncremental', () => { // Since we did nothing to the middle subtree during the interruption, // we should be able to reuse the reconciliation work that we already did // without restarting. - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual(['Middle']); }); @@ -727,7 +729,7 @@ describe('ReactIncremental', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); ops = []; // Begin working on a low priority update to Child, but stop before @@ -747,7 +749,7 @@ describe('ReactIncremental', () => { // Continue the low pri work. The work on Child and GrandChild was memoized // so they should not be worked on again. ops = []; - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual([ // No Child // No Grandchild @@ -803,7 +805,7 @@ describe('ReactIncremental', () => { // Init ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual(['Foo', 'Bar', 'Content', 'Middle', 'Bar', 'Middle']); @@ -836,7 +838,7 @@ describe('ReactIncremental', () => { // Since we did nothing to the middle subtree during the interruption, // we should be able to reuse the reconciliation work that we already did // without restarting. - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual(['Middle']); }); @@ -857,16 +859,16 @@ describe('ReactIncremental', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); ops = []; ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual(['shouldComponentUpdate: false']); ops = []; ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual([ // If the memoized props were not updated during last bail out, sCU will // keep returning false. @@ -897,10 +899,10 @@ describe('ReactIncremental', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(instance.state).toEqual({a: 'a'}); instance.setState({b: 'b'}); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(instance.state).toEqual({a: 'a', b: 'b'}); }); @@ -926,12 +928,12 @@ describe('ReactIncremental', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); // Call setState multiple times before flushing instance.setState({b: 'b'}); instance.setState({c: 'c'}); instance.setState({d: 'd'}); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(instance.state).toEqual({a: 'a', b: 'b', c: 'c', d: 'd'}); }); @@ -961,15 +963,15 @@ describe('ReactIncremental', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(instance.state.num).toEqual(1); instance.setState(updater); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(instance.state.num).toEqual(2); instance.setState(updater); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(instance.state.num).toEqual(6); }); @@ -1003,10 +1005,10 @@ describe('ReactIncremental', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); instance.setState(updater); instance.setState(updater, callback); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(instance.state.num).toEqual(4); expect(instance.state.called).toEqual(true); }); @@ -1030,11 +1032,11 @@ describe('ReactIncremental', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); instance.setState({b: 'b'}); instance.setState({c: 'c'}); instance.updater.enqueueReplaceState(instance, {d: 'd'}); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(instance.state).toEqual({d: 'd'}); }); @@ -1071,10 +1073,10 @@ describe('ReactIncremental', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual(['Foo', 'Bar', 'Baz']); instance.forceUpdate(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual(['Foo', 'Bar', 'Baz', 'Bar', 'Baz']); }); @@ -1091,14 +1093,14 @@ describe('ReactIncremental', () => { const foo = React.createRef(null); ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['A: 0, B: 0']); + expect(Scheduler).toFlushAndYield(['A: 0, B: 0']); a = 1; foo.current.forceUpdate(); - expect(ReactNoop).toFlushAndYield(['A: 1, B: 0']); + expect(Scheduler).toFlushAndYield(['A: 1, B: 0']); ReactNoop.render(); - expect(ReactNoop).toFlushAndYield([]); + expect(Scheduler).toFlushAndYield([]); }); xit('can call sCU while resuming a partly mounted component', () => { @@ -1193,7 +1195,7 @@ describe('ReactIncremental', () => {
, ); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); ops = []; @@ -1214,7 +1216,7 @@ describe('ReactIncremental', () => { ops = []; - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual(['Bar:A-1', 'Baz']); }); @@ -1263,7 +1265,7 @@ describe('ReactIncremental', () => { ops = []; ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual([ 'App', @@ -1311,7 +1313,7 @@ describe('ReactIncremental', () => { ops = []; ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual([ 'App', @@ -1366,7 +1368,7 @@ describe('ReactIncremental', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual([ 'App', @@ -1394,7 +1396,7 @@ describe('ReactIncremental', () => { ops = []; ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual([ 'App', @@ -1432,7 +1434,7 @@ describe('ReactIncremental', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual(['getDerivedStateFromProps', 'render']); expect(instance.state).toEqual({foo: 'foo'}); @@ -1440,7 +1442,7 @@ describe('ReactIncremental', () => { ops = []; instance.changeState(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual([ 'getDerivedStateFromProps', @@ -1472,7 +1474,7 @@ describe('ReactIncremental', () => { const child = React.createRef(null); ReactNoop.render(); - expect(ReactNoop).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ 'getDerivedStateFromProps', 'Parent', 'Child', @@ -1480,7 +1482,7 @@ describe('ReactIncremental', () => { // Schedule an update on the child. The parent should not re-render. child.current.setState({}); - expect(ReactNoop).toFlushAndYield(['Child']); + expect(Scheduler).toFlushAndYield(['Child']); }); xit('does not call componentWillReceiveProps for state-only updates', () => { @@ -1553,7 +1555,7 @@ describe('ReactIncremental', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual([ 'App', @@ -1584,7 +1586,7 @@ describe('ReactIncremental', () => { // LifeCycle instances[1].tick(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual([ // no componentWillReceiveProps @@ -1617,7 +1619,7 @@ describe('ReactIncremental', () => { // Next we will update LifeCycle directly but not with new props. instances[1].tick(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual([ // This should not trigger another componentWillReceiveProps because @@ -1672,7 +1674,7 @@ describe('ReactIncremental', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual([ 'componentWillMount', @@ -1685,7 +1687,7 @@ describe('ReactIncremental', () => { // Update to same props ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual([ 'componentWillReceiveProps', @@ -1715,7 +1717,7 @@ describe('ReactIncremental', () => { // ...but we'll interrupt it to rerender the same props. ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); // We can bail out this time, but we must call componentDidUpdate. expect(ops).toEqual([ @@ -1741,7 +1743,7 @@ describe('ReactIncremental', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); ops = []; ReactNoop.flushSync(() => { @@ -1783,7 +1785,7 @@ describe('ReactIncremental', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); ops = []; function updater({n}) { @@ -1798,7 +1800,7 @@ describe('ReactIncremental', () => { instance.setState(updater, () => ops.push('third callback')); expect(() => { - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); }).toThrow('callback error'); // The third callback isn't called because the second one throws @@ -1897,7 +1899,7 @@ describe('ReactIncremental', () => { , ); expect(() => - expect(ReactNoop).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ 'Intl {}', 'ShowLocale {"locale":"fr"}', 'ShowBoth {"locale":"fr"}', @@ -1916,7 +1918,7 @@ describe('ReactIncremental', () => { , ); - expect(ReactNoop).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ 'Intl {}', 'ShowLocale {"locale":"de"}', 'ShowBoth {"locale":"de"}', @@ -1930,7 +1932,7 @@ describe('ReactIncremental', () => { , ); - expect(ReactNoop).toFlushAndYieldThrough(['Intl {}']); + expect(Scheduler).toFlushAndYieldThrough(['Intl {}']); ReactNoop.render( @@ -1942,7 +1944,7 @@ describe('ReactIncremental', () => { , ); expect(() => - expect(ReactNoop).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ 'ShowLocale {"locale":"sv"}', 'ShowBoth {"locale":"sv"}', 'Intl {}', @@ -1986,7 +1988,7 @@ describe('ReactIncremental', () => { } ReactNoop.render(); - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev( + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev( 'Legacy context API has been detected within a strict-mode tree: \n\n' + 'Please update the following components: Recurse', {withoutStack: true}, @@ -2023,7 +2025,7 @@ describe('ReactIncremental', () => { }; ReactNoop.render(); - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev( + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev( 'Legacy context API has been detected within a strict-mode tree: \n\n' + 'Please update the following components: Recurse', {withoutStack: true}, @@ -2074,14 +2076,14 @@ describe('ReactIncremental', () => { , ); - expect(ReactNoop).toFlushAndYieldThrough([ + expect(Scheduler).toFlushAndYieldThrough([ 'Intl {}', 'ShowLocale {"locale":"fr"}', 'ShowLocale {"locale":"fr"}', ]); expect(() => - expect(ReactNoop).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ 'ShowLocale {"locale":"fr"}', 'Intl {}', 'ShowLocale {"locale":"ru"}', @@ -2165,7 +2167,7 @@ describe('ReactIncremental', () => { , ); - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev( + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev( 'Legacy context API has been detected within a strict-mode tree: \n\n' + 'Please update the following components: Intl, ShowLocaleClass, ShowLocaleFn', {withoutStack: true}, @@ -2181,7 +2183,7 @@ describe('ReactIncremental', () => { ops.length = 0; statefulInst.setState({x: 1}); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); // All work has been memoized because setState() // happened below the context and could not have affected it. expect(ops).toEqual([]); @@ -2257,7 +2259,7 @@ describe('ReactIncremental', () => { , ); - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev( + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev( 'Legacy context API has been detected within a strict-mode tree: \n\n' + 'Please update the following components: Intl, ShowLocaleClass, ShowLocaleFn', {withoutStack: true}, @@ -2273,7 +2275,7 @@ describe('ReactIncremental', () => { ops.length = 0; statefulInst.setState({locale: 'gr'}); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual([ // Intl is below setState() so it might have been // affected by it. Therefore we re-render and recompute @@ -2326,7 +2328,7 @@ describe('ReactIncremental', () => { // Init ReactNoop.render(); - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev( + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev( 'Legacy context API has been detected within a strict-mode tree: \n\n' + 'Please update the following components: Child', {withoutStack: true}, @@ -2334,7 +2336,7 @@ describe('ReactIncremental', () => { // Trigger an update in the middle of the tree instance.setState({}); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); }); it('maintains the correct context when unwinding due to an error in render', () => { @@ -2376,7 +2378,7 @@ describe('ReactIncremental', () => { // Init ReactNoop.render(); - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev( + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev( 'Legacy context API has been detected within a strict-mode tree: \n\n' + 'Please update the following components: ContextProvider', {withoutStack: true}, @@ -2387,7 +2389,7 @@ describe('ReactIncremental', () => { instance.setState({ throwError: true, }); - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev( + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev( 'Error boundaries should implement getDerivedStateFromError()', {withoutStack: true}, ); @@ -2425,7 +2427,7 @@ describe('ReactIncremental', () => { } ReactNoop.render(); - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev( + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev( [ 'componentWillReceiveProps: Please update the following components ' + 'to use static getDerivedStateFromProps instead: MyComponent', @@ -2496,7 +2498,7 @@ describe('ReactIncremental', () => { // Initial render of the entire tree. // Renders: Root, Middle, FirstChild, SecondChild ReactNoop.render(A); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(renderCounter).toBe(1); @@ -2518,7 +2520,7 @@ describe('ReactIncremental', () => { // The in-progress child content will bailout. // Renders: Root, Middle, FirstChild, SecondChild ReactNoop.render(B); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); // At this point the higher priority render has completed. // Since FirstChild props didn't change, sCU returned false. @@ -2575,14 +2577,14 @@ describe('ReactIncremental', () => { , ); - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev( + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev( 'Legacy context API has been detected within a strict-mode tree: \n\n' + 'Please update the following components: Child, TopContextProvider', {withoutStack: true}, ); expect(rendered).toEqual(['count:0']); instance.updateCount(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(rendered).toEqual(['count:0', 'count:1']); }); @@ -2637,14 +2639,14 @@ describe('ReactIncremental', () => { , ); - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev( + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev( 'Legacy context API has been detected within a strict-mode tree: \n\n' + 'Please update the following components: Child, MiddleContextProvider, TopContextProvider', {withoutStack: true}, ); expect(rendered).toEqual(['count:0']); instance.updateCount(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(rendered).toEqual(['count:0', 'count:1']); }); @@ -2708,14 +2710,14 @@ describe('ReactIncremental', () => { , ); - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev( + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev( 'Legacy context API has been detected within a strict-mode tree: \n\n' + 'Please update the following components: Child, MiddleContextProvider, TopContextProvider', {withoutStack: true}, ); expect(rendered).toEqual(['count:0']); instance.updateCount(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(rendered).toEqual(['count:0']); }); @@ -2789,17 +2791,17 @@ describe('ReactIncremental', () => { , ); - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev( + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev( 'Legacy context API has been detected within a strict-mode tree: \n\n' + 'Please update the following components: Child, MiddleContextProvider, TopContextProvider', {withoutStack: true}, ); expect(rendered).toEqual(['count:0, name:brian']); topInstance.updateCount(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(rendered).toEqual(['count:0, name:brian']); middleInstance.updateName('not brian'); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(rendered).toEqual([ 'count:0, name:brian', 'count:1, name:not brian', @@ -2818,12 +2820,12 @@ describe('ReactIncremental', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushAndYieldThrough(['Parent: 1']); + expect(Scheduler).toFlushAndYieldThrough(['Parent: 1']); // Interrupt at same priority ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['Child: 1', 'Parent: 2', 'Child: 2']); + expect(Scheduler).toFlushAndYield(['Child: 1', 'Parent: 2', 'Child: 2']); }); it('does not interrupt for update at lower priority', () => { @@ -2838,13 +2840,13 @@ describe('ReactIncremental', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushAndYieldThrough(['Parent: 1']); + expect(Scheduler).toFlushAndYieldThrough(['Parent: 1']); // Interrupt at lower priority ReactNoop.expire(2000); ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['Child: 1', 'Parent: 2', 'Child: 2']); + expect(Scheduler).toFlushAndYield(['Child: 1', 'Parent: 2', 'Child: 2']); }); it('does interrupt for update at higher priority', () => { @@ -2859,13 +2861,13 @@ describe('ReactIncremental', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushAndYieldThrough(['Parent: 1']); + expect(Scheduler).toFlushAndYieldThrough(['Parent: 1']); // Interrupt at higher priority ReactNoop.flushSync(() => ReactNoop.render()); - expect(ReactNoop).toHaveYielded(['Parent: 2', 'Child: 2']); + expect(Scheduler).toHaveYielded(['Parent: 2', 'Child: 2']); - expect(ReactNoop).toFlushAndYield([]); + expect(Scheduler).toFlushAndYield([]); }); // We don't currently use fibers as keys. Re-enable this test if we @@ -2887,7 +2889,7 @@ describe('ReactIncremental', () => { } } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); } // First, verify that this code path normally receives Fibers as keys, @@ -2905,6 +2907,7 @@ describe('ReactIncremental', () => { }; React = require('react'); ReactNoop = require('react-noop-renderer'); + Scheduler = require('scheduler'); try { receivedNonExtensibleObjects = false; triggerCodePathThatUsesFibersAsMapKeys(); diff --git a/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.internal.js b/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.internal.js index 4bf486ca439c8..9f009a6f10090 100644 --- a/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.internal.js @@ -88,7 +88,7 @@ describe('ReactIncrementalErrorHandling', () => { ); // Start rendering asynchronously - expect(ReactNoop).toFlushAndYieldThrough([ + expect(Scheduler).toFlushAndYieldThrough([ 'ErrorBoundary (try)', 'Indirection', 'Indirection', @@ -98,9 +98,9 @@ describe('ReactIncrementalErrorHandling', () => { ]); // Still rendering async... - expect(ReactNoop).toFlushAndYieldThrough(['Indirection']); + expect(Scheduler).toFlushAndYieldThrough(['Indirection']); - expect(ReactNoop).toFlushAndYieldThrough([ + expect(Scheduler).toFlushAndYieldThrough([ 'Indirection', // Call getDerivedStateFromError and re-render the error boundary, this @@ -181,7 +181,7 @@ describe('ReactIncrementalErrorHandling', () => { ); // Start rendering asynchronously - expect(ReactNoop).toFlushAndYieldThrough([ + expect(Scheduler).toFlushAndYieldThrough([ 'ErrorBoundary (try)', 'Indirection', 'Indirection', @@ -191,9 +191,9 @@ describe('ReactIncrementalErrorHandling', () => { ]); // Still rendering async... - expect(ReactNoop).toFlushAndYieldThrough(['Indirection']); + expect(Scheduler).toFlushAndYieldThrough(['Indirection']); - expect(ReactNoop).toFlushAndYieldThrough([ + expect(Scheduler).toFlushAndYieldThrough([ 'Indirection', // Now that the tree is complete, and there's no remaining work, React // reverts to sync mode to retry one more time before handling the error. @@ -236,13 +236,13 @@ describe('ReactIncrementalErrorHandling', () => { ReactNoop.render(, onCommit); Scheduler.advanceTime(1000); - expect(ReactNoop).toFlushAndYieldThrough(['error']); + expect(Scheduler).toFlushAndYieldThrough(['error']); interrupt(); // This update is in a separate batch ReactNoop.render(, onCommit); - expect(ReactNoop).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ // The first render fails. But because there's a lower priority pending // update, it doesn't throw. 'error', @@ -282,7 +282,7 @@ describe('ReactIncrementalErrorHandling', () => { // Initial mount const parent = React.createRef(null); ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['Child']); + expect(Scheduler).toFlushAndYield(['Child']); expect(ReactNoop.getChildren()).toEqual([span('Child')]); // Schedule a low priority update to hide the child @@ -293,7 +293,7 @@ describe('ReactIncrementalErrorHandling', () => { ReactNoop.flushSync(() => { ReactNoop.render(); }); - expect(ReactNoop).toHaveYielded([ + expect(Scheduler).toHaveYielded([ // First the sync update triggers an error 'Error!', // Because there's a pending low priority update, we restart at the @@ -333,10 +333,10 @@ describe('ReactIncrementalErrorHandling', () => { ReactNoop.render(, () => ReactNoop.yield('commit')); // Render the bad component asynchronously - expect(ReactNoop).toFlushAndYieldThrough(['Parent', 'BadRender']); + expect(Scheduler).toFlushAndYieldThrough(['Parent', 'BadRender']); // Finish the rest of the async work - expect(ReactNoop).toFlushAndYieldThrough(['Sibling']); + expect(Scheduler).toFlushAndYieldThrough(['Sibling']); // React retries once, synchronously, before throwing. ops = []; @@ -383,7 +383,7 @@ describe('ReactIncrementalErrorHandling', () => { , ); - expect(ReactNoop).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ 'ErrorBoundary', 'BadMount', 'BadMount', @@ -420,7 +420,7 @@ describe('ReactIncrementalErrorHandling', () => { , ); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren()).toEqual([span('Caught an error: Hello.')]); }); @@ -454,10 +454,10 @@ describe('ReactIncrementalErrorHandling', () => { , ); - expect(ReactNoop).toFlushAndYieldThrough(['ErrorBoundary render success']); + expect(Scheduler).toFlushAndYieldThrough(['ErrorBoundary render success']); expect(ReactNoop.getChildren()).toEqual([]); - expect(ReactNoop).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ 'BrokenRender', // React retries one more time 'ErrorBoundary render success', @@ -582,7 +582,7 @@ describe('ReactIncrementalErrorHandling', () => { ); expect(() => { - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); }).toThrow('Hello'); expect(ops).toEqual([ 'RethrowErrorBoundary render', @@ -621,12 +621,12 @@ describe('ReactIncrementalErrorHandling', () => { , ); - expect(ReactNoop).toFlushAndYieldThrough(['RethrowErrorBoundary render']); + expect(Scheduler).toFlushAndYieldThrough(['RethrowErrorBoundary render']); expect(() => { - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); }).toThrow('Hello'); - expect(ReactNoop).toHaveYielded([ + expect(Scheduler).toHaveYielded([ 'BrokenRender', // React retries one more time @@ -723,7 +723,7 @@ describe('ReactIncrementalErrorHandling', () => { throw new Error('Hello'); }); }).toThrow('Hello'); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren()).toEqual([span('a:3')]); }); @@ -740,7 +740,7 @@ describe('ReactIncrementalErrorHandling', () => { }); }); }).toThrow('Hello'); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren()).toEqual([span('a:5')]); }); @@ -773,7 +773,7 @@ describe('ReactIncrementalErrorHandling', () => { ReactNoop.render(); expect(() => { - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); }).toThrow('Hello'); expect(ops).toEqual([ 'BrokenRender', @@ -783,7 +783,7 @@ describe('ReactIncrementalErrorHandling', () => { ]); ops = []; ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual(['Foo']); }); @@ -804,12 +804,12 @@ describe('ReactIncrementalErrorHandling', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); ops = []; expect(() => { ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); }).toThrow('Hello'); expect(ops).toEqual([ 'BrokenRender', @@ -820,7 +820,7 @@ describe('ReactIncrementalErrorHandling', () => { ops = []; ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual(['Foo']); }); @@ -842,16 +842,16 @@ describe('ReactIncrementalErrorHandling', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(() => { ReactNoop.render(
); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); }).toThrow('Hello'); ops = []; ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual(['Foo']); }); @@ -885,9 +885,9 @@ describe('ReactIncrementalErrorHandling', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); ReactNoop.render(null); - expect(ReactNoop).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ // Parent unmounts before the error is thrown. 'Parent componentWillUnmount', 'ThrowsOnUnmount componentWillUnmount', @@ -924,7 +924,7 @@ describe('ReactIncrementalErrorHandling', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); ReactNoop.flushSync(() => { ReactNoop.render(); @@ -958,7 +958,7 @@ describe('ReactIncrementalErrorHandling', () => { 'a', ); ReactNoop.renderToRootWithID(, 'b'); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren('a')).toEqual([ span('Caught an error: Hello.'), ]); @@ -972,14 +972,14 @@ describe('ReactIncrementalErrorHandling', () => { ReactNoop.renderToRootWithID(, 'a'); expect(() => { - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); }).toThrow('Hello'); expect(ReactNoop.getChildren('a')).toEqual([]); ReactNoop.renderToRootWithID(, 'a'); ReactNoop.renderToRootWithID(, 'b'); expect(() => { - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); }).toThrow('Hello'); expect(ReactNoop.getChildren('a')).toEqual([]); @@ -988,7 +988,7 @@ describe('ReactIncrementalErrorHandling', () => { ReactNoop.renderToRootWithID(, 'a'); ReactNoop.renderToRootWithID(, 'b'); expect(() => { - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); }).toThrow('Hello'); expect(ReactNoop.getChildren('a')).toEqual([span('a:3')]); expect(ReactNoop.getChildren('b')).toEqual([]); @@ -997,7 +997,7 @@ describe('ReactIncrementalErrorHandling', () => { ReactNoop.renderToRootWithID(, 'b'); ReactNoop.renderToRootWithID(, 'c'); expect(() => { - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); }).toThrow('Hello'); expect(ReactNoop.getChildren('a')).toEqual([span('a:4')]); expect(ReactNoop.getChildren('b')).toEqual([]); @@ -1009,7 +1009,7 @@ describe('ReactIncrementalErrorHandling', () => { ReactNoop.renderToRootWithID(, 'd'); ReactNoop.renderToRootWithID(, 'e'); expect(() => { - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); }).toThrow('Hello'); expect(ReactNoop.getChildren('a')).toEqual([span('a:5')]); expect(ReactNoop.getChildren('b')).toEqual([span('b:5')]); @@ -1024,7 +1024,7 @@ describe('ReactIncrementalErrorHandling', () => { ReactNoop.renderToRootWithID(, 'e'); ReactNoop.renderToRootWithID(, 'f'); expect(() => { - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); }).toThrow('Hello'); expect(ReactNoop.getChildren('a')).toEqual([]); expect(ReactNoop.getChildren('b')).toEqual([span('b:6')]); @@ -1039,7 +1039,7 @@ describe('ReactIncrementalErrorHandling', () => { ReactNoop.unmountRootWithID('d'); ReactNoop.unmountRootWithID('e'); ReactNoop.unmountRootWithID('f'); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren('a')).toEqual(null); expect(ReactNoop.getChildren('b')).toEqual(null); expect(ReactNoop.getChildren('c')).toEqual(null); @@ -1100,7 +1100,7 @@ describe('ReactIncrementalErrorHandling', () => { , ); - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev( + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev( 'Legacy context API has been detected within a strict-mode tree: \n\n' + 'Please update the following components: Connector, Provider', {withoutStack: true}, @@ -1133,7 +1133,7 @@ describe('ReactIncrementalErrorHandling', () => { , ); - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev([ + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev([ 'Warning: React.createElement: type is invalid -- expected a string', // React retries once on error 'Warning: React.createElement: type is invalid -- expected a string', @@ -1175,14 +1175,14 @@ describe('ReactIncrementalErrorHandling', () => { , ); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); ReactNoop.render( , ); - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev([ + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev([ 'Warning: React.createElement: type is invalid -- expected a string', // React retries once on error 'Warning: React.createElement: type is invalid -- expected a string', @@ -1206,7 +1206,7 @@ describe('ReactIncrementalErrorHandling', () => { 'Warning: React.createElement: type is invalid -- expected a string', {withoutStack: true}, ); - expect(ReactNoop).toFlushAndThrow( + expect(Scheduler).toFlushAndThrow( 'Element type is invalid: expected a string (for built-in components) or ' + 'a class/function (for composite components) but got: undefined.' + (__DEV__ @@ -1216,7 +1216,7 @@ describe('ReactIncrementalErrorHandling', () => { ); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren()).toEqual([span('hi')]); }); @@ -1255,11 +1255,11 @@ describe('ReactIncrementalErrorHandling', () => { , ); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); inst.setState({fail: true}); expect(() => { - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); }).toThrowError('Hello.'); expect(ops).toEqual([ @@ -1297,7 +1297,7 @@ describe('ReactIncrementalErrorHandling', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual(['barRef attach']); expect(ReactNoop.getChildren()).toEqual([div(span('Bar'))]); @@ -1305,7 +1305,7 @@ describe('ReactIncrementalErrorHandling', () => { // Unmount ReactNoop.render(); - expect(ReactNoop).toFlushAndThrow('Detach error'); + expect(Scheduler).toFlushAndThrow('Detach error'); expect(ops).toEqual([ 'barRef detach', // Bar should unmount even though its ref threw an error while detaching @@ -1317,14 +1317,14 @@ describe('ReactIncrementalErrorHandling', () => { it('handles error thrown by host config while working on failed root', () => { ReactNoop.render(); - expect(ReactNoop).toFlushAndThrow('Error in host config.'); + expect(Scheduler).toFlushAndThrow('Error in host config.'); }); it('handles error thrown by top-level callback', () => { ReactNoop.render(
, () => { throw new Error('Error!'); }); - expect(ReactNoop).toFlushAndThrow('Error!'); + expect(Scheduler).toFlushAndThrow('Error!'); }); it('error boundaries capture non-errors', () => { @@ -1371,7 +1371,7 @@ describe('ReactIncrementalErrorHandling', () => { , ); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ops).toEqual([ 'ErrorBoundary (try)', @@ -1442,7 +1442,7 @@ describe('ReactIncrementalErrorHandling', () => { , ); - expect(ReactNoop).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ 'ErrorBoundary (try)', 'throw', // Continue rendering siblings after BadRender throws @@ -1492,7 +1492,7 @@ describe('ReactIncrementalErrorHandling', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushAndYieldThrough([ + expect(Scheduler).toFlushAndYieldThrough([ 'render', 'throw', 'render', @@ -1534,7 +1534,7 @@ describe('ReactIncrementalErrorHandling', () => { , ); - expect(ReactNoop).toFlushAndYield(['render error message']); + expect(Scheduler).toFlushAndYield(['render error message']); expect(ReactNoop.getChildren()).toEqual([ span( 'Caught an error:\n' + @@ -1570,7 +1570,7 @@ describe('ReactIncrementalErrorHandling', () => { , ); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren()).toEqual([span('Caught an error: Hello')]); }); @@ -1594,7 +1594,7 @@ describe('ReactIncrementalErrorHandling', () => { ReactNoop.render(); expect(() => { - expect(ReactNoop).toFlushAndThrow('Oops!'); + expect(Scheduler).toFlushAndThrow('Oops!'); }).toWarnDev( 'Legacy context API has been detected within a strict-mode tree: \n\n' + 'Please update the following components: Provider', diff --git a/packages/react-reconciler/src/__tests__/ReactIncrementalErrorLogging-test.js b/packages/react-reconciler/src/__tests__/ReactIncrementalErrorLogging-test.js index 16b0393d3ddcc..84258d65eb6ab 100644 --- a/packages/react-reconciler/src/__tests__/ReactIncrementalErrorLogging-test.js +++ b/packages/react-reconciler/src/__tests__/ReactIncrementalErrorLogging-test.js @@ -12,12 +12,14 @@ let React; let ReactNoop; +let Scheduler; describe('ReactIncrementalErrorLogging', () => { beforeEach(() => { jest.resetModules(); React = require('react'); ReactNoop = require('react-noop-renderer'); + Scheduler = require('scheduler'); }); // Note: in this test file we won't be using toWarnDev() matchers @@ -50,7 +52,7 @@ describe('ReactIncrementalErrorLogging', () => {
, ); - expect(ReactNoop).toFlushAndThrow('constructor error'); + expect(Scheduler).toFlushAndThrow('constructor error'); expect(console.error).toHaveBeenCalledTimes(1); expect(console.error).toHaveBeenCalledWith( __DEV__ @@ -86,7 +88,7 @@ describe('ReactIncrementalErrorLogging', () => {
, ); - expect(ReactNoop).toFlushAndThrow('componentDidMount error'); + expect(Scheduler).toFlushAndThrow('componentDidMount error'); expect(console.error).toHaveBeenCalledTimes(1); expect(console.error).toHaveBeenCalledWith( __DEV__ @@ -125,7 +127,7 @@ describe('ReactIncrementalErrorLogging', () => { , ); - expect(ReactNoop).toFlushAndThrow('render error'); + expect(Scheduler).toFlushAndThrow('render error'); expect(logCapturedErrorCalls.length).toBe(1); expect(logCapturedErrorCalls[0]).toEqual( __DEV__ @@ -181,7 +183,7 @@ describe('ReactIncrementalErrorLogging', () => { , ); - expect(ReactNoop).toFlushAndYield( + expect(Scheduler).toFlushAndYield( [ 'render: 0', __DEV__ && 'render: 0', // replay diff --git a/packages/react-reconciler/src/__tests__/ReactIncrementalErrorReplay-test.js b/packages/react-reconciler/src/__tests__/ReactIncrementalErrorReplay-test.js index 0b4d20c4a56e8..a7e1b761162b2 100644 --- a/packages/react-reconciler/src/__tests__/ReactIncrementalErrorReplay-test.js +++ b/packages/react-reconciler/src/__tests__/ReactIncrementalErrorReplay-test.js @@ -12,17 +12,19 @@ let React; let ReactNoop; +let Scheduler; describe('ReactIncrementalErrorReplay', () => { beforeEach(() => { jest.resetModules(); React = require('react'); ReactNoop = require('react-noop-renderer'); + Scheduler = require('scheduler'); }); it('should fail gracefully on error in the host environment', () => { ReactNoop.render(); - expect(ReactNoop).toFlushAndThrow('Error in host config.'); + expect(Scheduler).toFlushAndThrow('Error in host config.'); }); it("should ignore error if it doesn't throw on retry", () => { @@ -43,6 +45,6 @@ describe('ReactIncrementalErrorReplay', () => { } } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); }); }); diff --git a/packages/react-reconciler/src/__tests__/ReactIncrementalPerf-test.internal.js b/packages/react-reconciler/src/__tests__/ReactIncrementalPerf-test.internal.js index c1f555207c62e..8e69483b6a384 100644 --- a/packages/react-reconciler/src/__tests__/ReactIncrementalPerf-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactIncrementalPerf-test.internal.js @@ -13,6 +13,7 @@ describe('ReactDebugFiberPerf', () => { let React; let ReactNoop; + let Scheduler; let PropTypes; let root; @@ -122,6 +123,7 @@ describe('ReactDebugFiberPerf', () => { // Import after the polyfill is set up: React = require('react'); ReactNoop = require('react-noop-renderer'); + Scheduler = require('scheduler'); PropTypes = require('prop-types'); }); @@ -144,7 +146,7 @@ describe('ReactDebugFiberPerf', () => {
, ); addComment('Mount'); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); ReactNoop.render( @@ -152,11 +154,11 @@ describe('ReactDebugFiberPerf', () => { , ); addComment('Update'); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); ReactNoop.render(null); addComment('Unmount'); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(getFlameChart()).toMatchSnapshot(); }); @@ -182,7 +184,7 @@ describe('ReactDebugFiberPerf', () => {
, ); addComment('Mount'); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(getFlameChart()).toMatchSnapshot(); }); @@ -200,7 +202,7 @@ describe('ReactDebugFiberPerf', () => { , ); addComment('Mount'); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(getFlameChart()).toMatchSnapshot(); }); @@ -216,7 +218,7 @@ describe('ReactDebugFiberPerf', () => { , ); addComment('Mount'); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(getFlameChart()).toMatchSnapshot(); }); @@ -248,13 +250,13 @@ describe('ReactDebugFiberPerf', () => {
, ); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); resetFlamechart(); a.setState({}); b.setState({}); addComment('Should include just A and B, no Parents'); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(getFlameChart()).toMatchSnapshot(); }); @@ -274,7 +276,7 @@ describe('ReactDebugFiberPerf', () => {
, ); addComment('Should print a warning'); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(getFlameChart()).toMatchSnapshot(); }); @@ -291,7 +293,7 @@ describe('ReactDebugFiberPerf', () => { ReactNoop.renderToRootWithID(, 'a'); addComment('Rendering the first root'); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(getFlameChart()).toMatchSnapshot(); }); @@ -314,7 +316,7 @@ describe('ReactDebugFiberPerf', () => {
, ); addComment('Should not print a warning'); - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev( + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev( [ 'componentWillMount: Please update the following components ' + 'to use componentDidMount instead: NotCascading' + @@ -329,7 +331,7 @@ describe('ReactDebugFiberPerf', () => {
, ); addComment('Should not print a warning'); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(getFlameChart()).toMatchSnapshot(); }); @@ -356,7 +358,7 @@ describe('ReactDebugFiberPerf', () => { } ReactNoop.render(); addComment('Mount'); - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev( + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev( [ 'componentWillMount: Please update the following components ' + 'to use componentDidMount instead: AllLifecycles' + @@ -371,10 +373,10 @@ describe('ReactDebugFiberPerf', () => { ); ReactNoop.render(); addComment('Update'); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); ReactNoop.render(null); addComment('Unmount'); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(getFlameChart()).toMatchSnapshot(); }); @@ -390,7 +392,7 @@ describe('ReactDebugFiberPerf', () => { ); }); addComment('Flush the child'); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(getFlameChart()).toMatchSnapshot(); }); @@ -430,9 +432,9 @@ describe('ReactDebugFiberPerf', () => {
, ); addComment('Start rendering through B'); - expect(ReactNoop).toFlushAndYieldThrough(['A', 'B']); + expect(Scheduler).toFlushAndYieldThrough(['A', 'B']); addComment('Complete the rest'); - expect(ReactNoop).toFlushAndYield(['C']); + expect(Scheduler).toFlushAndYield(['C']); expect(getFlameChart()).toMatchSnapshot(); }); @@ -448,7 +450,7 @@ describe('ReactDebugFiberPerf', () => { ); try { addComment('Will fatal'); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); } catch (err) { expect(err.message).toBe('Game over'); } @@ -458,7 +460,7 @@ describe('ReactDebugFiberPerf', () => {
, ); addComment('Will reconcile from a clean state'); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(getFlameChart()).toMatchSnapshot(); }); @@ -494,7 +496,7 @@ describe('ReactDebugFiberPerf', () => {
, ); addComment('Stop on Baddie and restart from Boundary'); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(getFlameChart()).toMatchSnapshot(); }); @@ -525,7 +527,7 @@ describe('ReactDebugFiberPerf', () => { , ); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); resetFlamechart(); ReactNoop.render( @@ -537,7 +539,7 @@ describe('ReactDebugFiberPerf', () => { , ); addComment('The commit phase should mention A and B just once'); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); ReactNoop.render( @@ -548,7 +550,7 @@ describe('ReactDebugFiberPerf', () => { ); addComment("Because of deduplication, we don't know B was cascading,"); addComment('but we should still see the warning for the commit phase.'); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(getFlameChart()).toMatchSnapshot(); }); @@ -561,7 +563,7 @@ describe('ReactDebugFiberPerf', () => { {ReactNoop.createPortal(, portalContainer, null)} , ); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(getFlameChart()).toMatchSnapshot(); }); @@ -574,7 +576,7 @@ describe('ReactDebugFiberPerf', () => { , ); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(getFlameChart()).toMatchSnapshot(); }); @@ -602,7 +604,7 @@ describe('ReactDebugFiberPerf', () => { , ); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(getFlameChart()).toMatchSnapshot(); resolve( @@ -620,7 +622,7 @@ describe('ReactDebugFiberPerf', () => { , ); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(getFlameChart()).toMatchSnapshot(); }); @@ -651,8 +653,8 @@ describe('ReactDebugFiberPerf', () => { ReactNoop.flushSync(() => { ReactNoop.render(); }); - expect(ReactNoop).toHaveYielded(['Foo']); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toHaveYielded(['Foo']); + expect(Scheduler).toFlushWithoutYielding(); expect(getFlameChart()).toMatchSnapshot(); }); @@ -663,7 +665,7 @@ describe('ReactDebugFiberPerf', () => { ReactNoop.render(); ReactNoop.expire(6000); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(getFlameChart()).toMatchSnapshot(); }); }); diff --git a/packages/react-reconciler/src/__tests__/ReactIncrementalReflection-test.internal.js b/packages/react-reconciler/src/__tests__/ReactIncrementalReflection-test.internal.js index 0f67ff943c190..771efbdd4837e 100644 --- a/packages/react-reconciler/src/__tests__/ReactIncrementalReflection-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactIncrementalReflection-test.internal.js @@ -13,6 +13,7 @@ let React; let ReactFeatureFlags; let ReactNoop; +let Scheduler; describe('ReactIncrementalReflection', () => { beforeEach(() => { @@ -21,6 +22,7 @@ describe('ReactIncrementalReflection', () => { ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false; React = require('react'); ReactNoop = require('react-noop-renderer'); + Scheduler = require('scheduler'); }); function div(...children) { @@ -62,13 +64,13 @@ describe('ReactIncrementalReflection', () => { ReactNoop.render(); // Render part way through but don't yet commit the updates. - expect(ReactNoop).toFlushAndYieldThrough(['componentWillMount: false']); + expect(Scheduler).toFlushAndYieldThrough(['componentWillMount: false']); expect(instances[0]._isMounted()).toBe(false); // Render the rest and commit the updates. expect(() => - expect(ReactNoop).toFlushAndYield(['componentDidMount: true']), + expect(Scheduler).toFlushAndYield(['componentDidMount: true']), ).toWarnDev( 'componentWillMount: Please update the following components ' + 'to use componentDidMount instead: Component', @@ -107,7 +109,7 @@ describe('ReactIncrementalReflection', () => { } ReactNoop.render(); - expect(() => expect(ReactNoop).toFlushAndYield(['Component'])).toWarnDev( + expect(() => expect(Scheduler).toFlushAndYield(['Component'])).toWarnDev( 'componentWillMount: Please update the following components ' + 'to use componentDidMount instead: Component', {withoutStack: true}, @@ -118,12 +120,12 @@ describe('ReactIncrementalReflection', () => { ReactNoop.render(); // Render part way through but don't yet commit the updates so it is not // fully unmounted yet. - expect(ReactNoop).toFlushAndYieldThrough(['Other']); + expect(Scheduler).toFlushAndYieldThrough(['Other']); expect(instances[0]._isMounted()).toBe(true); // Finish flushing the unmount. - expect(ReactNoop).toFlushAndYield(['componentWillUnmount: true']); + expect(Scheduler).toFlushAndYield(['componentWillUnmount: true']); expect(instances[0]._isMounted()).toBe(false); }); @@ -185,7 +187,7 @@ describe('ReactIncrementalReflection', () => { ReactNoop.render(); // Flush past Component but don't complete rendering everything yet. - expect(ReactNoop).toFlushAndYieldThrough([ + expect(Scheduler).toFlushAndYieldThrough([ ['componentWillMount', null], 'render', 'render sibling', @@ -197,7 +199,7 @@ describe('ReactIncrementalReflection', () => { expect(findInstance(classInstance)).toBe(null); expect(() => - expect(ReactNoop).toFlushAndYield([['componentDidMount', span()]]), + expect(Scheduler).toFlushAndYield([['componentDidMount', span()]]), ).toWarnDev( 'componentWillMount: Please update the following components ' + 'to use componentDidMount instead: Component' + @@ -214,7 +216,7 @@ describe('ReactIncrementalReflection', () => { // Flush next step which will cause an update but not yet render a new host // node. ReactNoop.render(); - expect(ReactNoop).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ ['componentWillUpdate', hostSpan], 'render', 'render sibling', @@ -226,7 +228,7 @@ describe('ReactIncrementalReflection', () => { // The next step will render a new host node but won't get committed yet. // We expect this to mutate the original Fiber. ReactNoop.render(); - expect(ReactNoop).toFlushAndYieldThrough([ + expect(Scheduler).toFlushAndYieldThrough([ ['componentWillUpdate', hostSpan], 'render', 'render sibling', @@ -236,7 +238,7 @@ describe('ReactIncrementalReflection', () => { expect(ReactNoop.findInstance(classInstance)).toBe(hostSpan); // When we finally flush the tree it will get committed. - expect(ReactNoop).toFlushAndYield([['componentDidUpdate', div()]]); + expect(Scheduler).toFlushAndYield([['componentDidUpdate', div()]]); const hostDiv = classInstance.div; expect(hostDiv).toBeDefined(); @@ -247,7 +249,7 @@ describe('ReactIncrementalReflection', () => { // Render to null but don't commit it yet. ReactNoop.render(); - expect(ReactNoop).toFlushAndYieldThrough([ + expect(Scheduler).toFlushAndYieldThrough([ ['componentWillUpdate', hostDiv], 'render', 'render sibling', @@ -256,14 +258,14 @@ describe('ReactIncrementalReflection', () => { // This should still be the host div since the deletion is not committed. expect(ReactNoop.findInstance(classInstance)).toBe(hostDiv); - expect(ReactNoop).toFlushAndYield([['componentDidUpdate', null]]); + expect(Scheduler).toFlushAndYield([['componentDidUpdate', null]]); // This should still be the host div since the deletion is not committed. expect(ReactNoop.findInstance(classInstance)).toBe(null); // Render a div again ReactNoop.render(); - expect(ReactNoop).toFlushAndYield([ + expect(Scheduler).toFlushAndYield([ ['componentWillUpdate', null], 'render', 'render sibling', @@ -272,6 +274,6 @@ describe('ReactIncrementalReflection', () => { // Unmount the component. ReactNoop.render([]); - expect(ReactNoop).toFlushAndYield([['componentWillUnmount', hostDiv]]); + expect(Scheduler).toFlushAndYield([['componentWillUnmount', hostDiv]]); }); }); diff --git a/packages/react-reconciler/src/__tests__/ReactIncrementalScheduling-test.internal.js b/packages/react-reconciler/src/__tests__/ReactIncrementalScheduling-test.internal.js index 75185d263c430..4ee25bc545ed1 100644 --- a/packages/react-reconciler/src/__tests__/ReactIncrementalScheduling-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactIncrementalScheduling-test.internal.js @@ -13,6 +13,7 @@ let React; let ReactFeatureFlags; let ReactNoop; +let Scheduler; describe('ReactIncrementalScheduling', () => { beforeEach(() => { @@ -21,6 +22,7 @@ describe('ReactIncrementalScheduling', () => { ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false; React = require('react'); ReactNoop = require('react-noop-renderer'); + Scheduler = require('scheduler'); }); function span(prop) { @@ -31,7 +33,7 @@ describe('ReactIncrementalScheduling', () => { ReactNoop.render(); expect(ReactNoop.getChildren()).toEqual([]); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop).toMatchRenderedOutput(); }); @@ -40,7 +42,7 @@ describe('ReactIncrementalScheduling', () => { ReactNoop.renderToRootWithID(, 'b'); ReactNoop.renderToRootWithID(, 'c'); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]); expect(ReactNoop.getChildren('b')).toEqual([span('b:1')]); @@ -50,7 +52,7 @@ describe('ReactIncrementalScheduling', () => { it('schedules top-level updates in order of priority', () => { // Initial render. ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop).toMatchRenderedOutput(); ReactNoop.batchedUpdates(() => { @@ -66,14 +68,14 @@ describe('ReactIncrementalScheduling', () => { // The terminal value should be the last update that was scheduled, // regardless of priority. In this case, that's the last sync update. - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop).toMatchRenderedOutput(); }); it('schedules top-level updates with same priority in order of insertion', () => { // Initial render. ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop).toMatchRenderedOutput(); ReactNoop.render(); @@ -81,7 +83,7 @@ describe('ReactIncrementalScheduling', () => { ReactNoop.render(); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop).toMatchRenderedOutput(); }); @@ -102,7 +104,7 @@ describe('ReactIncrementalScheduling', () => { ReactNoop.renderToRootWithID(, 'b'); ReactNoop.renderToRootWithID(, 'c'); }); - expect(ReactNoop).toFlushAndYield(['a:1', 'b:1', 'c:1']); + expect(Scheduler).toFlushAndYield(['a:1', 'b:1', 'c:1']); expect(ReactNoop.getChildrenAsJSX('a')).toEqual('a:1'); expect(ReactNoop.getChildrenAsJSX('b')).toEqual('b:1'); @@ -114,7 +116,7 @@ describe('ReactIncrementalScheduling', () => { ReactNoop.renderToRootWithID(, 'b'); }); // Ensure it starts in the order it was scheduled - expect(ReactNoop).toFlushAndYieldThrough(['c:2']); + expect(Scheduler).toFlushAndYieldThrough(['c:2']); expect(ReactNoop.getChildrenAsJSX('a')).toEqual('a:1'); expect(ReactNoop.getChildrenAsJSX('b')).toEqual('b:1'); @@ -124,12 +126,12 @@ describe('ReactIncrementalScheduling', () => { ReactNoop.renderToRootWithID(, 'a'); }); // Keep performing work in the order it was scheduled - expect(ReactNoop).toFlushAndYieldThrough(['b:2']); + expect(Scheduler).toFlushAndYieldThrough(['b:2']); expect(ReactNoop.getChildrenAsJSX('a')).toEqual('a:1'); expect(ReactNoop.getChildrenAsJSX('b')).toEqual('b:2'); expect(ReactNoop.getChildrenAsJSX('c')).toEqual('c:2'); - expect(ReactNoop).toFlushAndYieldThrough(['a:2']); + expect(Scheduler).toFlushAndYieldThrough(['a:2']); expect(ReactNoop.getChildrenAsJSX('a')).toEqual('a:2'); expect(ReactNoop.getChildrenAsJSX('b')).toEqual('b:2'); expect(ReactNoop.getChildrenAsJSX('c')).toEqual('c:2'); @@ -175,7 +177,7 @@ describe('ReactIncrementalScheduling', () => { ReactNoop.render(); // Render without committing - expect(ReactNoop).toFlushAndYieldThrough(['render: 0']); + expect(Scheduler).toFlushAndYieldThrough(['render: 0']); // Do one more unit of work to commit expect(ReactNoop.flushNextYield()).toEqual([ @@ -188,7 +190,7 @@ describe('ReactIncrementalScheduling', () => { ]); instance.setState({tick: 2}); - expect(ReactNoop).toFlushAndYieldThrough(['render: 2']); + expect(Scheduler).toFlushAndYieldThrough(['render: 2']); expect(ReactNoop.flushNextYield()).toEqual([ 'componentDidUpdate: 2', 'componentDidUpdate (before setState): 2', @@ -243,7 +245,7 @@ describe('ReactIncrementalScheduling', () => { ReactNoop.render(); }); // The cDM update should not have flushed yet because it has async priority. - expect(ReactNoop).toHaveYielded([ + expect(Scheduler).toHaveYielded([ 'render: 0', 'componentDidMount (before setState): 0', 'componentDidMount (after setState): 0', @@ -251,13 +253,13 @@ describe('ReactIncrementalScheduling', () => { expect(ReactNoop).toMatchRenderedOutput(); // Now flush the cDM update. - expect(ReactNoop).toFlushAndYield(['render: 1', 'componentDidUpdate: 1']); + expect(Scheduler).toFlushAndYield(['render: 1', 'componentDidUpdate: 1']); expect(ReactNoop).toMatchRenderedOutput(); // Increment the tick to 2. This will trigger an update inside cDU. Flush // the first update without flushing the second one. instance.setState({tick: 2}); - expect(ReactNoop).toFlushAndYieldThrough([ + expect(Scheduler).toFlushAndYieldThrough([ 'render: 2', 'componentDidUpdate: 2', 'componentDidUpdate (before setState): 2', @@ -266,7 +268,7 @@ describe('ReactIncrementalScheduling', () => { expect(ReactNoop).toMatchRenderedOutput(); // Now flush the cDU update. - expect(ReactNoop).toFlushAndYield(['render: 3', 'componentDidUpdate: 3']); + expect(Scheduler).toFlushAndYield(['render: 3', 'componentDidUpdate: 3']); expect(ReactNoop).toMatchRenderedOutput(); }); @@ -290,7 +292,7 @@ describe('ReactIncrementalScheduling', () => { ReactNoop.render(); // This should be just enough to complete all the work, but not enough to // commit it. - expect(ReactNoop).toFlushAndYieldThrough(['Foo']); + expect(Scheduler).toFlushAndYieldThrough(['Foo']); expect(ReactNoop).toMatchRenderedOutput(null); // Do one more unit of work. @@ -345,7 +347,7 @@ describe('ReactIncrementalScheduling', () => { } } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop).toMatchRenderedOutput(); ReactNoop.flushSync(() => { diff --git a/packages/react-reconciler/src/__tests__/ReactIncrementalSideEffects-test.internal.js b/packages/react-reconciler/src/__tests__/ReactIncrementalSideEffects-test.internal.js index e96f61f88b7c4..c5c4afeb78d4c 100644 --- a/packages/react-reconciler/src/__tests__/ReactIncrementalSideEffects-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactIncrementalSideEffects-test.internal.js @@ -13,6 +13,7 @@ let React; let ReactFeatureFlags; let ReactNoop; +let Scheduler; describe('ReactIncrementalSideEffects', () => { beforeEach(() => { @@ -21,6 +22,7 @@ describe('ReactIncrementalSideEffects', () => { ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false; React = require('react'); ReactNoop = require('react-noop-renderer'); + Scheduler = require('scheduler'); }); function div(...children) { @@ -53,11 +55,11 @@ describe('ReactIncrementalSideEffects', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren()).toEqual([div(span())]); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren()).toEqual([div(span(), span())]); }); @@ -81,17 +83,17 @@ describe('ReactIncrementalSideEffects', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren()).toEqual([div(span(), span('test'))]); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren()).toEqual([ div(span(), span(), div(), span('test')), ]); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren()).toEqual([ div(span(), div(), span(), span('test')), ]); @@ -114,11 +116,11 @@ describe('ReactIncrementalSideEffects', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren()).toEqual([div('Hello')]); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren()).toEqual([div('World', 'World', '!')]); }); @@ -138,13 +140,13 @@ describe('ReactIncrementalSideEffects', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren()).toEqual([ div(div(), span('Hello'), 'World'), ]); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren()).toEqual([div()]); }); @@ -180,23 +182,23 @@ describe('ReactIncrementalSideEffects', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren()).toEqual([div(span('Class'), 'Trail')]); expect(unmounted).toBe(false); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren()).toEqual([div(span('Function'), 'Trail')]); expect(unmounted).toBe(true); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren()).toEqual([div('Text', 'Trail')]); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren()).toEqual([div('Trail')]); }); @@ -230,19 +232,19 @@ describe('ReactIncrementalSideEffects', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren()).toEqual([div(span('Class'), 'Trail')]); expect(unmounted).toBe(false); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren()).toEqual([div(span('Function'), 'Trail')]); expect(unmounted).toBe(true); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren()).toEqual([div('Trail')]); }); @@ -267,7 +269,7 @@ describe('ReactIncrementalSideEffects', () => { , ); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren()).toEqual([div()]); expect(ReactNoop.getChildren('portalContainer')).toEqual([ div(), @@ -280,7 +282,7 @@ describe('ReactIncrementalSideEffects', () => { , ); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren()).toEqual([div()]); expect(ReactNoop.getChildren('portalContainer')).toEqual([]); @@ -289,7 +291,7 @@ describe('ReactIncrementalSideEffects', () => { , ); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren()).toEqual([div()]); expect(ReactNoop.getChildren('portalContainer')).toEqual([ div(), @@ -298,17 +300,17 @@ describe('ReactIncrementalSideEffects', () => { ]); ReactNoop.render(null); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren()).toEqual([]); expect(ReactNoop.getChildren('portalContainer')).toEqual([]); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren()).toEqual([]); expect(ReactNoop.getChildren('portalContainer')).toEqual([]); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren()).toEqual([]); expect(ReactNoop.getChildren('portalContainer')).toEqual([ div(), @@ -317,7 +319,7 @@ describe('ReactIncrementalSideEffects', () => { ]); ReactNoop.render(null); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren()).toEqual([]); expect(ReactNoop.getChildren('portalContainer')).toEqual([]); }); @@ -343,7 +345,7 @@ describe('ReactIncrementalSideEffects', () => { , ); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren()).toEqual([div()]); expect(ReactNoop.getChildren('portalContainer')).toEqual([ div(), @@ -352,12 +354,12 @@ describe('ReactIncrementalSideEffects', () => { ]); ReactNoop.render(null); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren()).toEqual([]); expect(ReactNoop.getChildren('portalContainer')).toEqual([]); ReactNoop.render(); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren()).toEqual([]); expect(ReactNoop.getChildren('portalContainer')).toEqual([ div(), @@ -366,7 +368,7 @@ describe('ReactIncrementalSideEffects', () => { ]); ReactNoop.render(null); - expect(ReactNoop).toFlushWithoutYielding(); + expect(Scheduler).toFlushWithoutYielding(); expect(ReactNoop.getChildren()).toEqual([]); expect(ReactNoop.getChildren('portalContainer')).toEqual([]); }); @@ -391,7 +393,7 @@ describe('ReactIncrementalSideEffects', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['Foo', 'Bar', 'Bar', 'Bar']); + expect(Scheduler).toFlushAndYield(['Foo', 'Bar', 'Bar', 'Bar']); expect(ReactNoop.getChildren()).toEqual([ div(div(span('Hello'), span('Hello')), span('Yo')), ]); @@ -399,7 +401,7 @@ describe('ReactIncrementalSideEffects', () => { ReactNoop.render(); // Flush some of the work without committing - expect(ReactNoop).toFlushAndYieldThrough(['Foo', 'Bar']); + expect(Scheduler).toFlushAndYieldThrough(['Foo', 'Bar']); expect(ReactNoop.getChildren()).toEqual([ div(div(span('Hello'), span('Hello')), span('Yo')), ]); @@ -423,7 +425,7 @@ describe('ReactIncrementalSideEffects', () => { } ReactNoop.render(); - expect(ReactNoop).toFlushAndYield(['Foo', 'Middle']); + expect(Scheduler).toFlushAndYield(['Foo', 'Middle']); expect(ReactNoop.getChildrenAsJSX()).toEqual(
@@ -434,7 +436,7 @@ describe('ReactIncrementalSideEffects', () => { ); ReactNoop.render(, () => ReactNoop.yield('commit')); - expect(ReactNoop).toFlushAndYieldThrough(['Foo', 'commit']); + expect(Scheduler).toFlushAndYieldThrough(['Foo', 'commit']); expect(ReactNoop.getChildrenAsJSX()).toEqual(
, ); - expect(ReactNoop).toFlushAndYield(['Middle']); + expect(Scheduler).toFlushAndYield(['Middle']); expect(ReactNoop.getChildrenAsJSX()).toEqual(