@samitouri / QOS-React-2 / commits / 69060e1da6

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.

Andrew Clark committed Feb 28, 2019 at 12:54 UTC 69060e1da6061af845162dcf6854a5d9af28350a
35 files changed +1184 -1277
packages/create-subscription/src/__tests__/createSubscription-test.internal.js
+30 -28
@@ -14,6 +14,7 @@ let BehaviorSubject;
14 let ReactFeatureFlags;
15 let React;
16 let ReactNoop;
17 +let Scheduler;
18 let ReplaySubject;
19
20 describe('createSubscription', () => {
@@ -24,6 +25,7 @@ describe('createSubscription', () => {
25 ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false;
26 React = require('react');
27 ReactNoop = require('react-noop-renderer');
28 + Scheduler = require('scheduler');
29
30 BehaviorSubject = require('rxjs/BehaviorSubject').BehaviorSubject;
31 ReplaySubject = require('rxjs/ReplaySubject').ReplaySubject;
@@ -65,16 +67,16 @@ describe('createSubscription', () => {
67 );
68
69 // Updates while subscribed should re-render the child component
68 - expect(ReactNoop).toFlushAndYield(['default']);
70 + expect(Scheduler).toFlushAndYield(['default']);
71 observable.next(123);
70 - expect(ReactNoop).toFlushAndYield([123]);
72 + expect(Scheduler).toFlushAndYield([123]);
73 observable.next('abc');
72 - expect(ReactNoop).toFlushAndYield(['abc']);
74 + expect(Scheduler).toFlushAndYield(['abc']);
75
76 // Unmounting the subscriber should remove listeners
77 ReactNoop.render(<div />);
78 observable.next(456);
77 - expect(ReactNoop).toFlushAndYield([]);
79 + expect(Scheduler).toFlushAndYield([]);
80 });
81
82 it('should support observable types like RxJS ReplaySubject', () => {
@@ -102,13 +104,13 @@ describe('createSubscription', () => {
104 const observable = createReplaySubject('initial');
105
106 ReactNoop.render(<Subscription source={observable}>{render}</Subscription>);
105 - expect(ReactNoop).toFlushAndYield(['initial']);
107 + expect(Scheduler).toFlushAndYield(['initial']);
108 observable.next('updated');
107 - expect(ReactNoop).toFlushAndYield(['updated']);
109 + expect(Scheduler).toFlushAndYield(['updated']);
110
111 // Unsetting the subscriber prop should reset subscribed values
112 ReactNoop.render(<Subscription>{render}</Subscription>);
111 - expect(ReactNoop).toFlushAndYield(['default']);
113 + expect(Scheduler).toFlushAndYield(['default']);
114 });
115
116 describe('Promises', () => {
@@ -141,19 +143,19 @@ describe('createSubscription', () => {
143
144 // Test a promise that resolves after render
145 ReactNoop.render(<Subscription source={promiseA}>{render}</Subscription>);
144 - expect(ReactNoop).toFlushAndYield(['loading']);
146 + expect(Scheduler).toFlushAndYield(['loading']);
147 resolveA(true);
148 await promiseA;
147 - expect(ReactNoop).toFlushAndYield(['finished']);
149 + expect(Scheduler).toFlushAndYield(['finished']);
150
151 // Test a promise that resolves before render
152 // Note that this will require an extra render anyway,
153 // Because there is no way to synchronously get a Promise's value
154 rejectB(false);
155 ReactNoop.render(<Subscription source={promiseB}>{render}</Subscription>);
154 - expect(ReactNoop).toFlushAndYield(['loading']);
156 + expect(Scheduler).toFlushAndYield(['loading']);
157 await promiseB.catch(() => true);
156 - expect(ReactNoop).toFlushAndYield(['failed']);
158 + expect(Scheduler).toFlushAndYield(['failed']);
159 });
160
161 it('should still work if unsubscription is managed incorrectly', async () => {
@@ -177,9 +179,9 @@ describe('createSubscription', () => {
179
180 // Subscribe first to Promise A then Promise B
181 ReactNoop.render(<Subscription source={promiseA}>{render}</Subscription>);
180 - expect(ReactNoop).toFlushAndYield(['default']);
182 + expect(Scheduler).toFlushAndYield(['default']);
183 ReactNoop.render(<Subscription source={promiseB}>{render}</Subscription>);
182 - expect(ReactNoop).toFlushAndYield(['default']);
184 + expect(Scheduler).toFlushAndYield(['default']);
185
186 // Resolve both Promises
187 resolveB(123);
@@ -187,7 +189,7 @@ describe('createSubscription', () => {
189 await Promise.all([promiseA, promiseB]);
190
191 // Ensure that only Promise B causes an update
190 - expect(ReactNoop).toFlushAndYield([123]);
192 + expect(Scheduler).toFlushAndYield([123]);
193 });
194
195 it('should not call setState for a Promise that resolves after unmount', async () => {
@@ -211,11 +213,11 @@ describe('createSubscription', () => {
213 });
214
215 ReactNoop.render(<Subscription source={promise}>{render}</Subscription>);
214 - expect(ReactNoop).toFlushAndYield(['rendered']);
216 + expect(Scheduler).toFlushAndYield(['rendered']);
217
218 // Unmount
219 ReactNoop.render(null);
218 - expect(ReactNoop).toFlushWithoutYielding();
220 + expect(Scheduler).toFlushWithoutYielding();
221
222 // Resolve Promise should not trigger a setState warning
223 resolvePromise(true);
@@ -245,21 +247,21 @@ describe('createSubscription', () => {
247 );
248
249 // Updates while subscribed should re-render the child component
248 - expect(ReactNoop).toFlushAndYield(['a-0']);
250 + expect(Scheduler).toFlushAndYield(['a-0']);
251
252 // Unsetting the subscriber prop should reset subscribed values
253 ReactNoop.render(
254 <Subscription source={observableB}>{render}</Subscription>,
255 );
254 - expect(ReactNoop).toFlushAndYield(['b-0']);
256 + expect(Scheduler).toFlushAndYield(['b-0']);
257
258 // Updates to the old subscribable should not re-render the child component
259 observableA.next('a-1');
258 - expect(ReactNoop).toFlushAndYield([]);
260 + expect(Scheduler).toFlushAndYield([]);
261
262 // Updates to the bew subscribable should re-render the child component
263 observableB.next('b-1');
262 - expect(ReactNoop).toFlushAndYield(['b-1']);
264 + expect(Scheduler).toFlushAndYield(['b-1']);
265 });
266
267 it('should ignore values emitted by a new subscribable until the commit phase', () => {
@@ -315,12 +317,12 @@ describe('createSubscription', () => {
317 const observableB = createBehaviorSubject('b-0');
318
319 ReactNoop.render(<Parent observed={observableA} />);
318 - expect(ReactNoop).toFlushAndYield(['Subscriber: a-0', 'Child: a-0']);
320 + expect(Scheduler).toFlushAndYield(['Subscriber: a-0', 'Child: a-0']);
321 expect(log).toEqual(['Parent.componentDidMount']);
322
323 // Start React update, but don't finish
324 ReactNoop.render(<Parent observed={observableB} />);
323 - expect(ReactNoop).toFlushAndYieldThrough(['Subscriber: b-0']);
325 + expect(Scheduler).toFlushAndYieldThrough(['Subscriber: b-0']);
326 expect(log).toEqual(['Parent.componentDidMount']);
327
328 // Emit some updates from the uncommitted subscribable
@@ -335,7 +337,7 @@ describe('createSubscription', () => {
337 // We expect the last emitted update to be rendered (because of the commit phase value check)
338 // But the intermediate ones should be ignored,
339 // And the final rendered output should be the higher-priority observable.
338 - expect(ReactNoop).toFlushAndYield([
340 + expect(Scheduler).toFlushAndYield([
341 'Child: b-0',
342 'Subscriber: b-3',
343 'Child: b-3',
@@ -402,12 +404,12 @@ describe('createSubscription', () => {
404 const observableB = createBehaviorSubject('b-0');
405
406 ReactNoop.render(<Parent observed={observableA} />);
405 - expect(ReactNoop).toFlushAndYield(['Subscriber: a-0', 'Child: a-0']);
407 + expect(Scheduler).toFlushAndYield(['Subscriber: a-0', 'Child: a-0']);
408 expect(log).toEqual(['Parent.componentDidMount']);
409
410 // Start React update, but don't finish
411 ReactNoop.render(<Parent observed={observableB} />);
410 - expect(ReactNoop).toFlushAndYieldThrough(['Subscriber: b-0']);
412 + expect(Scheduler).toFlushAndYieldThrough(['Subscriber: b-0']);
413 expect(log).toEqual(['Parent.componentDidMount']);
414
415 // Emit some updates from the old subscribable
@@ -420,7 +422,7 @@ describe('createSubscription', () => {
422 // Flush everything and ensure that the correct subscribable is used
423 // We expect the new subscribable to finish rendering,
424 // But then the updated values from the old subscribable should be used.
423 - expect(ReactNoop).toFlushAndYield([
425 + expect(Scheduler).toFlushAndYield([
426 'Child: b-0',
427 'Subscriber: a-2',
428 'Child: a-2',
@@ -433,7 +435,7 @@ describe('createSubscription', () => {
435
436 // Updates from the new subscribable should be ignored.
437 observableB.next('b-1');
436 - expect(ReactNoop).toFlushAndYield([]);
438 + expect(Scheduler).toFlushAndYield([]);
439 expect(log).toEqual([
440 'Parent.componentDidMount',
441 'Parent.componentDidUpdate',
@@ -479,7 +481,7 @@ describe('createSubscription', () => {
481 <Subscription source={observable}>{value => null}</Subscription>,
482 );
483
482 - expect(ReactNoop).toFlushAndThrow(
484 + expect(Scheduler).toFlushAndThrow(
485 'A subscription must return an unsubscribe function.',
486 );
487 });
packages/jest-react/src/JestReact.js
-48
@@ -35,54 +35,6 @@ function assertYieldsWereCleared(root) {
35 );
36 }
37
38 -export function unstable_toFlushAndYield(root, expectedYields) {
39 - assertYieldsWereCleared(root);
40 - const actualYields = root.unstable_flushAll();
41 - return captureAssertion(() => {
42 - expect(actualYields).toEqual(expectedYields);
43 - });
44 -}
45 -
46 -export function unstable_toFlushAndYieldThrough(root, expectedYields) {
47 - assertYieldsWereCleared(root);
48 - const actualYields = root.unstable_flushNumberOfYields(expectedYields.length);
49 - return captureAssertion(() => {
50 - expect(actualYields).toEqual(expectedYields);
51 - });
52 -}
53 -
54 -export function unstable_toFlushWithoutYielding(root) {
55 - return unstable_toFlushAndYield(root, []);
56 -}
57 -
58 -export function unstable_toHaveYielded(ReactTestRenderer, expectedYields) {
59 - return captureAssertion(() => {
60 - if (
61 - ReactTestRenderer === null ||
62 - typeof ReactTestRenderer !== 'object' ||
63 - typeof ReactTestRenderer.unstable_setNowImplementation !== 'function'
64 - ) {
65 - invariant(
66 - false,
67 - 'The matcher `unstable_toHaveYielded` expects an instance of React Test ' +
68 - 'Renderer.\n\nTry: ' +
69 - 'expect(ReactTestRenderer).unstable_toHaveYielded(expectedYields)',
70 - );
71 - }
72 - const actualYields = ReactTestRenderer.unstable_clearYields();
73 - expect(actualYields).toEqual(expectedYields);
74 - });
75 -}
76 -
77 -export function unstable_toFlushAndThrow(root, ...rest) {
78 - assertYieldsWereCleared(root);
79 - return captureAssertion(() => {
80 - expect(() => {
81 - root.unstable_flushAll();
82 - }).toThrow(...rest);
83 - });
84 -}
85 -
38 export function unstable_toMatchRenderedOutput(root, expectedJSX) {
39 assertYieldsWereCleared(root);
40 const actualJSON = root.toJSON();
packages/react-art/src/__tests__/ReactART-test.js
+3 -2
@@ -31,6 +31,7 @@ const Wedge = require('react-art/Wedge');
31 // Isolate the noop renderer
32 jest.resetModules();
33 const ReactNoop = require('react-noop-renderer');
34 +const Scheduler = require('scheduler');
35
36 let Group;
37 let Shape;
@@ -385,7 +386,7 @@ describe('ReactART', () => {
386 </CurrentRendererContext.Provider>,
387 );
388
388 - expect(ReactNoop).toFlushAndYieldThrough(['A']);
389 + expect(Scheduler).toFlushAndYieldThrough(['A']);
390
391 ReactDOM.render(
392 <Surface>
@@ -400,7 +401,7 @@ describe('ReactART', () => {
401 expect(ops).toEqual([null, 'ART']);
402
403 ops = [];
403 - expect(ReactNoop).toFlushAndYield(['B', 'C']);
404 + expect(Scheduler).toFlushAndYield(['B', 'C']);
405
406 expect(ops).toEqual(['Test']);
407 });
packages/react-cache/src/__tests__/ReactCache-test.internal.js
+28 -28
@@ -107,15 +107,15 @@ describe('ReactCache', () => {
107 );
108 }
109
110 - const root = ReactTestRenderer.create(<App />, {
110 + ReactTestRenderer.create(<App />, {
111 unstable_isConcurrent: true,
112 });
113
114 - expect(root).toFlushAndYield(['Suspend! [Hi]', 'Loading...']);
114 + expect(Scheduler).toFlushAndYield(['Suspend! [Hi]', 'Loading...']);
115
116 jest.advanceTimersByTime(100);
117 - expect(ReactTestRenderer).toHaveYielded(['Promise resolved [Hi]']);
118 - expect(root).toFlushAndYield(['Hi']);
117 + expect(Scheduler).toHaveYielded(['Promise resolved [Hi]']);
118 + expect(Scheduler).toFlushAndYield(['Hi']);
119 });
120
121 it('throws an error on the subsequent read if the promise is rejected', async () => {
@@ -131,19 +131,19 @@ describe('ReactCache', () => {
131 unstable_isConcurrent: true,
132 });
133
134 - expect(root).toFlushAndYield(['Suspend! [Hi]', 'Loading...']);
134 + expect(Scheduler).toFlushAndYield(['Suspend! [Hi]', 'Loading...']);
135
136 textResourceShouldFail = true;
137 jest.advanceTimersByTime(100);
138 - expect(ReactTestRenderer).toHaveYielded(['Promise rejected [Hi]']);
138 + expect(Scheduler).toHaveYielded(['Promise rejected [Hi]']);
139
140 - expect(root).toFlushAndThrow('Failed to load: Hi');
141 - expect(ReactTestRenderer).toHaveYielded(['Error! [Hi]', 'Error! [Hi]']);
140 + expect(Scheduler).toFlushAndThrow('Failed to load: Hi');
141 + expect(Scheduler).toHaveYielded(['Error! [Hi]', 'Error! [Hi]']);
142
143 // Should throw again on a subsequent read
144 root.update(<App />);
145 - expect(root).toFlushAndThrow('Failed to load: Hi');
146 - expect(ReactTestRenderer).toHaveYielded(['Error! [Hi]', 'Error! [Hi]']);
145 + expect(Scheduler).toFlushAndThrow('Failed to load: Hi');
146 + expect(Scheduler).toHaveYielded(['Error! [Hi]', 'Error! [Hi]']);
147 });
148
149 it('warns if non-primitive key is passed to a resource without a hash function', () => {
@@ -160,7 +160,7 @@ describe('ReactCache', () => {
160 return BadTextResource.read(['Hi', 100]);
161 }
162
163 - const root = ReactTestRenderer.create(
163 + ReactTestRenderer.create(
164 <Suspense fallback={<Text text="Loading..." />}>
165 <App />
166 </Suspense>,
@@ -171,7 +171,7 @@ describe('ReactCache', () => {
171
172 if (__DEV__) {
173 expect(() => {
174 - expect(root).toFlushAndYield(['App', 'Loading...']);
174 + expect(Scheduler).toFlushAndYield(['App', 'Loading...']);
175 }).toWarnDev(
176 [
177 'Invalid key type. Expected a string, number, symbol, or ' +
@@ -182,7 +182,7 @@ describe('ReactCache', () => {
182 {withoutStack: true},
183 );
184 } else {
185 - expect(root).toFlushAndYield(['App', 'Loading...']);
185 + expect(Scheduler).toFlushAndYield(['App', 'Loading...']);
186 }
187 });
188
@@ -200,19 +200,19 @@ describe('ReactCache', () => {
200 unstable_isConcurrent: true,
201 },
202 );
203 - expect(root).toFlushAndYield([
203 + expect(Scheduler).toFlushAndYield([
204 'Suspend! [1]',
205 'Suspend! [2]',
206 'Suspend! [3]',
207 'Loading...',
208 ]);
209 jest.advanceTimersByTime(100);
210 - expect(ReactTestRenderer).toHaveYielded([
210 + expect(Scheduler).toHaveYielded([
211 'Promise resolved [1]',
212 'Promise resolved [2]',
213 'Promise resolved [3]',
214 ]);
215 - expect(root).toFlushAndYield([1, 2, 3]);
215 + expect(Scheduler).toFlushAndYield([1, 2, 3]);
216 expect(root).toMatchRenderedOutput('123');
217
218 // Render 1, 4, 5
@@ -224,18 +224,18 @@ describe('ReactCache', () => {
224 </Suspense>,
225 );
226
227 - expect(root).toFlushAndYield([
227 + expect(Scheduler).toFlushAndYield([
228 1,
229 'Suspend! [4]',
230 'Suspend! [5]',
231 'Loading...',
232 ]);
233 jest.advanceTimersByTime(100);
234 - expect(ReactTestRenderer).toHaveYielded([
234 + expect(Scheduler).toHaveYielded([
235 'Promise resolved [4]',
236 'Promise resolved [5]',
237 ]);
238 - expect(root).toFlushAndYield([1, 4, 5]);
238 + expect(Scheduler).toFlushAndYield([1, 4, 5]);
239 expect(root).toMatchRenderedOutput('145');
240
241 // We've now rendered values 1, 2, 3, 4, 5, over our limit of 3. The least
@@ -249,7 +249,7 @@ describe('ReactCache', () => {
249 </Suspense>,
250 );
251
252 - expect(root).toFlushAndYield([
252 + expect(Scheduler).toFlushAndYield([
253 // 1 is still cached
254 1,
255 // 2 and 3 suspend because they were evicted from the cache
@@ -258,11 +258,11 @@ describe('ReactCache', () => {
258 'Loading...',
259 ]);
260 jest.advanceTimersByTime(100);
261 - expect(ReactTestRenderer).toHaveYielded([
261 + expect(Scheduler).toHaveYielded([
262 'Promise resolved [2]',
263 'Promise resolved [3]',
264 ]);
265 - expect(root).toFlushAndYield([1, 2, 3]);
265 + expect(Scheduler).toFlushAndYield([1, 2, 3]);
266 expect(root).toMatchRenderedOutput('123');
267 });
268
@@ -283,14 +283,14 @@ describe('ReactCache', () => {
283 },
284 );
285
286 - expect(root).toFlushAndYield(['Loading...']);
286 + expect(Scheduler).toFlushAndYield(['Loading...']);
287
288 jest.advanceTimersByTime(1000);
289 - expect(ReactTestRenderer).toHaveYielded([
289 + expect(Scheduler).toHaveYielded([
290 'Promise resolved [B]',
291 'Promise resolved [A]',
292 ]);
293 - expect(root).toFlushAndYield(['Result']);
293 + expect(Scheduler).toFlushAndYield(['Result']);
294 expect(root).toMatchRenderedOutput('Result');
295 });
296
@@ -342,7 +342,7 @@ describe('ReactCache', () => {
342 },
343 );
344
345 - expect(root).toFlushAndYield(['Suspend! [Hi]', 'Loading...']);
345 + expect(Scheduler).toFlushAndYield(['Suspend! [Hi]', 'Loading...']);
346
347 resolveThenable('Hi');
348 // This thenable improperly resolves twice. We should not update the
@@ -358,8 +358,8 @@ describe('ReactCache', () => {
358 },
359 );
360
361 - expect(ReactTestRenderer).toHaveYielded([]);
362 - expect(root).toFlushAndYield(['Hi']);
361 + expect(Scheduler).toHaveYielded([]);
362 + expect(Scheduler).toFlushAndYield(['Hi']);
363 expect(root).toMatchRenderedOutput('Hi');
364 });
365
packages/react-reconciler/src/__tests__/ReactExpiration-test.internal.js
+11 -11
@@ -74,7 +74,7 @@ describe('ReactExpiration', () => {
74 // Advance the timer.
75 Scheduler.advanceTime(2000);
76 // Partially flush the the first update, then interrupt it.
77 - expect(ReactNoop).toFlushAndYieldThrough(['A [render]']);
77 + expect(Scheduler).toFlushAndYieldThrough(['A [render]']);
78 interrupt();
79
80 // Don't advance time by enough to expire the first update.
@@ -89,7 +89,7 @@ describe('ReactExpiration', () => {
89 // batch these two updates together. The fact that they aren't batched
90 // is an implementation detail. The important part of this unit test is that
91 // they are batched if it's possible that they happened in the same event.
92 - expect(ReactNoop).toFlushAndYield([
92 + expect(Scheduler).toFlushAndYield([
93 'A [render]',
94 'A [commit]',
95 'B [render]',
@@ -101,13 +101,13 @@ describe('ReactExpiration', () => {
101 // between the two updates.
102 ReactNoop.render(<Text text="A" />);
103 Scheduler.advanceTime(2000);
104 - expect(ReactNoop).toHaveYielded([]);
104 + expect(Scheduler).toHaveYielded([]);
105 expect(ReactNoop.getChildren()).toEqual([span('B')]);
106 // Schedule another update.
107 ReactNoop.render(<Text text="B" />);
108 // The updates should flush in the same batch, since as far as the scheduler
109 // knows, they may have occurred inside the same event.
110 - expect(ReactNoop).toFlushAndYield(['B [render]', 'B [commit]']);
110 + expect(Scheduler).toFlushAndYield(['B [render]', 'B [commit]']);
111 });
112
113 it(
@@ -139,7 +139,7 @@ describe('ReactExpiration', () => {
139 // Advance the timer.
140 Scheduler.advanceTime(2000);
141 // Partially flush the the first update, then interrupt it.
142 - expect(ReactNoop).toFlushAndYieldThrough(['A [render]']);
142 + expect(Scheduler).toFlushAndYieldThrough(['A [render]']);
143 interrupt();
144
145 // Don't advance time by enough to expire the first update.
@@ -154,7 +154,7 @@ describe('ReactExpiration', () => {
154 // batch these two updates together. The fact that they aren't batched
155 // is an implementation detail. The important part of this unit test is that
156 // they are batched if it's possible that they happened in the same event.
157 - expect(ReactNoop).toFlushAndYield([
157 + expect(Scheduler).toFlushAndYield([
158 'A [render]',
159 'A [commit]',
160 'B [render]',
@@ -166,7 +166,7 @@ describe('ReactExpiration', () => {
166 // between the two updates.
167 ReactNoop.render(<Text text="A" />);
168 Scheduler.advanceTime(2000);
169 - expect(ReactNoop).toHaveYielded([]);
169 + expect(Scheduler).toHaveYielded([]);
170 expect(ReactNoop.getChildren()).toEqual([span('B')]);
171
172 // Perform some synchronous work. The scheduler must assume we're inside
@@ -177,7 +177,7 @@ describe('ReactExpiration', () => {
177 ReactNoop.render(<Text text="B" />);
178 // The updates should flush in the same batch, since as far as the scheduler
179 // knows, they may have occurred inside the same event.
180 - expect(ReactNoop).toFlushAndYield(['B [render]', 'B [commit]']);
180 + expect(Scheduler).toFlushAndYield(['B [render]', 'B [commit]']);
181 },
182 );
183
@@ -212,7 +212,7 @@ describe('ReactExpiration', () => {
212
213 // Initial mount
214 ReactNoop.render(<App />);
215 - expect(ReactNoop).toFlushAndYield([
215 + expect(Scheduler).toFlushAndYield([
216 'initial [A] [render]',
217 'initial [B] [render]',
218 'initial [C] [render]',
@@ -225,7 +225,7 @@ describe('ReactExpiration', () => {
225
226 // Partial update
227 subscribers.forEach(s => s.setState({text: '1'}));
228 - expect(ReactNoop).toFlushAndYieldThrough([
228 + expect(Scheduler).toFlushAndYieldThrough([
229 '1 [A] [render]',
230 '1 [B] [render]',
231 ]);
@@ -234,7 +234,7 @@ describe('ReactExpiration', () => {
234 // advanced, this update should be given a different expiration time than
235 // the currently rendering one. So, C and D should render with 1, not 2.
236 subscribers.forEach(s => s.setState({text: '2'}));
237 - expect(ReactNoop).toFlushAndYieldThrough([
237 + expect(Scheduler).toFlushAndYieldThrough([
238 '1 [C] [render]',
239 '1 [D] [render]',
240 ]);
packages/react-reconciler/src/__tests__/ReactFragment-test.js
+54 -52
@@ -11,6 +11,7 @@
11
12 let React;
13 let ReactNoop;
14 +let Scheduler;
15
16 describe('ReactFragment', () => {
17 beforeEach(function() {
@@ -18,6 +19,7 @@ describe('ReactFragment', () => {
19
20 React = require('react');
21 ReactNoop = require('react-noop-renderer');
22 + Scheduler = require('scheduler');
23 });
24
25 function div(...children) {
@@ -43,7 +45,7 @@ describe('ReactFragment', () => {
45 );
46
47 ReactNoop.render(element);
46 - expect(ReactNoop).toFlushWithoutYielding();
48 + expect(Scheduler).toFlushWithoutYielding();
49
50 expect(ReactNoop.getChildren()).toEqual([span()]);
51 });
@@ -52,7 +54,7 @@ describe('ReactFragment', () => {
54 const element = <React.Fragment />;
55
56 ReactNoop.render(element);
55 - expect(ReactNoop).toFlushWithoutYielding();
57 + expect(Scheduler).toFlushWithoutYielding();
58
59 expect(ReactNoop.getChildren()).toEqual([]);
60 });
@@ -65,7 +67,7 @@ describe('ReactFragment', () => {
67 );
68
69 ReactNoop.render(element);
68 - expect(ReactNoop).toFlushWithoutYielding();
70 + expect(Scheduler).toFlushWithoutYielding();
71
72 expect(ReactNoop.getChildren()).toEqual([text('hello '), span()]);
73 });
@@ -78,7 +80,7 @@ describe('ReactFragment', () => {
80 );
81
82 ReactNoop.render(element);
81 - expect(ReactNoop).toFlushWithoutYielding();
83 + expect(Scheduler).toFlushWithoutYielding();
84
85 expect(ReactNoop.getChildren()).toEqual([span(), span()]);
86 });
@@ -108,16 +110,16 @@ describe('ReactFragment', () => {
110 }
111
112 ReactNoop.render(<Foo condition={true} />);
111 - expect(ReactNoop).toFlushWithoutYielding();
113 + expect(Scheduler).toFlushWithoutYielding();
114
115 ReactNoop.render(<Foo condition={false} />);
114 - expect(ReactNoop).toFlushWithoutYielding();
116 + expect(Scheduler).toFlushWithoutYielding();
117
118 expect(ops).toEqual(['Update Stateful']);
119 expect(ReactNoop.getChildren()).toEqual([div(), div()]);
120
121 ReactNoop.render(<Foo condition={true} />);
120 - expect(ReactNoop).toFlushWithoutYielding();
122 + expect(Scheduler).toFlushWithoutYielding();
123
124 expect(ops).toEqual(['Update Stateful', 'Update Stateful']);
125 expect(ReactNoop.getChildren()).toEqual([div()]);
@@ -149,16 +151,16 @@ describe('ReactFragment', () => {
151 }
152
153 ReactNoop.render(<Foo condition={true} />);
152 - expect(ReactNoop).toFlushWithoutYielding();
154 + expect(Scheduler).toFlushWithoutYielding();
155
156 ReactNoop.render(<Foo condition={false} />);
155 - expect(ReactNoop).toFlushWithoutYielding();
157 + expect(Scheduler).toFlushWithoutYielding();
158
159 expect(ops).toEqual(['Update Stateful']);
160 expect(ReactNoop.getChildren()).toEqual([div()]);
161
162 ReactNoop.render(<Foo condition={true} />);
161 - expect(ReactNoop).toFlushWithoutYielding();
163 + expect(Scheduler).toFlushWithoutYielding();
164
165 expect(ops).toEqual(['Update Stateful', 'Update Stateful']);
166 expect(ReactNoop.getChildren()).toEqual([div()]);
@@ -199,16 +201,16 @@ describe('ReactFragment', () => {
201 }
202
203 ReactNoop.render(<Foo condition={true} />);
202 - expect(ReactNoop).toFlushWithoutYielding();
204 + expect(Scheduler).toFlushWithoutYielding();
205
206 ReactNoop.render(<Foo condition={false} />);
205 - expect(ReactNoop).toFlushWithoutYielding();
207 + expect(Scheduler).toFlushWithoutYielding();
208
209 expect(ops).toEqual(['Update Stateful']);
210 expect(ReactNoop.getChildren()).toEqual([div(), div()]);
211
212 ReactNoop.render(<Foo condition={true} />);
211 - expect(ReactNoop).toFlushWithoutYielding();
213 + expect(Scheduler).toFlushWithoutYielding();
214
215 expect(ops).toEqual(['Update Stateful', 'Update Stateful']);
216 expect(ReactNoop.getChildren()).toEqual([div()]);
@@ -242,16 +244,16 @@ describe('ReactFragment', () => {
244 }
245
246 ReactNoop.render(<Foo condition={true} />);
245 - expect(ReactNoop).toFlushWithoutYielding();
247 + expect(Scheduler).toFlushWithoutYielding();
248
249 ReactNoop.render(<Foo condition={false} />);
248 - expect(ReactNoop).toFlushWithoutYielding();
250 + expect(Scheduler).toFlushWithoutYielding();
251
252 expect(ops).toEqual([]);
253 expect(ReactNoop.getChildren()).toEqual([div()]);
254
255 ReactNoop.render(<Foo condition={true} />);
254 - expect(ReactNoop).toFlushWithoutYielding();
256 + expect(Scheduler).toFlushWithoutYielding();
257
258 expect(ops).toEqual([]);
259 expect(ReactNoop.getChildren()).toEqual([div()]);
@@ -283,16 +285,16 @@ describe('ReactFragment', () => {
285 }
286
287 ReactNoop.render(<Foo condition={true} />);
286 - expect(ReactNoop).toFlushWithoutYielding();
288 + expect(Scheduler).toFlushWithoutYielding();
289
290 ReactNoop.render(<Foo condition={false} />);
289 - expect(ReactNoop).toFlushWithoutYielding();
291 + expect(Scheduler).toFlushWithoutYielding();
292
293 expect(ops).toEqual([]);
294 expect(ReactNoop.getChildren()).toEqual([div()]);
295
296 ReactNoop.render(<Foo condition={true} />);
295 - expect(ReactNoop).toFlushWithoutYielding();
297 + expect(Scheduler).toFlushWithoutYielding();
298
299 expect(ops).toEqual([]);
300 expect(ReactNoop.getChildren()).toEqual([div()]);
@@ -325,16 +327,16 @@ describe('ReactFragment', () => {
327 }
328
329 ReactNoop.render(<Foo condition={true} />);
328 - expect(ReactNoop).toFlushWithoutYielding();
330 + expect(Scheduler).toFlushWithoutYielding();
331
332 ReactNoop.render(<Foo condition={false} />);
331 - expect(ReactNoop).toFlushWithoutYielding();
333 + expect(Scheduler).toFlushWithoutYielding();
334
335 expect(ops).toEqual([]);
336 expect(ReactNoop.getChildren()).toEqual([div(), div()]);
337
338 ReactNoop.render(<Foo condition={true} />);
337 - expect(ReactNoop).toFlushWithoutYielding();
339 + expect(Scheduler).toFlushWithoutYielding();
340
341 expect(ops).toEqual([]);
342 expect(ReactNoop.getChildren()).toEqual([div()]);
@@ -364,16 +366,16 @@ describe('ReactFragment', () => {
366 }
367
368 ReactNoop.render(<Foo condition={true} />);
367 - expect(ReactNoop).toFlushWithoutYielding();
369 + expect(Scheduler).toFlushWithoutYielding();
370
371 ReactNoop.render(<Foo condition={false} />);
370 - expect(ReactNoop).toFlushWithoutYielding();
372 + expect(Scheduler).toFlushWithoutYielding();
373
374 expect(ops).toEqual(['Update Stateful']);
375 expect(ReactNoop.getChildren()).toEqual([div()]);
376
377 ReactNoop.render(<Foo condition={true} />);
376 - expect(ReactNoop).toFlushWithoutYielding();
378 + expect(Scheduler).toFlushWithoutYielding();
379
380 expect(ops).toEqual(['Update Stateful', 'Update Stateful']);
381 expect(ReactNoop.getChildren()).toEqual([div()]);
@@ -403,16 +405,16 @@ describe('ReactFragment', () => {
405 }
406
407 ReactNoop.render(<Foo condition={true} />);
406 - expect(ReactNoop).toFlushWithoutYielding();
408 + expect(Scheduler).toFlushWithoutYielding();
409
410 ReactNoop.render(<Foo condition={false} />);
409 - expect(ReactNoop).toFlushWithoutYielding();
411 + expect(Scheduler).toFlushWithoutYielding();
412
413 expect(ops).toEqual(['Update Stateful']);
414 expect(ReactNoop.getChildren()).toEqual([div()]);
415
416 ReactNoop.render(<Foo condition={true} />);
415 - expect(ReactNoop).toFlushWithoutYielding();
417 + expect(Scheduler).toFlushWithoutYielding();
418
419 expect(ops).toEqual(['Update Stateful', 'Update Stateful']);
420 expect(ReactNoop.getChildren()).toEqual([div()]);
@@ -444,16 +446,16 @@ describe('ReactFragment', () => {
446 }
447
448 ReactNoop.render(<Foo condition={true} />);
447 - expect(ReactNoop).toFlushWithoutYielding();
449 + expect(Scheduler).toFlushWithoutYielding();
450
451 ReactNoop.render(<Foo condition={false} />);
450 - expect(ReactNoop).toFlushWithoutYielding();
452 + expect(Scheduler).toFlushWithoutYielding();
453
454 expect(ops).toEqual([]);
455 expect(ReactNoop.getChildren()).toEqual([div()]);
456
457 ReactNoop.render(<Foo condition={true} />);
456 - expect(ReactNoop).toFlushWithoutYielding();
458 + expect(Scheduler).toFlushWithoutYielding();
459
460 expect(ops).toEqual([]);
461 expect(ReactNoop.getChildren()).toEqual([div()]);
@@ -481,16 +483,16 @@ describe('ReactFragment', () => {
483 }
484
485 ReactNoop.render(<Foo condition={true} />);
484 - expect(ReactNoop).toFlushWithoutYielding();
486 + expect(Scheduler).toFlushWithoutYielding();
487
488 ReactNoop.render(<Foo condition={false} />);
487 - expect(ReactNoop).toFlushWithoutYielding();
489 + expect(Scheduler).toFlushWithoutYielding();
490
491 expect(ops).toEqual([]);
492 expect(ReactNoop.getChildren()).toEqual([div()]);
493
494 ReactNoop.render(<Foo condition={true} />);
493 - expect(ReactNoop).toFlushWithoutYielding();
495 + expect(Scheduler).toFlushWithoutYielding();
496
497 expect(ops).toEqual([]);
498 expect(ReactNoop.getChildren()).toEqual([div()]);
@@ -522,16 +524,16 @@ describe('ReactFragment', () => {
524 }
525
526 ReactNoop.render(<Foo condition={true} />);
525 - expect(ReactNoop).toFlushWithoutYielding();
527 + expect(Scheduler).toFlushWithoutYielding();
528
529 ReactNoop.render(<Foo condition={false} />);
528 - expect(ReactNoop).toFlushWithoutYielding();
530 + expect(Scheduler).toFlushWithoutYielding();
531
532 expect(ops).toEqual(['Update Stateful']);
533 expect(ReactNoop.getChildren()).toEqual([div()]);
534
535 ReactNoop.render(<Foo condition={true} />);
534 - expect(ReactNoop).toFlushWithoutYielding();
536 + expect(Scheduler).toFlushWithoutYielding();
537
538 expect(ops).toEqual(['Update Stateful', 'Update Stateful']);
539 expect(ReactNoop.getChildren()).toEqual([div()]);
@@ -564,16 +566,16 @@ describe('ReactFragment', () => {
566 }
567
568 ReactNoop.render(<Foo condition={true} />);
567 - expect(ReactNoop).toFlushWithoutYielding();
569 + expect(Scheduler).toFlushWithoutYielding();
570
571 ReactNoop.render(<Foo condition={false} />);
570 - expect(ReactNoop).toFlushWithoutYielding();
572 + expect(Scheduler).toFlushWithoutYielding();
573
574 expect(ops).toEqual([]);
575 expect(ReactNoop.getChildren()).toEqual([div(), span()]);
576
577 ReactNoop.render(<Foo condition={true} />);
576 - expect(ReactNoop).toFlushWithoutYielding();
578 + expect(Scheduler).toFlushWithoutYielding();
579
580 expect(ops).toEqual([]);
581 expect(ReactNoop.getChildren()).toEqual([div()]);
@@ -605,16 +607,16 @@ describe('ReactFragment', () => {
607 }
608
609 ReactNoop.render(<Foo condition={true} />);
608 - expect(ReactNoop).toFlushWithoutYielding();
610 + expect(Scheduler).toFlushWithoutYielding();
611
612 ReactNoop.render(<Foo condition={false} />);
611 - expect(ReactNoop).toFlushWithoutYielding();
613 + expect(Scheduler).toFlushWithoutYielding();
614
615 expect(ops).toEqual([]);
616 expect(ReactNoop.getChildren()).toEqual([div()]);
617
618 ReactNoop.render(<Foo condition={true} />);
617 - expect(ReactNoop).toFlushWithoutYielding();
619 + expect(Scheduler).toFlushWithoutYielding();
620
621 expect(ops).toEqual([]);
622 expect(ReactNoop.getChildren()).toEqual([div()]);
@@ -658,16 +660,16 @@ describe('ReactFragment', () => {
660 }
661
662 ReactNoop.render(<Foo condition={true} />);
661 - expect(ReactNoop).toFlushWithoutYielding();
663 + expect(Scheduler).toFlushWithoutYielding();
664
665 ReactNoop.render(<Foo condition={false} />);
664 - expect(ReactNoop).toFlushWithoutYielding();
666 + expect(Scheduler).toFlushWithoutYielding();
667
668 expect(ops).toEqual(['Update Stateful']);
669 expect(ReactNoop.getChildren()).toEqual([div(span(), div(div()), span())]);
670
671 ReactNoop.render(<Foo condition={true} />);
670 - expect(ReactNoop).toFlushWithoutYielding();
672 + expect(Scheduler).toFlushWithoutYielding();
673
674 expect(ops).toEqual(['Update Stateful', 'Update Stateful']);
675 expect(ReactNoop.getChildren()).toEqual([div(span(), div(div()), span())]);
@@ -705,10 +707,10 @@ describe('ReactFragment', () => {
707 }
708
709 ReactNoop.render(<Foo condition={true} />);
708 - expect(ReactNoop).toFlushWithoutYielding();
710 + expect(Scheduler).toFlushWithoutYielding();
711
712 ReactNoop.render(<Foo condition={false} />);
711 - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev(
713 + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
714 'Each child in a list should have a unique "key" prop.',
715 );
716
@@ -716,7 +718,7 @@ describe('ReactFragment', () => {
718 expect(ReactNoop.getChildren()).toEqual([div(div(), span())]);
719
720 ReactNoop.render(<Foo condition={true} />);
719 - expect(ReactNoop).toFlushWithoutYielding();
721 + expect(Scheduler).toFlushWithoutYielding();
722
723 expect(ops).toEqual([]);
724 expect(ReactNoop.getChildren()).toEqual([div(div(), span())]);
@@ -752,12 +754,12 @@ describe('ReactFragment', () => {
754 }
755
756 ReactNoop.render(<Foo condition={true} />);
755 - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev(
757 + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
758 'Each child in a list should have a unique "key" prop.',
759 );
760
761 ReactNoop.render(<Foo condition={false} />);
760 - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev(
762 + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
763 'Each child in a list should have a unique "key" prop.',
764 );
765
@@ -765,7 +767,7 @@ describe('ReactFragment', () => {
767 expect(ReactNoop.getChildren()).toEqual([span(), div()]);
768
769 ReactNoop.render(<Foo condition={true} />);
768 - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev(
770 + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
771 'Each child in a list should have a unique "key" prop.',
772 );
773
packages/react-reconciler/src/__tests__/ReactHooks-test.internal.js
+44 -41
@@ -77,7 +77,7 @@ describe('ReactHooks', () => {
77
78 const root = ReactTestRenderer.create(null, {unstable_isConcurrent: true});
79 root.update(<Parent />);
80 - expect(root).toFlushAndYield([
80 + expect(Scheduler).toFlushAndYield([
81 'Parent: 0, 0',
82 'Child: 0, 0',
83 'Effect: 0, 0',
@@ -90,7 +90,7 @@ describe('ReactHooks', () => {
90 setCounter2(1);
91 });
92
93 - expect(root).toFlushAndYield([
93 + expect(Scheduler).toFlushAndYield([
94 'Parent: 1, 1',
95 'Child: 1, 1',
96 'Effect: 1, 1',
@@ -98,7 +98,7 @@ describe('ReactHooks', () => {
98
99 // Update that bails out.
100 act(() => setCounter1(1));
101 - expect(root).toFlushAndYield(['Parent: 1, 1']);
101 + expect(Scheduler).toFlushAndYield(['Parent: 1, 1']);
102
103 // This time, one of the state updates but the other one doesn't. So we
104 // can't bail out.
@@ -107,7 +107,7 @@ describe('ReactHooks', () => {
107 setCounter2(2);
108 });
109
110 - expect(root).toFlushAndYield([
110 + expect(Scheduler).toFlushAndYield([
111 'Parent: 1, 2',
112 'Child: 1, 2',
113 'Effect: 1, 2',
@@ -125,14 +125,14 @@ describe('ReactHooks', () => {
125
126 // Because the final values are the same as the current values, the
127 // component bails out.
128 - expect(root).toFlushAndYield(['Parent: 1, 2']);
128 + expect(Scheduler).toFlushAndYield(['Parent: 1, 2']);
129
130 // prepare to check SameValue
131 act(() => {
132 setCounter1(0 / -1);
133 setCounter2(NaN);
134 });
135 - expect(root).toFlushAndYield([
135 + expect(Scheduler).toFlushAndYield([
136 'Parent: 0, NaN',
137 'Child: 0, NaN',
138 'Effect: 0, NaN',
@@ -146,13 +146,13 @@ describe('ReactHooks', () => {
146 setCounter2(NaN);
147 });
148
149 - expect(root).toFlushAndYield(['Parent: 0, NaN']);
149 + expect(Scheduler).toFlushAndYield(['Parent: 0, NaN']);
150
151 // check if changing negative 0 to positive 0 does not bail out
152 act(() => {
153 setCounter1(0);
154 });
155 - expect(root).toFlushAndYield([
155 + expect(Scheduler).toFlushAndYield([
156 'Parent: 0, NaN',
157 'Child: 0, NaN',
158 'Effect: 0, NaN',
@@ -184,7 +184,7 @@ describe('ReactHooks', () => {
184
185 const root = ReactTestRenderer.create(null, {unstable_isConcurrent: true});
186 root.update(<Parent theme="light" />);
187 - expect(root).toFlushAndYield([
187 + expect(Scheduler).toFlushAndYield([
188 'Parent: 0, 0 (light)',
189 'Child: 0, 0 (light)',
190 ]);
@@ -196,14 +196,14 @@ describe('ReactHooks', () => {
196 setCounter2(1);
197 });
198
199 - expect(root).toFlushAndYield([
199 + expect(Scheduler).toFlushAndYield([
200 'Parent: 1, 1 (light)',
201 'Child: 1, 1 (light)',
202 ]);
203
204 // Update that bails out.
205 act(() => setCounter1(1));
206 - expect(root).toFlushAndYield(['Parent: 1, 1 (light)']);
206 + expect(Scheduler).toFlushAndYield(['Parent: 1, 1 (light)']);
207
208 // This time, one of the state updates but the other one doesn't. So we
209 // can't bail out.
@@ -212,7 +212,7 @@ describe('ReactHooks', () => {
212 setCounter2(2);
213 });
214
215 - expect(root).toFlushAndYield([
215 + expect(Scheduler).toFlushAndYield([
216 'Parent: 1, 2 (light)',
217 'Child: 1, 2 (light)',
218 ]);
@@ -225,7 +225,10 @@ describe('ReactHooks', () => {
225 });
226
227 root.update(<Parent theme="dark" />);
228 - expect(root).toFlushAndYield(['Parent: 1, 2 (dark)', 'Child: 1, 2 (dark)']);
228 + expect(Scheduler).toFlushAndYield([
229 + 'Parent: 1, 2 (dark)',
230 + 'Child: 1, 2 (dark)',
231 + ]);
232
233 // Both props and state bail out
234 act(() => {
@@ -234,7 +237,7 @@ describe('ReactHooks', () => {
237 });
238
239 root.update(<Parent theme="dark" />);
237 - expect(root).toFlushAndYield(['Parent: 1, 2 (dark)']);
240 + expect(Scheduler).toFlushAndYield(['Parent: 1, 2 (dark)']);
241 });
242
243 it('warns about setState second argument', () => {
@@ -251,7 +254,7 @@ describe('ReactHooks', () => {
254
255 const root = ReactTestRenderer.create(null, {unstable_isConcurrent: true});
256 root.update(<Counter />);
254 - expect(root).toFlushAndYield(['Count: 0']);
257 + expect(Scheduler).toFlushAndYield(['Count: 0']);
258 expect(root).toMatchRenderedOutput('0');
259
260 expect(() => {
@@ -267,7 +270,7 @@ describe('ReactHooks', () => {
270 'declare it in the component body with useEffect().',
271 {withoutStack: true},
272 );
270 - expect(root).toFlushAndYield(['Count: 1']);
273 + expect(Scheduler).toFlushAndYield(['Count: 1']);
274 expect(root).toMatchRenderedOutput('1');
275 });
276
@@ -285,7 +288,7 @@ describe('ReactHooks', () => {
288
289 const root = ReactTestRenderer.create(null, {unstable_isConcurrent: true});
290 root.update(<Counter />);
288 - expect(root).toFlushAndYield(['Count: 0']);
291 + expect(Scheduler).toFlushAndYield(['Count: 0']);
292 expect(root).toMatchRenderedOutput('0');
293
294 expect(() => {
@@ -301,7 +304,7 @@ describe('ReactHooks', () => {
304 'declare it in the component body with useEffect().',
305 {withoutStack: true},
306 );
304 - expect(root).toFlushAndYield(['Count: 1']);
307 + expect(Scheduler).toFlushAndYield(['Count: 1']);
308 expect(root).toMatchRenderedOutput('1');
309 });
310
@@ -346,7 +349,7 @@ describe('ReactHooks', () => {
349 <Parent />
350 </ThemeProvider>,
351 );
349 - expect(root).toFlushAndYield([
352 + expect(Scheduler).toFlushAndYield([
353 'Theme: light',
354 'Parent: 0 (light)',
355 'Child: 0 (light)',
@@ -357,12 +360,12 @@ describe('ReactHooks', () => {
360 // Updating the theme to the same value doesn't cause the consumers
361 // to re-render.
362 setTheme('light');
360 - expect(root).toFlushAndYield([]);
363 + expect(Scheduler).toFlushAndYield([]);
364 expect(root).toMatchRenderedOutput('0 (light)');
365
366 // Normal update
367 act(() => setCounter(1));
365 - expect(root).toFlushAndYield([
368 + expect(Scheduler).toFlushAndYield([
369 'Parent: 1 (light)',
370 'Child: 1 (light)',
371 'Effect: 1 (light)',
@@ -371,7 +374,7 @@ describe('ReactHooks', () => {
374
375 // Update that doesn't change state, so it bails out
376 act(() => setCounter(1));
374 - expect(root).toFlushAndYield(['Parent: 1 (light)']);
377 + expect(Scheduler).toFlushAndYield(['Parent: 1 (light)']);
378 expect(root).toMatchRenderedOutput('1 (light)');
379
380 // Update that doesn't change state, but the context changes, too, so it
@@ -381,7 +384,7 @@ describe('ReactHooks', () => {
384 setTheme('dark');
385 });
386
384 - expect(root).toFlushAndYield([
387 + expect(Scheduler).toFlushAndYield([
388 'Theme: dark',
389 'Parent: 1 (dark)',
390 'Child: 1 (dark)',
@@ -411,12 +414,12 @@ describe('ReactHooks', () => {
414
415 const root = ReactTestRenderer.create(null, {unstable_isConcurrent: true});
416 root.update(<Parent />);
414 - expect(root).toFlushAndYield(['Parent: 0', 'Child: 0', 'Effect: 0']);
417 + expect(Scheduler).toFlushAndYield(['Parent: 0', 'Child: 0', 'Effect: 0']);
418 expect(root).toMatchRenderedOutput('0');
419
420 // Normal update
421 act(() => setCounter(1));
419 - expect(root).toFlushAndYield(['Parent: 1', 'Child: 1', 'Effect: 1']);
422 + expect(Scheduler).toFlushAndYield(['Parent: 1', 'Child: 1', 'Effect: 1']);
423 expect(root).toMatchRenderedOutput('1');
424
425 // Update to the same state. React doesn't know if the queue is empty
@@ -424,25 +427,25 @@ describe('ReactHooks', () => {
427 // enter the render phase before we can bail out. But we bail out before
428 // rendering the child, and we don't fire any effects.
429 act(() => setCounter(1));
427 - expect(root).toFlushAndYield(['Parent: 1']);
430 + expect(Scheduler).toFlushAndYield(['Parent: 1']);
431 expect(root).toMatchRenderedOutput('1');
432
433 // Update to the same state again. This times, neither fiber has pending
434 // update priority, so we can bail out before even entering the render phase.
435 act(() => setCounter(1));
433 - expect(root).toFlushAndYield([]);
436 + expect(Scheduler).toFlushAndYield([]);
437 expect(root).toMatchRenderedOutput('1');
438
439 // This changes the state to something different so it renders normally.
440 act(() => setCounter(2));
438 - expect(root).toFlushAndYield(['Parent: 2', 'Child: 2', 'Effect: 2']);
441 + expect(Scheduler).toFlushAndYield(['Parent: 2', 'Child: 2', 'Effect: 2']);
442 expect(root).toMatchRenderedOutput('2');
443
444 // prepare to check SameValue
445 act(() => {
446 setCounter(0);
447 });
445 - expect(root).toFlushAndYield(['Parent: 0', 'Child: 0', 'Effect: 0']);
448 + expect(Scheduler).toFlushAndYield(['Parent: 0', 'Child: 0', 'Effect: 0']);
449 expect(root).toMatchRenderedOutput('0');
450
451 // Update to the same state for the first time to flush the queue
@@ -450,21 +453,21 @@ describe('ReactHooks', () => {
453 setCounter(0);
454 });
455
453 - expect(root).toFlushAndYield(['Parent: 0']);
456 + expect(Scheduler).toFlushAndYield(['Parent: 0']);
457 expect(root).toMatchRenderedOutput('0');
458
459 // Update again to the same state. Should bail out.
460 act(() => {
461 setCounter(0);
462 });
460 - expect(root).toFlushAndYield([]);
463 + expect(Scheduler).toFlushAndYield([]);
464 expect(root).toMatchRenderedOutput('0');
465
466 // Update to a different state (positive 0 to negative 0)
467 act(() => {
468 setCounter(0 / -1);
469 });
467 - expect(root).toFlushAndYield(['Parent: 0', 'Child: 0', 'Effect: 0']);
470 + expect(Scheduler).toFlushAndYield(['Parent: 0', 'Child: 0', 'Effect: 0']);
471 expect(root).toMatchRenderedOutput('0');
472 });
473
@@ -486,7 +489,7 @@ describe('ReactHooks', () => {
489
490 const root = ReactTestRenderer.create(null, {unstable_isConcurrent: true});
491 root.update(<Parent />);
489 - expect(root).toFlushAndYield(['Parent: 0', 'Child: 0']);
492 + expect(Scheduler).toFlushAndYield(['Parent: 0', 'Child: 0']);
493 expect(root).toMatchRenderedOutput('0');
494
495 const update = value => {
@@ -504,7 +507,7 @@ describe('ReactHooks', () => {
507 update(3);
508 });
509
507 - expect(ReactTestRenderer).toHaveYielded([
510 + expect(Scheduler).toHaveYielded([
511 // The first four updates were eagerly computed, because the queue is
512 // empty before each one.
513 'Compute state (0 -> 0)',
@@ -516,7 +519,7 @@ describe('ReactHooks', () => {
519 ]);
520
521 // Now let's enter the render phase
519 - expect(root).toFlushAndYield([
522 + expect(Scheduler).toFlushAndYield([
523 // We don't need to re-compute the first four updates. Only the final two.
524 'Compute state (1 -> 2)',
525 'Compute state (2 -> 3)',
@@ -544,7 +547,7 @@ describe('ReactHooks', () => {
547
548 const root = ReactTestRenderer.create(null, {unstable_isConcurrent: true});
549 root.update(<Parent />);
547 - expect(root).toFlushAndYield(['Parent: 1', 'Child: 1']);
550 + expect(Scheduler).toFlushAndYield(['Parent: 1', 'Child: 1']);
551 expect(root).toMatchRenderedOutput('1');
552
553 const update = compute => {
@@ -559,13 +562,13 @@ describe('ReactHooks', () => {
562 act(() => update(n => n * 100));
563
564 // The new state is eagerly computed.
562 - expect(ReactTestRenderer).toHaveYielded(['Compute state (1 -> 100)']);
565 + expect(Scheduler).toHaveYielded(['Compute state (1 -> 100)']);
566
567 // but before it's flushed, a higher priority update interrupts it.
568 root.unstable_flushSync(() => {
569 update(n => n + 5);
570 });
568 - expect(ReactTestRenderer).toHaveYielded([
571 + expect(Scheduler).toHaveYielded([
572 // The eagerly computed state was completely skipped
573 'Compute state (1 -> 6)',
574 'Parent: 6',
@@ -576,7 +579,7 @@ describe('ReactHooks', () => {
579 // Now when we finish the first update, the second update is rebased on top.
580 // Notice we didn't have to recompute the first update even though it was
581 // skipped in the previous render.
579 - expect(root).toFlushAndYield([
582 + expect(Scheduler).toFlushAndYield([
583 'Compute state (100 -> 105)',
584 'Parent: 105',
585 'Child: 105',
@@ -593,7 +596,7 @@ describe('ReactHooks', () => {
596 return props.dependencies;
597 }
598 const root = ReactTestRenderer.create(<App dependencies={['A']} />);
596 - expect(ReactTestRenderer).toHaveYielded(['Did commit: A']);
599 + expect(Scheduler).toHaveYielded(['Did commit: A']);
600 expect(() => {
601 root.update(<App dependencies={['A', 'B']} />);
602 }).toWarnDev([
@@ -617,7 +620,7 @@ describe('ReactHooks', () => {
620
621 const root = ReactTestRenderer.create(null);
622 root.update(<App text="Hello" hasDeps={true} />);
620 - expect(ReactTestRenderer).toHaveYielded(['Compute']);
623 + expect(Scheduler).toHaveYielded(['Compute']);
624 expect(root).toMatchRenderedOutput('HELLO');
625
626 expect(() => {
packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.internal.js
+173 -173
@@ -76,7 +76,7 @@ describe('ReactHooksWithNoopRenderer', () => {
76 // Initial mount
77 const counter = React.createRef(null);
78 ReactNoop.render(<Counter label="Count" ref={counter} />);
79 - expect(ReactNoop).toFlushAndYield(['Count: 0']);
79 + expect(Scheduler).toFlushAndYield(['Count: 0']);
80 expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
81
82 // Schedule some updates
@@ -86,17 +86,17 @@ describe('ReactHooksWithNoopRenderer', () => {
86 });
87
88 // Partially flush without committing
89 - expect(ReactNoop).toFlushAndYieldThrough(['Count: 11']);
89 + expect(Scheduler).toFlushAndYieldThrough(['Count: 11']);
90 expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
91
92 // Interrupt with a high priority update
93 ReactNoop.flushSync(() => {
94 ReactNoop.render(<Counter label="Total" />);
95 });
96 - expect(ReactNoop).toHaveYielded(['Total: 0']);
96 + expect(Scheduler).toHaveYielded(['Total: 0']);
97
98 // Resume rendering
99 - expect(ReactNoop).toFlushAndYield(['Total: 11']);
99 + expect(Scheduler).toFlushAndYield(['Total: 11']);
100 expect(ReactNoop.getChildren()).toEqual([span('Total: 11')]);
101 });
102
@@ -109,7 +109,7 @@ describe('ReactHooksWithNoopRenderer', () => {
109 }
110 ReactNoop.render(<BadCounter />);
111
112 - expect(ReactNoop).toFlushAndThrow(
112 + expect(Scheduler).toFlushAndThrow(
113 'Hooks can only be called inside the body of a function component.',
114 );
115
@@ -119,7 +119,7 @@ describe('ReactHooksWithNoopRenderer', () => {
119 return <Text text={count} />;
120 }
121 ReactNoop.render(<GoodCounter initialCount={10} />);
122 - expect(ReactNoop).toFlushAndYield([10]);
122 + expect(Scheduler).toFlushAndYield([10]);
123 });
124
125 it('throws inside module-style components', () => {
@@ -132,7 +132,7 @@ describe('ReactHooksWithNoopRenderer', () => {
132 };
133 }
134 ReactNoop.render(<Counter />);
135 - expect(ReactNoop).toFlushAndThrow(
135 + expect(Scheduler).toFlushAndThrow(
136 'Hooks can only be called inside the body of a function component.',
137 );
138
@@ -142,7 +142,7 @@ describe('ReactHooksWithNoopRenderer', () => {
142 return <Text text={count} />;
143 }
144 ReactNoop.render(<GoodCounter initialCount={10} />);
145 - expect(ReactNoop).toFlushAndYield([10]);
145 + expect(Scheduler).toFlushAndYield([10]);
146 });
147
148 it('throws when called outside the render phase', () => {
@@ -161,15 +161,15 @@ describe('ReactHooksWithNoopRenderer', () => {
161 Counter = forwardRef(Counter);
162 const counter = React.createRef(null);
163 ReactNoop.render(<Counter ref={counter} />);
164 - expect(ReactNoop).toFlushAndYield(['Count: 0']);
164 + expect(Scheduler).toFlushAndYield(['Count: 0']);
165 expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
166
167 act(() => counter.current.updateCount(1));
168 - expect(ReactNoop).toFlushAndYield(['Count: 1']);
168 + expect(Scheduler).toFlushAndYield(['Count: 1']);
169 expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]);
170
171 act(() => counter.current.updateCount(count => count + 10));
172 - expect(ReactNoop).toFlushAndYield(['Count: 11']);
172 + expect(Scheduler).toFlushAndYield(['Count: 11']);
173 expect(ReactNoop.getChildren()).toEqual([span('Count: 11')]);
174 });
175
@@ -185,11 +185,11 @@ describe('ReactHooksWithNoopRenderer', () => {
185 Counter = forwardRef(Counter);
186 const counter = React.createRef(null);
187 ReactNoop.render(<Counter initialState={42} ref={counter} />);
188 - expect(ReactNoop).toFlushAndYield(['getInitialState', 'Count: 42']);
188 + expect(Scheduler).toFlushAndYield(['getInitialState', 'Count: 42']);
189 expect(ReactNoop.getChildren()).toEqual([span('Count: 42')]);
190
191 act(() => counter.current.updateCount(7));
192 - expect(ReactNoop).toFlushAndYield(['Count: 7']);
192 + expect(Scheduler).toFlushAndYield(['Count: 7']);
193 expect(ReactNoop.getChildren()).toEqual([span('Count: 7')]);
194 });
195
@@ -203,14 +203,14 @@ describe('ReactHooksWithNoopRenderer', () => {
203 Counter = forwardRef(Counter);
204 const counter = React.createRef(null);
205 ReactNoop.render(<Counter ref={counter} />);
206 - expect(ReactNoop).toFlushAndYield(['Count: 0']);
206 + expect(Scheduler).toFlushAndYield(['Count: 0']);
207 expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
208
209 act(() => counter.current.updateCount(7));
210 - expect(ReactNoop).toFlushAndYield(['Count: 7']);
210 + expect(Scheduler).toFlushAndYield(['Count: 7']);
211
212 act(() => counter.current.updateLabel('Total'));
213 - expect(ReactNoop).toFlushAndYield(['Total: 7']);
213 + expect(Scheduler).toFlushAndYield(['Total: 7']);
214 });
215
216 it('returns the same updater function every time', () => {
@@ -221,15 +221,15 @@ describe('ReactHooksWithNoopRenderer', () => {
221 return <Text text={'Count: ' + count} />;
222 }
223 ReactNoop.render(<Counter />);
224 - expect(ReactNoop).toFlushAndYield(['Count: 0']);
224 + expect(Scheduler).toFlushAndYield(['Count: 0']);
225 expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
226
227 act(() => updaters[0](1));
228 - expect(ReactNoop).toFlushAndYield(['Count: 1']);
228 + expect(Scheduler).toFlushAndYield(['Count: 1']);
229 expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]);
230
231 act(() => updaters[0](count => count + 10));
232 - expect(ReactNoop).toFlushAndYield(['Count: 11']);
232 + expect(Scheduler).toFlushAndYield(['Count: 11']);
233 expect(ReactNoop.getChildren()).toEqual([span('Count: 11')]);
234
235 expect(updaters).toEqual([updaters[0], updaters[0], updaters[0]]);
@@ -244,9 +244,9 @@ describe('ReactHooksWithNoopRenderer', () => {
244 }
245
246 ReactNoop.render(<Counter />);
247 - expect(ReactNoop).toFlushWithoutYielding();
247 + expect(Scheduler).toFlushWithoutYielding();
248 ReactNoop.render(null);
249 - expect(ReactNoop).toFlushWithoutYielding();
249 + expect(Scheduler).toFlushWithoutYielding();
250 expect(() => act(() => _updateCount(1))).toWarnDev(
251 "Warning: Can't perform a React state update on an unmounted " +
252 'component. This is a no-op, but it indicates a memory leak in your ' +
@@ -266,15 +266,15 @@ describe('ReactHooksWithNoopRenderer', () => {
266 Counter = memo(Counter);
267
268 ReactNoop.render(<Counter />);
269 - expect(ReactNoop).toFlushAndYield(['Count: 0']);
269 + expect(Scheduler).toFlushAndYield(['Count: 0']);
270 expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
271
272 ReactNoop.render(<Counter />);
273 - expect(ReactNoop).toFlushAndYield([]);
273 + expect(Scheduler).toFlushAndYield([]);
274 expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
275
276 act(() => _updateCount(1));
277 - expect(ReactNoop).toFlushAndYield(['Count: 1']);
277 + expect(Scheduler).toFlushAndYield(['Count: 1']);
278 expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]);
279 });
280 });
@@ -295,27 +295,27 @@ describe('ReactHooksWithNoopRenderer', () => {
295 }
296
297 ReactNoop.render(<ScrollView row={1} />);
298 - expect(ReactNoop).toFlushAndYield(['Scrolling down: false']);
298 + expect(Scheduler).toFlushAndYield(['Scrolling down: false']);
299 expect(ReactNoop.getChildren()).toEqual([span('Scrolling down: false')]);
300
301 ReactNoop.render(<ScrollView row={5} />);
302 - expect(ReactNoop).toFlushAndYield(['Scrolling down: true']);
302 + expect(Scheduler).toFlushAndYield(['Scrolling down: true']);
303 expect(ReactNoop.getChildren()).toEqual([span('Scrolling down: true')]);
304
305 ReactNoop.render(<ScrollView row={5} />);
306 - expect(ReactNoop).toFlushAndYield(['Scrolling down: true']);
306 + expect(Scheduler).toFlushAndYield(['Scrolling down: true']);
307 expect(ReactNoop.getChildren()).toEqual([span('Scrolling down: true')]);
308
309 ReactNoop.render(<ScrollView row={10} />);
310 - expect(ReactNoop).toFlushAndYield(['Scrolling down: true']);
310 + expect(Scheduler).toFlushAndYield(['Scrolling down: true']);
311 expect(ReactNoop.getChildren()).toEqual([span('Scrolling down: true')]);
312
313 ReactNoop.render(<ScrollView row={2} />);
314 - expect(ReactNoop).toFlushAndYield(['Scrolling down: false']);
314 + expect(Scheduler).toFlushAndYield(['Scrolling down: false']);
315 expect(ReactNoop.getChildren()).toEqual([span('Scrolling down: false')]);
316
317 ReactNoop.render(<ScrollView row={2} />);
318 - expect(ReactNoop).toFlushAndYield(['Scrolling down: false']);
318 + expect(Scheduler).toFlushAndYield(['Scrolling down: false']);
319 expect(ReactNoop.getChildren()).toEqual([span('Scrolling down: false')]);
320 });
321
@@ -330,7 +330,7 @@ describe('ReactHooksWithNoopRenderer', () => {
330 }
331
332 ReactNoop.render(<Counter />);
333 - expect(ReactNoop).toFlushAndYield([
333 + expect(Scheduler).toFlushAndYield([
334 'Render: 0',
335 'Render: 1',
336 'Render: 2',
@@ -353,7 +353,7 @@ describe('ReactHooksWithNoopRenderer', () => {
353 }
354
355 ReactNoop.render(<Counter />);
356 - expect(ReactNoop).toFlushAndYield([
356 + expect(Scheduler).toFlushAndYield([
357 // Should increase by three each time
358 'Render: 0',
359 'Render: 3',
@@ -373,7 +373,7 @@ describe('ReactHooksWithNoopRenderer', () => {
373 return <Text text={count} />;
374 }
375 ReactNoop.render(<Counter />);
376 - expect(ReactNoop).toFlushAndThrow(
376 + expect(Scheduler).toFlushAndThrow(
377 'Too many re-renders. React limits the number of renders to prevent ' +
378 'an infinite loop.',
379 );
@@ -393,7 +393,7 @@ describe('ReactHooksWithNoopRenderer', () => {
393 }
394
395 ReactNoop.render(<Counter />);
396 - expect(ReactNoop).toFlushAndYield([
396 + expect(Scheduler).toFlushAndYield([
397 'Render: 0',
398 'Render: 1',
399 'Render: 2',
@@ -443,7 +443,7 @@ describe('ReactHooksWithNoopRenderer', () => {
443 Counter = forwardRef(Counter);
444 const counter = React.createRef(null);
445 ReactNoop.render(<Counter ref={counter} />);
446 - expect(ReactNoop).toFlushAndYield([
446 + expect(Scheduler).toFlushAndYield([
447 // The count should increase by alternating amounts of 10 and 1
448 // until we reach 21.
449 'Render: 0',
@@ -460,7 +460,7 @@ describe('ReactHooksWithNoopRenderer', () => {
460 counter.current.dispatch('reset');
461 });
462 ReactNoop.render(<Counter ref={counter} />);
463 - expect(ReactNoop).toFlushAndYield([
463 + expect(Scheduler).toFlushAndYield([
464 'Render: 0',
465 'Render: 1',
466 'Render: 11',
@@ -496,11 +496,11 @@ describe('ReactHooksWithNoopRenderer', () => {
496 Counter = forwardRef(Counter);
497 const counter = React.createRef(null);
498 ReactNoop.render(<Counter ref={counter} />);
499 - expect(ReactNoop).toFlushAndYield(['Count: 0']);
499 + expect(Scheduler).toFlushAndYield(['Count: 0']);
500 expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
501
502 act(() => counter.current.dispatch(INCREMENT));
503 - expect(ReactNoop).toFlushAndYield(['Count: 1']);
503 + expect(Scheduler).toFlushAndYield(['Count: 1']);
504 expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]);
505 act(() => {
506 counter.current.dispatch(DECREMENT);
@@ -508,7 +508,7 @@ describe('ReactHooksWithNoopRenderer', () => {
508 counter.current.dispatch(DECREMENT);
509 });
510
511 - expect(ReactNoop).toFlushAndYield(['Count: -2']);
511 + expect(Scheduler).toFlushAndYield(['Count: -2']);
512 expect(ReactNoop.getChildren()).toEqual([span('Count: -2')]);
513 });
514
@@ -538,11 +538,11 @@ describe('ReactHooksWithNoopRenderer', () => {
538 Counter = forwardRef(Counter);
539 const counter = React.createRef(null);
540 ReactNoop.render(<Counter initialCount={10} ref={counter} />);
541 - expect(ReactNoop).toFlushAndYield(['Init', 'Count: 10']);
541 + expect(Scheduler).toFlushAndYield(['Init', 'Count: 10']);
542 expect(ReactNoop.getChildren()).toEqual([span('Count: 10')]);
543
544 act(() => counter.current.dispatch(INCREMENT));
545 - expect(ReactNoop).toFlushAndYield(['Count: 11']);
545 + expect(Scheduler).toFlushAndYield(['Count: 11']);
546 expect(ReactNoop.getChildren()).toEqual([span('Count: 11')]);
547
548 act(() => {
@@ -551,7 +551,7 @@ describe('ReactHooksWithNoopRenderer', () => {
551 counter.current.dispatch(DECREMENT);
552 });
553
554 - expect(ReactNoop).toFlushAndYield(['Count: 8']);
554 + expect(Scheduler).toFlushAndYield(['Count: 8']);
555 expect(ReactNoop.getChildren()).toEqual([span('Count: 8')]);
556 });
557
@@ -573,7 +573,7 @@ describe('ReactHooksWithNoopRenderer', () => {
573 const counter = React.createRef(null);
574 ReactNoop.render(<Counter ref={counter} />);
575
576 - expect(ReactNoop).toFlushAndYield(['Count: 0']);
576 + expect(Scheduler).toFlushAndYield(['Count: 0']);
577 expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
578
579 act(() => {
@@ -585,10 +585,10 @@ describe('ReactHooksWithNoopRenderer', () => {
585 ReactNoop.flushSync(() => {
586 counter.current.dispatch(INCREMENT);
587 });
588 - expect(ReactNoop).toHaveYielded(['Count: 1']);
588 + expect(Scheduler).toHaveYielded(['Count: 1']);
589 expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]);
590
591 - expect(ReactNoop).toFlushAndYield(['Count: 4']);
591 + expect(Scheduler).toFlushAndYield(['Count: 4']);
592 expect(ReactNoop.getChildren()).toEqual([span('Count: 4')]);
593 });
594 });
@@ -604,18 +604,18 @@ describe('ReactHooksWithNoopRenderer', () => {
604 ReactNoop.render(<Counter count={0} />, () =>
605 ReactNoop.yield('Sync effect'),
606 );
607 - expect(ReactNoop).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
607 + expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
608 expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
609 // Effects are deferred until after the commit
610 - expect(ReactNoop).toFlushAndYield(['Passive effect [0]']);
610 + expect(Scheduler).toFlushAndYield(['Passive effect [0]']);
611
612 ReactNoop.render(<Counter count={1} />, () =>
613 ReactNoop.yield('Sync effect'),
614 );
615 - expect(ReactNoop).toFlushAndYieldThrough(['Count: 1', 'Sync effect']);
615 + expect(Scheduler).toFlushAndYieldThrough(['Count: 1', 'Sync effect']);
616 expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]);
617 // Effects are deferred until after the commit
618 - expect(ReactNoop).toFlushAndYield(['Passive effect [1]']);
618 + expect(Scheduler).toFlushAndYield(['Passive effect [1]']);
619 });
620
621 it('flushes passive effects even with sibling deletions', () => {
@@ -633,7 +633,7 @@ describe('ReactHooksWithNoopRenderer', () => {
633 }
634 let passive = <PassiveEffect key="p" />;
635 ReactNoop.render([<LayoutEffect key="l" />, passive]);
636 - expect(ReactNoop).toFlushAndYieldThrough([
636 + expect(Scheduler).toFlushAndYieldThrough([
637 'Layout',
638 'Passive',
639 'Layout effect',
@@ -646,13 +646,13 @@ describe('ReactHooksWithNoopRenderer', () => {
646 // Destroying the first child shouldn't prevent the passive effect from
647 // being executed
648 ReactNoop.render([passive]);
649 - expect(ReactNoop).toHaveYielded(['Passive effect']);
650 - expect(ReactNoop).toFlushAndYield([]);
649 + expect(Scheduler).toHaveYielded(['Passive effect']);
650 + expect(Scheduler).toFlushAndYield([]);
651 expect(ReactNoop.getChildren()).toEqual([span('Passive')]);
652
653 // (No effects are left to flush.)
654 ReactNoop.flushPassiveEffects();
655 - expect(ReactNoop).toHaveYielded([]);
655 + expect(Scheduler).toHaveYielded([]);
656 });
657
658 it('flushes passive effects even if siblings schedule an update', () => {
@@ -677,7 +677,7 @@ describe('ReactHooksWithNoopRenderer', () => {
677 ReactNoop.render([<PassiveEffect key="p" />, <LayoutEffect key="l" />]);
678
679 act(() => {
680 - expect(ReactNoop).toFlushAndYield([
680 + expect(Scheduler).toFlushAndYield([
681 'Passive',
682 'Layout',
683 'Layout effect 0',
@@ -709,7 +709,7 @@ describe('ReactHooksWithNoopRenderer', () => {
709 return <Text text="Layout" />;
710 }
711 ReactNoop.render([<PassiveEffect key="p" />, <LayoutEffect key="l" />]);
712 - expect(ReactNoop).toFlushAndYield([
712 + expect(Scheduler).toFlushAndYield([
713 'Passive',
714 'Layout',
715 'Layout effect',
@@ -745,22 +745,22 @@ describe('ReactHooksWithNoopRenderer', () => {
745 ReactNoop.render(<Counter count={0} />, () =>
746 ReactNoop.yield('Sync effect'),
747 );
748 - expect(ReactNoop).toFlushAndYieldThrough([0, 'Sync effect']);
748 + expect(Scheduler).toFlushAndYieldThrough([0, 'Sync effect']);
749 expect(ReactNoop.getChildren()).toEqual([span(0)]);
750
751 // Before the effects have a chance to flush, schedule another update
752 ReactNoop.render(<Counter count={1} />, () =>
753 ReactNoop.yield('Sync effect'),
754 );
755 - expect(ReactNoop).toHaveYielded([
755 + expect(Scheduler).toHaveYielded([
756 // The previous effect flushes before the reconciliation
757 'Committed state when effect was fired: 0',
758 ]);
759 - expect(ReactNoop).toFlushAndYieldThrough([1, 'Sync effect']);
759 + expect(Scheduler).toFlushAndYieldThrough([1, 'Sync effect']);
760 expect(ReactNoop.getChildren()).toEqual([span(1)]);
761
762 ReactNoop.flushPassiveEffects();
763 - expect(ReactNoop).toHaveYielded([
763 + expect(Scheduler).toHaveYielded([
764 'Committed state when effect was fired: 1',
765 ]);
766 },
@@ -781,23 +781,23 @@ describe('ReactHooksWithNoopRenderer', () => {
781 ReactNoop.render(<Counter count={0} />, () =>
782 ReactNoop.yield('Sync effect'),
783 );
784 - expect(ReactNoop).toFlushAndYieldThrough([
784 + expect(Scheduler).toFlushAndYieldThrough([
785 'Count: (empty)',
786 'Sync effect',
787 ]);
788 expect(ReactNoop.getChildren()).toEqual([span('Count: (empty)')]);
789 ReactNoop.flushPassiveEffects();
790 - expect(ReactNoop).toHaveYielded(['Schedule update [0]']);
791 - expect(ReactNoop).toFlushAndYield(['Count: 0']);
790 + expect(Scheduler).toHaveYielded(['Schedule update [0]']);
791 + expect(Scheduler).toFlushAndYield(['Count: 0']);
792
793 ReactNoop.render(<Counter count={1} />, () =>
794 ReactNoop.yield('Sync effect'),
795 );
796 - expect(ReactNoop).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
796 + expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
797 expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
798 ReactNoop.flushPassiveEffects();
799 - expect(ReactNoop).toHaveYielded(['Schedule update [1]']);
800 - expect(ReactNoop).toFlushAndYield(['Count: 1']);
799 + expect(Scheduler).toHaveYielded(['Schedule update [1]']);
800 + expect(Scheduler).toFlushAndYield(['Count: 1']);
801 });
802
803 it('updates have async priority even if effects are flushed early', () => {
@@ -815,7 +815,7 @@ describe('ReactHooksWithNoopRenderer', () => {
815 ReactNoop.render(<Counter count={0} />, () =>
816 ReactNoop.yield('Sync effect'),
817 );
818 - expect(ReactNoop).toFlushAndYieldThrough([
818 + expect(Scheduler).toFlushAndYieldThrough([
819 'Count: (empty)',
820 'Sync effect',
821 ]);
@@ -825,16 +825,16 @@ describe('ReactHooksWithNoopRenderer', () => {
825 ReactNoop.render(<Counter count={1} />, () =>
826 ReactNoop.yield('Sync effect'),
827 );
828 - expect(ReactNoop).toHaveYielded(['Schedule update [0]']);
829 - expect(ReactNoop).toFlushAndYieldThrough(['Count: 0']);
828 + expect(Scheduler).toHaveYielded(['Schedule update [0]']);
829 + expect(Scheduler).toFlushAndYieldThrough(['Count: 0']);
830 expect(ReactNoop.getChildren()).toEqual([span('Count: (empty)')]);
831
832 - expect(ReactNoop).toFlushAndYieldThrough(['Sync effect']);
832 + expect(Scheduler).toFlushAndYieldThrough(['Sync effect']);
833 expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
834
835 ReactNoop.flushPassiveEffects();
836 - expect(ReactNoop).toHaveYielded(['Schedule update [1]']);
837 - expect(ReactNoop).toFlushAndYield(['Count: 1']);
836 + expect(Scheduler).toHaveYielded(['Schedule update [1]']);
837 + expect(Scheduler).toFlushAndYield(['Count: 1']);
838 expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]);
839 });
840
@@ -853,14 +853,14 @@ describe('ReactHooksWithNoopRenderer', () => {
853 ReactNoop.render(<Counter count={0} />, () =>
854 ReactNoop.yield('Sync effect'),
855 );
856 - expect(ReactNoop).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
856 + expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
857 expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
858
859 // Enqueuing this update forces the passive effect to be flushed --
860 // updateCount(1) happens first, so 2 wins.
861 act(() => _updateCount(2));
862 - expect(ReactNoop).toHaveYielded(['Will set count to 1']);
863 - expect(ReactNoop).toFlushAndYield(['Count: 2']);
862 + expect(Scheduler).toHaveYielded(['Will set count to 1']);
863 + expect(Scheduler).toFlushAndYield(['Count: 2']);
864 expect(ReactNoop.getChildren()).toEqual([span('Count: 2')]);
865 });
866
@@ -900,7 +900,7 @@ describe('ReactHooksWithNoopRenderer', () => {
900 );
901 },
902 );
903 - expect(ReactNoop).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
903 + expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
904 expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
905
906 expect(onInteractionScheduledWorkCompleted).toHaveBeenCalledTimes(0);
@@ -908,8 +908,8 @@ describe('ReactHooksWithNoopRenderer', () => {
908 // Enqueuing this update forces the passive effect to be flushed --
909 // updateCount(1) happens first, so 2 wins.
910 act(() => _updateCount(2));
911 - expect(ReactNoop).toHaveYielded(['Will set count to 1']);
912 - expect(ReactNoop).toFlushAndYield(['Count: 2']);
911 + expect(Scheduler).toHaveYielded(['Will set count to 1']);
912 + expect(Scheduler).toFlushAndYield(['Count: 2']);
913 expect(ReactNoop.getChildren()).toEqual([span('Count: 2')]);
914
915 expect(onInteractionScheduledWorkCompleted).toHaveBeenCalledTimes(1);
@@ -939,13 +939,13 @@ describe('ReactHooksWithNoopRenderer', () => {
939 }
940 ReactNoop.renderLegacySyncRoot(<Counter count={0} />);
941 // Even in sync mode, effects are deferred until after paint
942 - expect(ReactNoop).toHaveYielded(['Count: (empty)']);
942 + expect(Scheduler).toHaveYielded(['Count: (empty)']);
943 expect(ReactNoop.getChildren()).toEqual([span('Count: (empty)')]);
944 // Now fire the effects
945 ReactNoop.flushPassiveEffects();
946 // There were multiple updates, but there should only be a
947 // single render
948 - expect(ReactNoop).toHaveYielded(['Count: 0']);
948 + expect(Scheduler).toHaveYielded(['Count: 0']);
949 expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
950 },
951 );
@@ -967,7 +967,7 @@ describe('ReactHooksWithNoopRenderer', () => {
967 ReactNoop.render(<Counter count={0} />, () =>
968 ReactNoop.yield('Sync effect'),
969 );
970 - expect(ReactNoop).toFlushAndYieldThrough([
970 + expect(Scheduler).toFlushAndYieldThrough([
971 'Count: (empty)',
972 'Sync effect',
973 ]);
@@ -991,18 +991,18 @@ describe('ReactHooksWithNoopRenderer', () => {
991 ReactNoop.render(<Counter count={0} />, () =>
992 ReactNoop.yield('Sync effect'),
993 );
994 - expect(ReactNoop).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
994 + expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
995 expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
996 ReactNoop.flushPassiveEffects();
997 - expect(ReactNoop).toHaveYielded(['Did create [0]']);
997 + expect(Scheduler).toHaveYielded(['Did create [0]']);
998
999 ReactNoop.render(<Counter count={1} />, () =>
1000 ReactNoop.yield('Sync effect'),
1001 );
1002 - expect(ReactNoop).toFlushAndYieldThrough(['Count: 1', 'Sync effect']);
1002 + expect(Scheduler).toFlushAndYieldThrough(['Count: 1', 'Sync effect']);
1003 expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]);
1004 ReactNoop.flushPassiveEffects();
1005 - expect(ReactNoop).toHaveYielded(['Did destroy [0]', 'Did create [1]']);
1005 + expect(Scheduler).toHaveYielded(['Did destroy [0]', 'Did create [1]']);
1006 });
1007
1008 it('unmounts on deletion', () => {
@@ -1018,13 +1018,13 @@ describe('ReactHooksWithNoopRenderer', () => {
1018 ReactNoop.render(<Counter count={0} />, () =>
1019 ReactNoop.yield('Sync effect'),
1020 );
1021 - expect(ReactNoop).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
1021 + expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
1022 expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
1023 ReactNoop.flushPassiveEffects();
1024 - expect(ReactNoop).toHaveYielded(['Did create [0]']);
1024 + expect(Scheduler).toHaveYielded(['Did create [0]']);
1025
1026 ReactNoop.render(null);
1027 - expect(ReactNoop).toFlushAndYield(['Did destroy [0]']);
1027 + expect(Scheduler).toFlushAndYield(['Did destroy [0]']);
1028 expect(ReactNoop.getChildren()).toEqual([]);
1029 });
1030
@@ -1041,21 +1041,21 @@ describe('ReactHooksWithNoopRenderer', () => {
1041 ReactNoop.render(<Counter count={0} />, () =>
1042 ReactNoop.yield('Sync effect'),
1043 );
1044 - expect(ReactNoop).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
1044 + expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
1045 expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
1046 ReactNoop.flushPassiveEffects();
1047 - expect(ReactNoop).toHaveYielded(['Did create [0]']);
1047 + expect(Scheduler).toHaveYielded(['Did create [0]']);
1048
1049 ReactNoop.render(<Counter count={1} />, () =>
1050 ReactNoop.yield('Sync effect'),
1051 );
1052 - expect(ReactNoop).toFlushAndYieldThrough(['Count: 1', 'Sync effect']);
1052 + expect(Scheduler).toFlushAndYieldThrough(['Count: 1', 'Sync effect']);
1053 expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]);
1054 ReactNoop.flushPassiveEffects();
1055 - expect(ReactNoop).toHaveYielded([]);
1055 + expect(Scheduler).toHaveYielded([]);
1056
1057 ReactNoop.render(null);
1058 - expect(ReactNoop).toFlushAndYield(['Did destroy [0]']);
1058 + expect(Scheduler).toFlushAndYield(['Did destroy [0]']);
1059 expect(ReactNoop.getChildren()).toEqual([]);
1060 });
1061
@@ -1073,21 +1073,21 @@ describe('ReactHooksWithNoopRenderer', () => {
1073 ReactNoop.render(<Counter count={0} />, () =>
1074 ReactNoop.yield('Sync effect'),
1075 );
1076 - expect(ReactNoop).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
1076 + expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
1077 expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
1078 ReactNoop.flushPassiveEffects();
1079 - expect(ReactNoop).toHaveYielded(['Did create']);
1079 + expect(Scheduler).toHaveYielded(['Did create']);
1080
1081 ReactNoop.render(<Counter count={1} />, () =>
1082 ReactNoop.yield('Sync effect'),
1083 );
1084 - expect(ReactNoop).toFlushAndYieldThrough(['Count: 1', 'Sync effect']);
1084 + expect(Scheduler).toFlushAndYieldThrough(['Count: 1', 'Sync effect']);
1085 expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]);
1086 ReactNoop.flushPassiveEffects();
1087 - expect(ReactNoop).toHaveYielded(['Did destroy', 'Did create']);
1087 + expect(Scheduler).toHaveYielded(['Did destroy', 'Did create']);
1088
1089 ReactNoop.render(null);
1090 - expect(ReactNoop).toFlushAndYield(['Did destroy']);
1090 + expect(Scheduler).toFlushAndYield(['Did destroy']);
1091 expect(ReactNoop.getChildren()).toEqual([]);
1092 });
1093
@@ -1108,19 +1108,19 @@ describe('ReactHooksWithNoopRenderer', () => {
1108 ReactNoop.render(<Counter label="Count" count={0} />, () =>
1109 ReactNoop.yield('Sync effect'),
1110 );
1111 - expect(ReactNoop).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
1111 + expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
1112 ReactNoop.flushPassiveEffects();
1113 - expect(ReactNoop).toHaveYielded(['Did create [Count: 0]']);
1113 + expect(Scheduler).toHaveYielded(['Did create [Count: 0]']);
1114 expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
1115
1116 ReactNoop.render(<Counter label="Count" count={1} />, () =>
1117 ReactNoop.yield('Sync effect'),
1118 );
1119 // Count changed
1120 - expect(ReactNoop).toFlushAndYieldThrough(['Count: 1', 'Sync effect']);
1120 + expect(Scheduler).toFlushAndYieldThrough(['Count: 1', 'Sync effect']);
1121 expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]);
1122 ReactNoop.flushPassiveEffects();
1123 - expect(ReactNoop).toHaveYielded([
1123 + expect(Scheduler).toHaveYielded([
1124 'Did destroy [Count: 0]',
1125 'Did create [Count: 1]',
1126 ]);
@@ -1129,19 +1129,19 @@ describe('ReactHooksWithNoopRenderer', () => {
1129 ReactNoop.yield('Sync effect'),
1130 );
1131 // Nothing changed, so no effect should have fired
1132 - expect(ReactNoop).toFlushAndYieldThrough(['Count: 1', 'Sync effect']);
1132 + expect(Scheduler).toFlushAndYieldThrough(['Count: 1', 'Sync effect']);
1133 ReactNoop.flushPassiveEffects();
1134 - expect(ReactNoop).toHaveYielded([]);
1134 + expect(Scheduler).toHaveYielded([]);
1135 expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]);
1136
1137 ReactNoop.render(<Counter label="Total" count={1} />, () =>
1138 ReactNoop.yield('Sync effect'),
1139 );
1140 // Label changed
1141 - expect(ReactNoop).toFlushAndYieldThrough(['Total: 1', 'Sync effect']);
1141 + expect(Scheduler).toFlushAndYieldThrough(['Total: 1', 'Sync effect']);
1142 expect(ReactNoop.getChildren()).toEqual([span('Total: 1')]);
1143 ReactNoop.flushPassiveEffects();
1144 - expect(ReactNoop).toHaveYielded([
1144 + expect(Scheduler).toHaveYielded([
1145 'Did destroy [Count: 1]',
1146 'Did create [Total: 1]',
1147 ]);
@@ -1160,18 +1160,18 @@ describe('ReactHooksWithNoopRenderer', () => {
1160 ReactNoop.render(<Counter count={0} />, () =>
1161 ReactNoop.yield('Sync effect'),
1162 );
1163 - expect(ReactNoop).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
1163 + expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
1164 expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
1165 ReactNoop.flushPassiveEffects();
1166 - expect(ReactNoop).toHaveYielded(['Did commit 1 [0]', 'Did commit 2 [0]']);
1166 + expect(Scheduler).toHaveYielded(['Did commit 1 [0]', 'Did commit 2 [0]']);
1167
1168 ReactNoop.render(<Counter count={1} />, () =>
1169 ReactNoop.yield('Sync effect'),
1170 );
1171 - expect(ReactNoop).toFlushAndYieldThrough(['Count: 1', 'Sync effect']);
1171 + expect(Scheduler).toFlushAndYieldThrough(['Count: 1', 'Sync effect']);
1172 expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]);
1173 ReactNoop.flushPassiveEffects();
1174 - expect(ReactNoop).toHaveYielded(['Did commit 1 [1]', 'Did commit 2 [1]']);
1174 + expect(Scheduler).toHaveYielded(['Did commit 1 [1]', 'Did commit 2 [1]']);
1175 });
1176
1177 it('unmounts all previous effects before creating any new ones', () => {
@@ -1193,18 +1193,18 @@ describe('ReactHooksWithNoopRenderer', () => {
1193 ReactNoop.render(<Counter count={0} />, () =>
1194 ReactNoop.yield('Sync effect'),
1195 );
1196 - expect(ReactNoop).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
1196 + expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
1197 expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
1198 ReactNoop.flushPassiveEffects();
1199 - expect(ReactNoop).toHaveYielded(['Mount A [0]', 'Mount B [0]']);
1199 + expect(Scheduler).toHaveYielded(['Mount A [0]', 'Mount B [0]']);
1200
1201 ReactNoop.render(<Counter count={1} />, () =>
1202 ReactNoop.yield('Sync effect'),
1203 );
1204 - expect(ReactNoop).toFlushAndYieldThrough(['Count: 1', 'Sync effect']);
1204 + expect(Scheduler).toFlushAndYieldThrough(['Count: 1', 'Sync effect']);
1205 expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]);
1206 ReactNoop.flushPassiveEffects();
1207 - expect(ReactNoop).toHaveYielded([
1207 + expect(Scheduler).toHaveYielded([
1208 'Unmount A [0]',
1209 'Unmount B [0]',
1210 'Mount A [1]',
@@ -1234,10 +1234,10 @@ describe('ReactHooksWithNoopRenderer', () => {
1234 ReactNoop.render(<Counter count={0} />, () =>
1235 ReactNoop.yield('Sync effect'),
1236 );
1237 - expect(ReactNoop).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
1237 + expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
1238 expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
1239 expect(() => ReactNoop.flushPassiveEffects()).toThrow('Oops');
1240 - expect(ReactNoop).toHaveYielded([
1240 + expect(Scheduler).toHaveYielded([
1241 'Mount A [0]',
1242 'Oops!',
1243 // Clean up effect A. There's no effect B to clean-up, because it
@@ -1270,19 +1270,19 @@ describe('ReactHooksWithNoopRenderer', () => {
1270 ReactNoop.render(<Counter count={0} />, () =>
1271 ReactNoop.yield('Sync effect'),
1272 );
1273 - expect(ReactNoop).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
1273 + expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
1274 expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
1275 ReactNoop.flushPassiveEffects();
1276 - expect(ReactNoop).toHaveYielded(['Mount A [0]', 'Mount B [0]']);
1276 + expect(Scheduler).toHaveYielded(['Mount A [0]', 'Mount B [0]']);
1277
1278 // This update will trigger an errror
1279 ReactNoop.render(<Counter count={1} />, () =>
1280 ReactNoop.yield('Sync effect'),
1281 );
1282 - expect(ReactNoop).toFlushAndYieldThrough(['Count: 1', 'Sync effect']);
1282 + expect(Scheduler).toFlushAndYieldThrough(['Count: 1', 'Sync effect']);
1283 expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]);
1284 expect(() => ReactNoop.flushPassiveEffects()).toThrow('Oops');
1285 - expect(ReactNoop).toHaveYielded([
1285 + expect(Scheduler).toHaveYielded([
1286 'Unmount A [0]',
1287 'Unmount B [0]',
1288 'Mount A [1]',
@@ -1316,19 +1316,19 @@ describe('ReactHooksWithNoopRenderer', () => {
1316 ReactNoop.render(<Counter count={0} />, () =>
1317 ReactNoop.yield('Sync effect'),
1318 );
1319 - expect(ReactNoop).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
1319 + expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
1320 expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
1321 ReactNoop.flushPassiveEffects();
1322 - expect(ReactNoop).toHaveYielded(['Mount A [0]', 'Mount B [0]']);
1322 + expect(Scheduler).toHaveYielded(['Mount A [0]', 'Mount B [0]']);
1323
1324 // This update will trigger an errror
1325 ReactNoop.render(<Counter count={1} />, () =>
1326 ReactNoop.yield('Sync effect'),
1327 );
1328 - expect(ReactNoop).toFlushAndYieldThrough(['Count: 1', 'Sync effect']);
1328 + expect(Scheduler).toFlushAndYieldThrough(['Count: 1', 'Sync effect']);
1329 expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]);
1330 expect(() => ReactNoop.flushPassiveEffects()).toThrow('Oops');
1331 - expect(ReactNoop).toHaveYielded([
1331 + expect(Scheduler).toHaveYielded([
1332 'Oops!',
1333 // B unmounts even though an error was thrown in the previous effect
1334 'Unmount B [0]',
@@ -1349,7 +1349,7 @@ describe('ReactHooksWithNoopRenderer', () => {
1349 ReactNoop.render(<Counter count={0} />, () =>
1350 ReactNoop.yield('Sync effect'),
1351 );
1352 - expect(ReactNoop).toFlushAndYieldThrough([
1352 + expect(Scheduler).toFlushAndYieldThrough([
1353 'Count: 0',
1354 'Mount: 0',
1355 'Sync effect',
@@ -1359,7 +1359,7 @@ describe('ReactHooksWithNoopRenderer', () => {
1359 ReactNoop.render(<Counter count={1} />, () =>
1360 ReactNoop.yield('Sync effect'),
1361 );
1362 - expect(ReactNoop).toFlushAndYieldThrough([
1362 + expect(Scheduler).toFlushAndYieldThrough([
1363 'Count: 1',
1364 'Unmount: 0',
1365 'Mount: 1',
@@ -1368,7 +1368,7 @@ describe('ReactHooksWithNoopRenderer', () => {
1368 expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]);
1369
1370 ReactNoop.render(null);
1371 - expect(ReactNoop).toFlushAndYieldThrough(['Unmount: 1']);
1371 + expect(Scheduler).toFlushAndYieldThrough(['Unmount: 1']);
1372 expect(ReactNoop.getChildren()).toEqual([]);
1373 });
1374 });
@@ -1395,7 +1395,7 @@ describe('ReactHooksWithNoopRenderer', () => {
1395 ReactNoop.render(<Counter count={0} />, () =>
1396 ReactNoop.yield('Sync effect'),
1397 );
1398 - expect(ReactNoop).toFlushAndYieldThrough([
1398 + expect(Scheduler).toFlushAndYieldThrough([
1399 [0],
1400 'Current: 0',
1401 'Sync effect',
@@ -1405,7 +1405,7 @@ describe('ReactHooksWithNoopRenderer', () => {
1405 ReactNoop.render(<Counter count={1} />, () =>
1406 ReactNoop.yield('Sync effect'),
1407 );
1408 - expect(ReactNoop).toFlushAndYieldThrough([
1408 + expect(Scheduler).toFlushAndYieldThrough([
1409 [1],
1410 'Current: 1',
1411 'Sync effect',
@@ -1439,7 +1439,7 @@ describe('ReactHooksWithNoopRenderer', () => {
1439 ReactNoop.render(<Counter count={0} />, () =>
1440 ReactNoop.yield('Sync effect'),
1441 );
1442 - expect(ReactNoop).toFlushAndYieldThrough([
1442 + expect(Scheduler).toFlushAndYieldThrough([
1443 'Mount layout [current: 0]',
1444 'Sync effect',
1445 ]);
@@ -1448,8 +1448,8 @@ describe('ReactHooksWithNoopRenderer', () => {
1448 ReactNoop.render(<Counter count={1} />, () =>
1449 ReactNoop.yield('Sync effect'),
1450 );
1451 - expect(ReactNoop).toHaveYielded(['Mount normal [current: 0]']);
1452 - expect(ReactNoop).toFlushAndYieldThrough([
1451 + expect(Scheduler).toHaveYielded(['Mount normal [current: 0]']);
1452 + expect(Scheduler).toFlushAndYieldThrough([
1453 'Unmount layout [current: 0]',
1454 'Mount layout [current: 1]',
1455 'Sync effect',
@@ -1457,7 +1457,7 @@ describe('ReactHooksWithNoopRenderer', () => {
1457 expect(committedText).toEqual('1');
1458
1459 ReactNoop.flushPassiveEffects();
1460 - expect(ReactNoop).toHaveYielded([
1460 + expect(Scheduler).toHaveYielded([
1461 'Unmount normal [current: 1]',
1462 'Mount normal [current: 1]',
1463 ]);
@@ -1490,14 +1490,14 @@ describe('ReactHooksWithNoopRenderer', () => {
1490
1491 const button = React.createRef(null);
1492 ReactNoop.render(<Counter incrementBy={1} />);
1493 - expect(ReactNoop).toFlushAndYield(['Increment', 'Count: 0']);
1493 + expect(Scheduler).toFlushAndYield(['Increment', 'Count: 0']);
1494 expect(ReactNoop.getChildren()).toEqual([
1495 span('Increment'),
1496 span('Count: 0'),
1497 ]);
1498
1499 act(button.current.increment);
1500 - expect(ReactNoop).toFlushAndYield([
1500 + expect(Scheduler).toFlushAndYield([
1501 // Button should not re-render, because its props haven't changed
1502 // 'Increment',
1503 'Count: 1',
@@ -1509,7 +1509,7 @@ describe('ReactHooksWithNoopRenderer', () => {
1509
1510 // Increase the increment amount
1511 ReactNoop.render(<Counter incrementBy={10} />);
1512 - expect(ReactNoop).toFlushAndYield([
1512 + expect(Scheduler).toFlushAndYield([
1513 // Inputs did change this time
1514 'Increment',
1515 'Count: 1',
@@ -1521,7 +1521,7 @@ describe('ReactHooksWithNoopRenderer', () => {
1521
1522 // Callback should have updated
1523 act(button.current.increment);
1524 - expect(ReactNoop).toFlushAndYield(['Count: 11']);
1524 + expect(Scheduler).toFlushAndYield(['Count: 11']);
1525 expect(ReactNoop.getChildren()).toEqual([
1526 span('Increment'),
1527 span('Count: 11'),
@@ -1544,19 +1544,19 @@ describe('ReactHooksWithNoopRenderer', () => {
1544 }
1545
1546 ReactNoop.render(<CapitalizedText text="hello" />);
1547 - expect(ReactNoop).toFlushAndYield(["Capitalize 'hello'", 'HELLO']);
1547 + expect(Scheduler).toFlushAndYield(["Capitalize 'hello'", 'HELLO']);
1548 expect(ReactNoop.getChildren()).toEqual([span('HELLO')]);
1549
1550 ReactNoop.render(<CapitalizedText text="hi" />);
1551 - expect(ReactNoop).toFlushAndYield(["Capitalize 'hi'", 'HI']);
1551 + expect(Scheduler).toFlushAndYield(["Capitalize 'hi'", 'HI']);
1552 expect(ReactNoop.getChildren()).toEqual([span('HI')]);
1553
1554 ReactNoop.render(<CapitalizedText text="hi" />);
1555 - expect(ReactNoop).toFlushAndYield(['HI']);
1555 + expect(Scheduler).toFlushAndYield(['HI']);
1556 expect(ReactNoop.getChildren()).toEqual([span('HI')]);
1557
1558 ReactNoop.render(<CapitalizedText text="goodbye" />);
1559 - expect(ReactNoop).toFlushAndYield(["Capitalize 'goodbye'", 'GOODBYE']);
1559 + expect(Scheduler).toFlushAndYield(["Capitalize 'goodbye'", 'GOODBYE']);
1560 expect(ReactNoop.getChildren()).toEqual([span('GOODBYE')]);
1561 });
1562
@@ -1577,16 +1577,16 @@ describe('ReactHooksWithNoopRenderer', () => {
1577 }
1578
1579 ReactNoop.render(<LazyCompute compute={computeA} />);
1580 - expect(ReactNoop).toFlushAndYield(['compute A', 'A']);
1580 + expect(Scheduler).toFlushAndYield(['compute A', 'A']);
1581
1582 ReactNoop.render(<LazyCompute compute={computeA} />);
1583 - expect(ReactNoop).toFlushAndYield(['compute A', 'A']);
1583 + expect(Scheduler).toFlushAndYield(['compute A', 'A']);
1584
1585 ReactNoop.render(<LazyCompute compute={computeA} />);
1586 - expect(ReactNoop).toFlushAndYield(['compute A', 'A']);
1586 + expect(Scheduler).toFlushAndYield(['compute A', 'A']);
1587
1588 ReactNoop.render(<LazyCompute compute={computeB} />);
1589 - expect(ReactNoop).toFlushAndYield(['compute B', 'B']);
1589 + expect(Scheduler).toFlushAndYield(['compute B', 'B']);
1590 });
1591
1592 it('should not invoke memoized function during re-renders unless inputs change', () => {
@@ -1607,13 +1607,13 @@ describe('ReactHooksWithNoopRenderer', () => {
1607 }
1608
1609 ReactNoop.render(<LazyCompute compute={compute} input="A" />);
1610 - expect(ReactNoop).toFlushAndYield(['compute A', 'A']);
1610 + expect(Scheduler).toFlushAndYield(['compute A', 'A']);
1611
1612 ReactNoop.render(<LazyCompute compute={compute} input="A" />);
1613 - expect(ReactNoop).toFlushAndYield(['A']);
1613 + expect(Scheduler).toFlushAndYield(['A']);
1614
1615 ReactNoop.render(<LazyCompute compute={compute} input="B" />);
1616 - expect(ReactNoop).toFlushAndYield(['compute B', 'B']);
1616 + expect(Scheduler).toFlushAndYield(['compute B', 'B']);
1617 });
1618 });
1619
@@ -1651,17 +1651,17 @@ describe('ReactHooksWithNoopRenderer', () => {
1651 }
1652
1653 ReactNoop.render(<App />);
1654 - expect(ReactNoop).toFlushAndYield([]);
1654 + expect(Scheduler).toFlushAndYield([]);
1655
1656 ping(1);
1657 ping(2);
1658 ping(3);
1659
1660 - expect(ReactNoop).toHaveYielded([]);
1660 + expect(Scheduler).toHaveYielded([]);
1661
1662 jest.advanceTimersByTime(100);
1663
1664 - expect(ReactNoop).toHaveYielded(['ping: 3']);
1664 + expect(Scheduler).toHaveYielded(['ping: 3']);
1665
1666 ping(4);
1667 jest.advanceTimersByTime(20);
@@ -1669,10 +1669,10 @@ describe('ReactHooksWithNoopRenderer', () => {
1669 ping(6);
1670 jest.advanceTimersByTime(80);
1671
1672 - expect(ReactNoop).toHaveYielded([]);
1672 + expect(Scheduler).toHaveYielded([]);
1673
1674 jest.advanceTimersByTime(20);
1675 - expect(ReactNoop).toHaveYielded(['ping: 6']);
1675 + expect(Scheduler).toHaveYielded(['ping: 6']);
1676 });
1677
1678 it('should return the same ref during re-renders', () => {
@@ -1693,10 +1693,10 @@ describe('ReactHooksWithNoopRenderer', () => {
1693 }
1694
1695 ReactNoop.render(<Counter />);
1696 - expect(ReactNoop).toFlushAndYield(['val']);
1696 + expect(Scheduler).toFlushAndYield(['val']);
1697
1698 ReactNoop.render(<Counter />);
1699 - expect(ReactNoop).toFlushAndYield(['val']);
1699 + expect(Scheduler).toFlushAndYield(['val']);
1700 });
1701 });
1702
@@ -1717,14 +1717,14 @@ describe('ReactHooksWithNoopRenderer', () => {
1717 Counter = forwardRef(Counter);
1718 const counter = React.createRef(null);
1719 ReactNoop.render(<Counter ref={counter} />);
1720 - expect(ReactNoop).toFlushAndYield(['Count: 0']);
1720 + expect(Scheduler).toFlushAndYield(['Count: 0']);
1721 expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
1722 expect(counter.current.count).toBe(0);
1723
1724 act(() => {
1725 counter.current.dispatch(INCREMENT);
1726 });
1727 - expect(ReactNoop).toFlushAndYield(['Count: 1']);
1727 + expect(Scheduler).toFlushAndYield(['Count: 1']);
1728 expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]);
1729 // Intentionally not updated because of [] deps:
1730 expect(counter.current.count).toBe(0);
@@ -1747,14 +1747,14 @@ describe('ReactHooksWithNoopRenderer', () => {
1747 Counter = forwardRef(Counter);
1748 const counter = React.createRef(null);
1749 ReactNoop.render(<Counter ref={counter} />);
1750 - expect(ReactNoop).toFlushAndYield(['Count: 0']);
1750 + expect(Scheduler).toFlushAndYield(['Count: 0']);
1751 expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
1752 expect(counter.current.count).toBe(0);
1753
1754 act(() => {
1755 counter.current.dispatch(INCREMENT);
1756 });
1757 - expect(ReactNoop).toFlushAndYield(['Count: 1']);
1757 + expect(Scheduler).toFlushAndYield(['Count: 1']);
1758 expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]);
1759 expect(counter.current.count).toBe(1);
1760 });
@@ -1783,7 +1783,7 @@ describe('ReactHooksWithNoopRenderer', () => {
1783 Counter = forwardRef(Counter);
1784 const counter = React.createRef(null);
1785 ReactNoop.render(<Counter ref={counter} />);
1786 - expect(ReactNoop).toFlushAndYield(['Count: 0']);
1786 + expect(Scheduler).toFlushAndYield(['Count: 0']);
1787 expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
1788 expect(counter.current.count).toBe(0);
1789 expect(totalRefUpdates).toBe(1);
@@ -1791,14 +1791,14 @@ describe('ReactHooksWithNoopRenderer', () => {
1791 act(() => {
1792 counter.current.dispatch(INCREMENT);
1793 });
1794 - expect(ReactNoop).toFlushAndYield(['Count: 1']);
1794 + expect(Scheduler).toFlushAndYield(['Count: 1']);
1795 expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]);
1796 expect(counter.current.count).toBe(1);
1797 expect(totalRefUpdates).toBe(2);
1798
1799 // Update that doesn't change the ref dependencies
1800 ReactNoop.render(<Counter ref={counter} />);
1801 - expect(ReactNoop).toFlushAndYield(['Count: 1']);
1801 + expect(Scheduler).toFlushAndYield(['Count: 1']);
1802 expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]);
1803 expect(counter.current.count).toBe(1);
1804 expect(totalRefUpdates).toBe(2); // Should not increase since last time
@@ -1828,7 +1828,7 @@ describe('ReactHooksWithNoopRenderer', () => {
1828 }
1829
1830 ReactNoop.render(<App loadC={false} />);
1831 - expect(ReactNoop).toFlushAndYield(['A: 0, B: 0, C: [not loaded]']);
1831 + expect(Scheduler).toFlushAndYield(['A: 0, B: 0, C: [not loaded]']);
1832 expect(ReactNoop.getChildren()).toEqual([
1833 span('A: 0, B: 0, C: [not loaded]'),
1834 ]);
@@ -1838,7 +1838,7 @@ describe('ReactHooksWithNoopRenderer', () => {
1838 updateB(3);
1839 });
1840
1841 - expect(ReactNoop).toFlushAndYield(['A: 2, B: 3, C: [not loaded]']);
1841 + expect(Scheduler).toFlushAndYield(['A: 2, B: 3, C: [not loaded]']);
1842 expect(ReactNoop.getChildren()).toEqual([
1843 span('A: 2, B: 3, C: [not loaded]'),
1844 ]);
@@ -1846,7 +1846,7 @@ describe('ReactHooksWithNoopRenderer', () => {
1846 ReactNoop.render(<App loadC={true} />);
1847 expect(() => {
1848 expect(() => {
1849 - expect(ReactNoop).toFlushAndYield(['A: 2, B: 3, C: 0']);
1849 + expect(Scheduler).toFlushAndYield(['A: 2, B: 3, C: 0']);
1850 }).toThrow('Rendered more hooks than during the previous render');
1851 }).toWarnDev([
1852 'Warning: React has detected a change in the order of Hooks called by App. ' +
@@ -1864,7 +1864,7 @@ describe('ReactHooksWithNoopRenderer', () => {
1864 // expect(ReactNoop.getChildren()).toEqual([span('A: 2, B: 3, C: 0')]);
1865
1866 // updateC(4);
1867 - // expect(ReactNoop).toFlushAndYield(['A: 2, B: 3, C: 4']);
1867 + // expect(Scheduler).toFlushAndYield(['A: 2, B: 3, C: 4']);
1868 // expect(ReactNoop.getChildren()).toEqual([span('A: 2, B: 3, C: 4')]);
1869 });
1870
@@ -1892,17 +1892,17 @@ describe('ReactHooksWithNoopRenderer', () => {
1892 }
1893
1894 ReactNoop.render(<App loadC={true} />);
1895 - expect(ReactNoop).toFlushAndYield(['A: 0, B: 0, C: 0']);
1895 + expect(Scheduler).toFlushAndYield(['A: 0, B: 0, C: 0']);
1896 expect(ReactNoop.getChildren()).toEqual([span('A: 0, B: 0, C: 0')]);
1897 act(() => {
1898 updateA(2);
1899 updateB(3);
1900 updateC(4);
1901 });
1902 - expect(ReactNoop).toFlushAndYield(['A: 2, B: 3, C: 4']);
1902 + expect(Scheduler).toFlushAndYield(['A: 2, B: 3, C: 4']);
1903 expect(ReactNoop.getChildren()).toEqual([span('A: 2, B: 3, C: 4')]);
1904 ReactNoop.render(<App loadC={false} />);
1905 - expect(ReactNoop).toFlushAndThrow(
1905 + expect(Scheduler).toFlushAndThrow(
1906 'Rendered fewer hooks than expected. This may be caused by an ' +
1907 'accidental early return statement.',
1908 );
@@ -1932,14 +1932,14 @@ describe('ReactHooksWithNoopRenderer', () => {
1932 ReactNoop.render(<App showMore={false} />, () =>
1933 ReactNoop.yield('Sync effect'),
1934 );
1935 - expect(ReactNoop).toFlushAndYieldThrough(['Sync effect']);
1935 + expect(Scheduler).toFlushAndYieldThrough(['Sync effect']);
1936 ReactNoop.flushPassiveEffects();
1937 - expect(ReactNoop).toHaveYielded(['Mount A']);
1937 + expect(Scheduler).toHaveYielded(['Mount A']);
1938
1939 ReactNoop.render(<App showMore={true} />);
1940 expect(() => {
1941 expect(() => {
1942 - expect(ReactNoop).toFlushAndYield([]);
1942 + expect(Scheduler).toFlushAndYield([]);
1943 }).toThrow('Rendered more hooks than during the previous render');
1944 }).toWarnDev([
1945 'Warning: React has detected a change in the order of Hooks called by App. ' +
@@ -1954,10 +1954,10 @@ describe('ReactHooksWithNoopRenderer', () => {
1954
1955 // Uncomment if/when we support this again
1956 // ReactNoop.flushPassiveEffects();
1957 - // expect(ReactNoop).toHaveYielded(['Mount B']);
1957 + // expect(Scheduler).toHaveYielded(['Mount B']);
1958
1959 // ReactNoop.render(<App showMore={false} />);
1960 - // expect(ReactNoop).toFlushAndThrow(
1960 + // expect(Scheduler).toFlushAndThrow(
1961 // 'Rendered fewer hooks than expected. This may be caused by an ' +
1962 // 'accidental early return statement.',
1963 // );
packages/react-reconciler/src/__tests__/ReactIncremental-test.internal.js
+104 -101
@@ -13,6 +13,7 @@
13 let React;
14 let ReactFeatureFlags;
15 let ReactNoop;
16 +let Scheduler;
17 let PropTypes;
18
19 describe('ReactIncremental', () => {
@@ -22,6 +23,7 @@ describe('ReactIncremental', () => {
23 ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false;
24 React = require('react');
25 ReactNoop = require('react-noop-renderer');
26 + Scheduler = require('scheduler');
27 PropTypes = require('prop-types');
28 });
29
@@ -35,7 +37,7 @@ describe('ReactIncremental', () => {
37 }
38
39 ReactNoop.render(<Foo />);
38 - expect(ReactNoop).toFlushWithoutYielding();
40 + expect(Scheduler).toFlushWithoutYielding();
41 });
42
43 it('should render a simple component, in steps if needed', () => {
@@ -58,7 +60,7 @@ describe('ReactIncremental', () => {
60 expect(ReactNoop.flushNextYield()).toEqual(['Foo']);
61
62 // Do the rest of the work.
61 - expect(ReactNoop).toFlushAndYield(['Bar', 'Bar', 'callback']);
63 + expect(Scheduler).toFlushAndYield(['Bar', 'Bar', 'callback']);
64 });
65
66 it('updates a previous render', () => {
@@ -96,7 +98,7 @@ describe('ReactIncremental', () => {
98 ReactNoop.render(<Foo text="foo" />, () =>
99 ops.push('renderCallbackCalled'),
100 );
99 - expect(ReactNoop).toFlushWithoutYielding();
101 + expect(Scheduler).toFlushWithoutYielding();
102
103 expect(ops).toEqual([
104 'Foo',
@@ -114,7 +116,7 @@ describe('ReactIncremental', () => {
116 ReactNoop.render(<Foo text="bar" />, () =>
117 ops.push('secondRenderCallbackCalled'),
118 );
117 - expect(ReactNoop).toFlushWithoutYielding();
119 + expect(Scheduler).toFlushWithoutYielding();
120
121 // TODO: Test bail out of host components. This is currently unobservable.
122
@@ -146,21 +148,21 @@ describe('ReactIncremental', () => {
148
149 // Init
150 ReactNoop.render(<Foo text="foo" />);
149 - expect(ReactNoop).toFlushAndYield(['Foo', 'Bar', 'Bar']);
151 + expect(Scheduler).toFlushAndYield(['Foo', 'Bar', 'Bar']);
152
153 ReactNoop.render(<Foo text="bar" />);
154 // Flush part of the work
153 - expect(ReactNoop).toFlushAndYieldThrough(['Foo', 'Bar']);
155 + expect(Scheduler).toFlushAndYieldThrough(['Foo', 'Bar']);
156
157 // This will abort the previous work and restart
158 ReactNoop.flushSync(() => ReactNoop.render(null));
159 ReactNoop.render(<Foo text="baz" />);
160
161 // Flush part of the new work
160 - expect(ReactNoop).toFlushAndYieldThrough(['Foo', 'Bar']);
162 + expect(Scheduler).toFlushAndYieldThrough(['Foo', 'Bar']);
163
164 // Flush the rest of the work which now includes the low priority
163 - expect(ReactNoop).toFlushAndYield(['Bar']);
165 + expect(Scheduler).toFlushAndYield(['Bar']);
166 });
167
168 it('should call callbacks even if updates are aborted', () => {
@@ -186,7 +188,7 @@ describe('ReactIncremental', () => {
188 }
189
190 ReactNoop.render(<Foo />);
189 - expect(ReactNoop).toFlushWithoutYielding();
191 + expect(Scheduler).toFlushWithoutYielding();
192
193 inst.setState(
194 () => {
@@ -197,7 +199,7 @@ describe('ReactIncremental', () => {
199 );
200
201 // Flush part of the work
200 - expect(ReactNoop).toFlushAndYieldThrough(['setState1']);
202 + expect(Scheduler).toFlushAndYieldThrough(['setState1']);
203
204 // This will abort the previous work and restart
205 ReactNoop.flushSync(() => ReactNoop.render(<Foo />));
@@ -210,7 +212,7 @@ describe('ReactIncremental', () => {
212 );
213
214 // Flush the rest of the work which now includes the low priority
213 - expect(ReactNoop).toFlushAndYield([
215 + expect(Scheduler).toFlushAndYield([
216 'setState1',
217 'setState2',
218 'callback1',
@@ -248,7 +250,7 @@ describe('ReactIncremental', () => {
250
251 // Init
252 ReactNoop.render(<Foo text="foo" />);
251 - expect(ReactNoop).toFlushAndYield([
253 + expect(Scheduler).toFlushAndYield([
254 'Foo',
255 'Bar',
256 'Bar',
@@ -259,9 +261,9 @@ describe('ReactIncremental', () => {
261 // Render part of the work. This should be enough to flush everything except
262 // the middle which has lower priority.
263 ReactNoop.render(<Foo text="bar" />);
262 - expect(ReactNoop).toFlushAndYieldThrough(['Foo', 'Bar', 'Bar']);
264 + expect(Scheduler).toFlushAndYieldThrough(['Foo', 'Bar', 'Bar']);
265 // Flush only the remaining work
264 - expect(ReactNoop).toFlushAndYield(['Middle', 'Middle']);
266 + expect(Scheduler).toFlushAndYield(['Middle', 'Middle']);
267 });
268
269 it('can deprioritize a tree from without dropping work', () => {
@@ -297,7 +299,7 @@ describe('ReactIncremental', () => {
299 ReactNoop.flushSync(() => {
300 ReactNoop.render(<Foo text="foo" />);
301 });
300 - expect(ReactNoop).toFlushWithoutYielding();
302 + expect(Scheduler).toFlushWithoutYielding();
303 expect(ops).toEqual(['Foo', 'Bar', 'Bar', 'Middle', 'Middle']);
304
305 ops = [];
@@ -312,7 +314,7 @@ describe('ReactIncremental', () => {
314
315 // The hidden content was deprioritized from high to low priority. A low
316 // priority callback should have been scheduled. Flush it now.
315 - expect(ReactNoop).toFlushWithoutYielding();
317 + expect(Scheduler).toFlushWithoutYielding();
318 expect(ops).toEqual(['Middle', 'Middle']);
319 });
320
@@ -375,7 +377,7 @@ describe('ReactIncremental', () => {
377 ops = [];
378
379 // Flush the rest to make sure that the bailout didn't block this work.
378 - expect(ReactNoop).toFlushWithoutYielding();
380 + expect(Scheduler).toFlushWithoutYielding();
381 expect(ops).toEqual(['Middle']);
382 });
383
@@ -455,7 +457,7 @@ describe('ReactIncremental', () => {
457 // as a single batch. Therefore, it is correct that Middle should be in the
458 // middle. If it occurs after the two "Bar" components then it was flushed
459 // after them which is not correct.
458 - expect(ReactNoop).toFlushWithoutYielding();
460 + expect(Scheduler).toFlushWithoutYielding();
461 expect(ops).toEqual(['Bar', 'Middle', 'Bar']);
462
463 ops = [];
@@ -473,7 +475,7 @@ describe('ReactIncremental', () => {
475 // it. If the priority levels aren't down-prioritized correctly this may
476 // abort rendering of the down-prioritized content.
477 ReactNoop.render(<Foo text="bar" />);
476 - expect(ReactNoop).toFlushWithoutYielding();
478 + expect(Scheduler).toFlushWithoutYielding();
479 expect(ops).toEqual(['Foo', 'Bar', 'Bar']);
480 });
481
@@ -514,7 +516,7 @@ describe('ReactIncremental', () => {
516 foo.setState({value: 'bar'});
517
518 ops = [];
517 - expect(ReactNoop).toFlushWithoutYielding();
519 + expect(Scheduler).toFlushWithoutYielding();
520 expect(ops).toEqual(['Foo', 'Bar']);
521 });
522
@@ -577,7 +579,7 @@ describe('ReactIncremental', () => {
579 foo.setState({value: 'bar'});
580
581 ops = [];
580 - expect(ReactNoop).toFlushWithoutYielding();
582 + expect(Scheduler).toFlushWithoutYielding();
583 expect(constructorCount).toEqual(1);
584 expect(ops).toEqual([
585 'componentWillMount: foo',
@@ -639,7 +641,7 @@ describe('ReactIncremental', () => {
641 // Interrupt the rendering with a quick update. This should not touch the
642 // middle content.
643 ReactNoop.render(<Foo text="foo" text2="bar" step={0} />);
642 - expect(ReactNoop).toFlushWithoutYielding();
644 + expect(Scheduler).toFlushWithoutYielding();
645
646 // We've now rendered the entire tree but we didn't have to redo the work
647 // done by the first Middle and Bar already.
@@ -674,7 +676,7 @@ describe('ReactIncremental', () => {
676 // Since we did nothing to the middle subtree during the interruption,
677 // we should be able to reuse the reconciliation work that we already did
678 // without restarting.
677 - expect(ReactNoop).toFlushWithoutYielding();
679 + expect(Scheduler).toFlushWithoutYielding();
680 expect(ops).toEqual(['Middle']);
681 });
682
@@ -727,7 +729,7 @@ describe('ReactIncremental', () => {
729 }
730
731 ReactNoop.render(<Parent />);
730 - expect(ReactNoop).toFlushWithoutYielding();
732 + expect(Scheduler).toFlushWithoutYielding();
733 ops = [];
734
735 // Begin working on a low priority update to Child, but stop before
@@ -747,7 +749,7 @@ describe('ReactIncremental', () => {
749 // Continue the low pri work. The work on Child and GrandChild was memoized
750 // so they should not be worked on again.
751 ops = [];
750 - expect(ReactNoop).toFlushWithoutYielding();
752 + expect(Scheduler).toFlushWithoutYielding();
753 expect(ops).toEqual([
754 // No Child
755 // No Grandchild
@@ -803,7 +805,7 @@ describe('ReactIncremental', () => {
805
806 // Init
807 ReactNoop.render(<Foo text="foo" step={0} />);
806 - expect(ReactNoop).toFlushWithoutYielding();
808 + expect(Scheduler).toFlushWithoutYielding();
809
810 expect(ops).toEqual(['Foo', 'Bar', 'Content', 'Middle', 'Bar', 'Middle']);
811
@@ -836,7 +838,7 @@ describe('ReactIncremental', () => {
838 // Since we did nothing to the middle subtree during the interruption,
839 // we should be able to reuse the reconciliation work that we already did
840 // without restarting.
839 - expect(ReactNoop).toFlushWithoutYielding();
841 + expect(Scheduler).toFlushWithoutYielding();
842 expect(ops).toEqual(['Middle']);
843 });
844
@@ -857,16 +859,16 @@ describe('ReactIncremental', () => {
859 }
860
861 ReactNoop.render(<Foo step={1} />);
860 - expect(ReactNoop).toFlushWithoutYielding();
862 + expect(Scheduler).toFlushWithoutYielding();
863
864 ops = [];
865 ReactNoop.render(<Foo step={2} />);
864 - expect(ReactNoop).toFlushWithoutYielding();
866 + expect(Scheduler).toFlushWithoutYielding();
867 expect(ops).toEqual(['shouldComponentUpdate: false']);
868
869 ops = [];
870 ReactNoop.render(<Foo step={3} />);
869 - expect(ReactNoop).toFlushWithoutYielding();
871 + expect(Scheduler).toFlushWithoutYielding();
872 expect(ops).toEqual([
873 // If the memoized props were not updated during last bail out, sCU will
874 // keep returning false.
@@ -897,10 +899,10 @@ describe('ReactIncremental', () => {
899 }
900
901 ReactNoop.render(<Foo />);
900 - expect(ReactNoop).toFlushWithoutYielding();
902 + expect(Scheduler).toFlushWithoutYielding();
903 expect(instance.state).toEqual({a: 'a'});
904 instance.setState({b: 'b'});
903 - expect(ReactNoop).toFlushWithoutYielding();
905 + expect(Scheduler).toFlushWithoutYielding();
906 expect(instance.state).toEqual({a: 'a', b: 'b'});
907 });
908
@@ -926,12 +928,12 @@ describe('ReactIncremental', () => {
928 }
929
930 ReactNoop.render(<Foo />);
929 - expect(ReactNoop).toFlushWithoutYielding();
931 + expect(Scheduler).toFlushWithoutYielding();
932 // Call setState multiple times before flushing
933 instance.setState({b: 'b'});
934 instance.setState({c: 'c'});
935 instance.setState({d: 'd'});
934 - expect(ReactNoop).toFlushWithoutYielding();
936 + expect(Scheduler).toFlushWithoutYielding();
937 expect(instance.state).toEqual({a: 'a', b: 'b', c: 'c', d: 'd'});
938 });
939
@@ -961,15 +963,15 @@ describe('ReactIncremental', () => {
963 }
964
965 ReactNoop.render(<Foo multiplier={2} />);
964 - expect(ReactNoop).toFlushWithoutYielding();
966 + expect(Scheduler).toFlushWithoutYielding();
967 expect(instance.state.num).toEqual(1);
968 instance.setState(updater);
967 - expect(ReactNoop).toFlushWithoutYielding();
969 + expect(Scheduler).toFlushWithoutYielding();
970 expect(instance.state.num).toEqual(2);
971
972 instance.setState(updater);
973 ReactNoop.render(<Foo multiplier={3} />);
972 - expect(ReactNoop).toFlushWithoutYielding();
974 + expect(Scheduler).toFlushWithoutYielding();
975 expect(instance.state.num).toEqual(6);
976 });
977
@@ -1003,10 +1005,10 @@ describe('ReactIncremental', () => {
1005 }
1006
1007 ReactNoop.render(<Foo multiplier={2} />);
1006 - expect(ReactNoop).toFlushWithoutYielding();
1008 + expect(Scheduler).toFlushWithoutYielding();
1009 instance.setState(updater);
1010 instance.setState(updater, callback);
1009 - expect(ReactNoop).toFlushWithoutYielding();
1011 + expect(Scheduler).toFlushWithoutYielding();
1012 expect(instance.state.num).toEqual(4);
1013 expect(instance.state.called).toEqual(true);
1014 });
@@ -1030,11 +1032,11 @@ describe('ReactIncremental', () => {
1032 }
1033
1034 ReactNoop.render(<Foo />);
1033 - expect(ReactNoop).toFlushWithoutYielding();
1035 + expect(Scheduler).toFlushWithoutYielding();
1036 instance.setState({b: 'b'});
1037 instance.setState({c: 'c'});
1038 instance.updater.enqueueReplaceState(instance, {d: 'd'});
1037 - expect(ReactNoop).toFlushWithoutYielding();
1039 + expect(Scheduler).toFlushWithoutYielding();
1040 expect(instance.state).toEqual({d: 'd'});
1041 });
1042
@@ -1071,10 +1073,10 @@ describe('ReactIncremental', () => {
1073 }
1074
1075 ReactNoop.render(<Foo />);
1074 - expect(ReactNoop).toFlushWithoutYielding();
1076 + expect(Scheduler).toFlushWithoutYielding();
1077 expect(ops).toEqual(['Foo', 'Bar', 'Baz']);
1078 instance.forceUpdate();
1077 - expect(ReactNoop).toFlushWithoutYielding();
1079 + expect(Scheduler).toFlushWithoutYielding();
1080 expect(ops).toEqual(['Foo', 'Bar', 'Baz', 'Bar', 'Baz']);
1081 });
1082
@@ -1091,14 +1093,14 @@ describe('ReactIncremental', () => {
1093
1094 const foo = React.createRef(null);
1095 ReactNoop.render(<Foo ref={foo} b={0} />);
1094 - expect(ReactNoop).toFlushAndYield(['A: 0, B: 0']);
1096 + expect(Scheduler).toFlushAndYield(['A: 0, B: 0']);
1097
1098 a = 1;
1099 foo.current.forceUpdate();
1098 - expect(ReactNoop).toFlushAndYield(['A: 1, B: 0']);
1100 + expect(Scheduler).toFlushAndYield(['A: 1, B: 0']);
1101
1102 ReactNoop.render(<Foo ref={foo} b={0} />);
1101 - expect(ReactNoop).toFlushAndYield([]);
1103 + expect(Scheduler).toFlushAndYield([]);
1104 });
1105
1106 xit('can call sCU while resuming a partly mounted component', () => {
@@ -1193,7 +1195,7 @@ describe('ReactIncremental', () => {
1195 <Baz />
1196 </div>,
1197 );
1196 - expect(ReactNoop).toFlushWithoutYielding();
1198 + expect(Scheduler).toFlushWithoutYielding();
1199
1200 ops = [];
1201
@@ -1214,7 +1216,7 @@ describe('ReactIncremental', () => {
1216
1217 ops = [];
1218
1217 - expect(ReactNoop).toFlushWithoutYielding();
1219 + expect(Scheduler).toFlushWithoutYielding();
1220 expect(ops).toEqual(['Bar:A-1', 'Baz']);
1221 });
1222
@@ -1263,7 +1265,7 @@ describe('ReactIncremental', () => {
1265 ops = [];
1266
1267 ReactNoop.render(<App x={1} />);
1266 - expect(ReactNoop).toFlushWithoutYielding();
1268 + expect(Scheduler).toFlushWithoutYielding();
1269
1270 expect(ops).toEqual([
1271 'App',
@@ -1311,7 +1313,7 @@ describe('ReactIncremental', () => {
1313
1314 ops = [];
1315 ReactNoop.render(<App x={1} />);
1314 - expect(ReactNoop).toFlushWithoutYielding();
1316 + expect(Scheduler).toFlushWithoutYielding();
1317
1318 expect(ops).toEqual([
1319 'App',
@@ -1366,7 +1368,7 @@ describe('ReactIncremental', () => {
1368 }
1369
1370 ReactNoop.render(<App x={0} />);
1369 - expect(ReactNoop).toFlushWithoutYielding();
1371 + expect(Scheduler).toFlushWithoutYielding();
1372
1373 expect(ops).toEqual([
1374 'App',
@@ -1394,7 +1396,7 @@ describe('ReactIncremental', () => {
1396 ops = [];
1397
1398 ReactNoop.render(<App x={2} />);
1397 - expect(ReactNoop).toFlushWithoutYielding();
1399 + expect(Scheduler).toFlushWithoutYielding();
1400
1401 expect(ops).toEqual([
1402 'App',
@@ -1432,7 +1434,7 @@ describe('ReactIncremental', () => {
1434 }
1435
1436 ReactNoop.render(<LifeCycle />);
1435 - expect(ReactNoop).toFlushWithoutYielding();
1437 + expect(Scheduler).toFlushWithoutYielding();
1438
1439 expect(ops).toEqual(['getDerivedStateFromProps', 'render']);
1440 expect(instance.state).toEqual({foo: 'foo'});
@@ -1440,7 +1442,7 @@ describe('ReactIncremental', () => {
1442 ops = [];
1443
1444 instance.changeState();
1443 - expect(ReactNoop).toFlushWithoutYielding();
1445 + expect(Scheduler).toFlushWithoutYielding();
1446
1447 expect(ops).toEqual([
1448 'getDerivedStateFromProps',
@@ -1472,7 +1474,7 @@ describe('ReactIncremental', () => {
1474
1475 const child = React.createRef(null);
1476 ReactNoop.render(<Parent />);
1475 - expect(ReactNoop).toFlushAndYield([
1477 + expect(Scheduler).toFlushAndYield([
1478 'getDerivedStateFromProps',
1479 'Parent',
1480 'Child',
@@ -1480,7 +1482,7 @@ describe('ReactIncremental', () => {
1482
1483 // Schedule an update on the child. The parent should not re-render.
1484 child.current.setState({});
1483 - expect(ReactNoop).toFlushAndYield(['Child']);
1485 + expect(Scheduler).toFlushAndYield(['Child']);
1486 });
1487
1488 xit('does not call componentWillReceiveProps for state-only updates', () => {
@@ -1553,7 +1555,7 @@ describe('ReactIncremental', () => {
1555 }
1556
1557 ReactNoop.render(<App y={0} />);
1556 - expect(ReactNoop).toFlushWithoutYielding();
1558 + expect(Scheduler).toFlushWithoutYielding();
1559
1560 expect(ops).toEqual([
1561 'App',
@@ -1584,7 +1586,7 @@ describe('ReactIncremental', () => {
1586 // LifeCycle
1587 instances[1].tick();
1588
1587 - expect(ReactNoop).toFlushWithoutYielding();
1589 + expect(Scheduler).toFlushWithoutYielding();
1590
1591 expect(ops).toEqual([
1592 // no componentWillReceiveProps
@@ -1617,7 +1619,7 @@ describe('ReactIncremental', () => {
1619 // Next we will update LifeCycle directly but not with new props.
1620 instances[1].tick();
1621
1620 - expect(ReactNoop).toFlushWithoutYielding();
1622 + expect(Scheduler).toFlushWithoutYielding();
1623
1624 expect(ops).toEqual([
1625 // This should not trigger another componentWillReceiveProps because
@@ -1672,7 +1674,7 @@ describe('ReactIncremental', () => {
1674 }
1675
1676 ReactNoop.render(<App x={0} />);
1675 - expect(ReactNoop).toFlushWithoutYielding();
1677 + expect(Scheduler).toFlushWithoutYielding();
1678
1679 expect(ops).toEqual([
1680 'componentWillMount',
@@ -1685,7 +1687,7 @@ describe('ReactIncremental', () => {
1687
1688 // Update to same props
1689 ReactNoop.render(<App x={0} />);
1688 - expect(ReactNoop).toFlushWithoutYielding();
1690 + expect(Scheduler).toFlushWithoutYielding();
1691
1692 expect(ops).toEqual([
1693 'componentWillReceiveProps',
@@ -1715,7 +1717,7 @@ describe('ReactIncremental', () => {
1717
1718 // ...but we'll interrupt it to rerender the same props.
1719 ReactNoop.render(<App x={1} />);
1718 - expect(ReactNoop).toFlushWithoutYielding();
1720 + expect(Scheduler).toFlushWithoutYielding();
1721
1722 // We can bail out this time, but we must call componentDidUpdate.
1723 expect(ops).toEqual([
@@ -1741,7 +1743,7 @@ describe('ReactIncremental', () => {
1743 }
1744
1745 ReactNoop.render(<Foo />);
1744 - expect(ReactNoop).toFlushWithoutYielding();
1746 + expect(Scheduler).toFlushWithoutYielding();
1747 ops = [];
1748
1749 ReactNoop.flushSync(() => {
@@ -1783,7 +1785,7 @@ describe('ReactIncremental', () => {
1785 }
1786
1787 ReactNoop.render(<Foo />);
1786 - expect(ReactNoop).toFlushWithoutYielding();
1788 + expect(Scheduler).toFlushWithoutYielding();
1789 ops = [];
1790
1791 function updater({n}) {
@@ -1798,7 +1800,7 @@ describe('ReactIncremental', () => {
1800 instance.setState(updater, () => ops.push('third callback'));
1801
1802 expect(() => {
1801 - expect(ReactNoop).toFlushWithoutYielding();
1803 + expect(Scheduler).toFlushWithoutYielding();
1804 }).toThrow('callback error');
1805
1806 // The third callback isn't called because the second one throws
@@ -1897,7 +1899,7 @@ describe('ReactIncremental', () => {
1899 </Intl>,
1900 );
1901 expect(() =>
1900 - expect(ReactNoop).toFlushAndYield([
1902 + expect(Scheduler).toFlushAndYield([
1903 'Intl {}',
1904 'ShowLocale {"locale":"fr"}',
1905 'ShowBoth {"locale":"fr"}',
@@ -1916,7 +1918,7 @@ describe('ReactIncremental', () => {
1918 </div>
1919 </Intl>,
1920 );
1919 - expect(ReactNoop).toFlushAndYield([
1921 + expect(Scheduler).toFlushAndYield([
1922 'Intl {}',
1923 'ShowLocale {"locale":"de"}',
1924 'ShowBoth {"locale":"de"}',
@@ -1930,7 +1932,7 @@ describe('ReactIncremental', () => {
1932 </div>
1933 </Intl>,
1934 );
1933 - expect(ReactNoop).toFlushAndYieldThrough(['Intl {}']);
1935 + expect(Scheduler).toFlushAndYieldThrough(['Intl {}']);
1936
1937 ReactNoop.render(
1938 <Intl locale="en">
@@ -1942,7 +1944,7 @@ describe('ReactIncremental', () => {
1944 </Intl>,
1945 );
1946 expect(() =>
1945 - expect(ReactNoop).toFlushAndYield([
1947 + expect(Scheduler).toFlushAndYield([
1948 'ShowLocale {"locale":"sv"}',
1949 'ShowBoth {"locale":"sv"}',
1950 'Intl {}',
@@ -1986,7 +1988,7 @@ describe('ReactIncremental', () => {
1988 }
1989
1990 ReactNoop.render(<Recurse />);
1989 - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev(
1991 + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
1992 'Legacy context API has been detected within a strict-mode tree: \n\n' +
1993 'Please update the following components: Recurse',
1994 {withoutStack: true},
@@ -2023,7 +2025,7 @@ describe('ReactIncremental', () => {
2025 };
2026
2027 ReactNoop.render(<Recurse />);
2026 - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev(
2028 + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
2029 'Legacy context API has been detected within a strict-mode tree: \n\n' +
2030 'Please update the following components: Recurse',
2031 {withoutStack: true},
@@ -2074,14 +2076,14 @@ describe('ReactIncremental', () => {
2076 <ShowLocale />
2077 </Intl>,
2078 );
2077 - expect(ReactNoop).toFlushAndYieldThrough([
2079 + expect(Scheduler).toFlushAndYieldThrough([
2080 'Intl {}',
2081 'ShowLocale {"locale":"fr"}',
2082 'ShowLocale {"locale":"fr"}',
2083 ]);
2084
2085 expect(() =>
2084 - expect(ReactNoop).toFlushAndYield([
2086 + expect(Scheduler).toFlushAndYield([
2087 'ShowLocale {"locale":"fr"}',
2088 'Intl {}',
2089 'ShowLocale {"locale":"ru"}',
@@ -2165,7 +2167,7 @@ describe('ReactIncremental', () => {
2167 </IndirectionFn>
2168 </Intl>,
2169 );
2168 - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev(
2170 + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
2171 'Legacy context API has been detected within a strict-mode tree: \n\n' +
2172 'Please update the following components: Intl, ShowLocaleClass, ShowLocaleFn',
2173 {withoutStack: true},
@@ -2181,7 +2183,7 @@ describe('ReactIncremental', () => {
2183
2184 ops.length = 0;
2185 statefulInst.setState({x: 1});
2184 - expect(ReactNoop).toFlushWithoutYielding();
2186 + expect(Scheduler).toFlushWithoutYielding();
2187 // All work has been memoized because setState()
2188 // happened below the context and could not have affected it.
2189 expect(ops).toEqual([]);
@@ -2257,7 +2259,7 @@ describe('ReactIncremental', () => {
2259 </IndirectionFn>
2260 </Stateful>,
2261 );
2260 - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev(
2262 + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
2263 'Legacy context API has been detected within a strict-mode tree: \n\n' +
2264 'Please update the following components: Intl, ShowLocaleClass, ShowLocaleFn',
2265 {withoutStack: true},
@@ -2273,7 +2275,7 @@ describe('ReactIncremental', () => {
2275
2276 ops.length = 0;
2277 statefulInst.setState({locale: 'gr'});
2276 - expect(ReactNoop).toFlushWithoutYielding();
2278 + expect(Scheduler).toFlushWithoutYielding();
2279 expect(ops).toEqual([
2280 // Intl is below setState() so it might have been
2281 // affected by it. Therefore we re-render and recompute
@@ -2326,7 +2328,7 @@ describe('ReactIncremental', () => {
2328
2329 // Init
2330 ReactNoop.render(<Root />);
2329 - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev(
2331 + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
2332 'Legacy context API has been detected within a strict-mode tree: \n\n' +
2333 'Please update the following components: Child',
2334 {withoutStack: true},
@@ -2334,7 +2336,7 @@ describe('ReactIncremental', () => {
2336
2337 // Trigger an update in the middle of the tree
2338 instance.setState({});
2337 - expect(ReactNoop).toFlushWithoutYielding();
2339 + expect(Scheduler).toFlushWithoutYielding();
2340 });
2341
2342 it('maintains the correct context when unwinding due to an error in render', () => {
@@ -2376,7 +2378,7 @@ describe('ReactIncremental', () => {
2378
2379 // Init
2380 ReactNoop.render(<Root />);
2379 - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev(
2381 + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
2382 'Legacy context API has been detected within a strict-mode tree: \n\n' +
2383 'Please update the following components: ContextProvider',
2384 {withoutStack: true},
@@ -2387,7 +2389,7 @@ describe('ReactIncremental', () => {
2389 instance.setState({
2390 throwError: true,
2391 });
2390 - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev(
2392 + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
2393 'Error boundaries should implement getDerivedStateFromError()',
2394 {withoutStack: true},
2395 );
@@ -2425,7 +2427,7 @@ describe('ReactIncremental', () => {
2427 }
2428
2429 ReactNoop.render(<MyComponent />);
2428 - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev(
2430 + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
2431 [
2432 'componentWillReceiveProps: Please update the following components ' +
2433 'to use static getDerivedStateFromProps instead: MyComponent',
@@ -2496,7 +2498,7 @@ describe('ReactIncremental', () => {
2498 // Initial render of the entire tree.
2499 // Renders: Root, Middle, FirstChild, SecondChild
2500 ReactNoop.render(<Root>A</Root>);
2499 - expect(ReactNoop).toFlushWithoutYielding();
2501 + expect(Scheduler).toFlushWithoutYielding();
2502
2503 expect(renderCounter).toBe(1);
2504
@@ -2518,7 +2520,7 @@ describe('ReactIncremental', () => {
2520 // The in-progress child content will bailout.
2521 // Renders: Root, Middle, FirstChild, SecondChild
2522 ReactNoop.render(<Root>B</Root>);
2521 - expect(ReactNoop).toFlushWithoutYielding();
2523 + expect(Scheduler).toFlushWithoutYielding();
2524
2525 // At this point the higher priority render has completed.
2526 // Since FirstChild props didn't change, sCU returned false.
@@ -2575,14 +2577,14 @@ describe('ReactIncremental', () => {
2577 </TopContextProvider>,
2578 );
2579
2578 - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev(
2580 + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
2581 'Legacy context API has been detected within a strict-mode tree: \n\n' +
2582 'Please update the following components: Child, TopContextProvider',
2583 {withoutStack: true},
2584 );
2585 expect(rendered).toEqual(['count:0']);
2586 instance.updateCount();
2585 - expect(ReactNoop).toFlushWithoutYielding();
2587 + expect(Scheduler).toFlushWithoutYielding();
2588 expect(rendered).toEqual(['count:0', 'count:1']);
2589 });
2590
@@ -2637,14 +2639,14 @@ describe('ReactIncremental', () => {
2639 </TopContextProvider>,
2640 );
2641
2640 - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev(
2642 + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
2643 'Legacy context API has been detected within a strict-mode tree: \n\n' +
2644 'Please update the following components: Child, MiddleContextProvider, TopContextProvider',
2645 {withoutStack: true},
2646 );
2647 expect(rendered).toEqual(['count:0']);
2648 instance.updateCount();
2647 - expect(ReactNoop).toFlushWithoutYielding();
2649 + expect(Scheduler).toFlushWithoutYielding();
2650 expect(rendered).toEqual(['count:0', 'count:1']);
2651 });
2652
@@ -2708,14 +2710,14 @@ describe('ReactIncremental', () => {
2710 </TopContextProvider>,
2711 );
2712
2711 - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev(
2713 + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
2714 'Legacy context API has been detected within a strict-mode tree: \n\n' +
2715 'Please update the following components: Child, MiddleContextProvider, TopContextProvider',
2716 {withoutStack: true},
2717 );
2718 expect(rendered).toEqual(['count:0']);
2719 instance.updateCount();
2718 - expect(ReactNoop).toFlushWithoutYielding();
2720 + expect(Scheduler).toFlushWithoutYielding();
2721 expect(rendered).toEqual(['count:0']);
2722 });
2723
@@ -2789,17 +2791,17 @@ describe('ReactIncremental', () => {
2791 </TopContextProvider>,
2792 );
2793
2792 - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev(
2794 + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
2795 'Legacy context API has been detected within a strict-mode tree: \n\n' +
2796 'Please update the following components: Child, MiddleContextProvider, TopContextProvider',
2797 {withoutStack: true},
2798 );
2799 expect(rendered).toEqual(['count:0, name:brian']);
2800 topInstance.updateCount();
2799 - expect(ReactNoop).toFlushWithoutYielding();
2801 + expect(Scheduler).toFlushWithoutYielding();
2802 expect(rendered).toEqual(['count:0, name:brian']);
2803 middleInstance.updateName('not brian');
2802 - expect(ReactNoop).toFlushWithoutYielding();
2804 + expect(Scheduler).toFlushWithoutYielding();
2805 expect(rendered).toEqual([
2806 'count:0, name:brian',
2807 'count:1, name:not brian',
@@ -2818,12 +2820,12 @@ describe('ReactIncremental', () => {
2820 }
2821
2822 ReactNoop.render(<Parent step={1} />);
2821 - expect(ReactNoop).toFlushAndYieldThrough(['Parent: 1']);
2823 + expect(Scheduler).toFlushAndYieldThrough(['Parent: 1']);
2824
2825 // Interrupt at same priority
2826 ReactNoop.render(<Parent step={2} />);
2827
2826 - expect(ReactNoop).toFlushAndYield(['Child: 1', 'Parent: 2', 'Child: 2']);
2828 + expect(Scheduler).toFlushAndYield(['Child: 1', 'Parent: 2', 'Child: 2']);
2829 });
2830
2831 it('does not interrupt for update at lower priority', () => {
@@ -2838,13 +2840,13 @@ describe('ReactIncremental', () => {
2840 }
2841
2842 ReactNoop.render(<Parent step={1} />);
2841 - expect(ReactNoop).toFlushAndYieldThrough(['Parent: 1']);
2843 + expect(Scheduler).toFlushAndYieldThrough(['Parent: 1']);
2844
2845 // Interrupt at lower priority
2846 ReactNoop.expire(2000);
2847 ReactNoop.render(<Parent step={2} />);
2848
2847 - expect(ReactNoop).toFlushAndYield(['Child: 1', 'Parent: 2', 'Child: 2']);
2849 + expect(Scheduler).toFlushAndYield(['Child: 1', 'Parent: 2', 'Child: 2']);
2850 });
2851
2852 it('does interrupt for update at higher priority', () => {
@@ -2859,13 +2861,13 @@ describe('ReactIncremental', () => {
2861 }
2862
2863 ReactNoop.render(<Parent step={1} />);
2862 - expect(ReactNoop).toFlushAndYieldThrough(['Parent: 1']);
2864 + expect(Scheduler).toFlushAndYieldThrough(['Parent: 1']);
2865
2866 // Interrupt at higher priority
2867 ReactNoop.flushSync(() => ReactNoop.render(<Parent step={2} />));
2866 - expect(ReactNoop).toHaveYielded(['Parent: 2', 'Child: 2']);
2868 + expect(Scheduler).toHaveYielded(['Parent: 2', 'Child: 2']);
2869
2868 - expect(ReactNoop).toFlushAndYield([]);
2870 + expect(Scheduler).toFlushAndYield([]);
2871 });
2872
2873 // We don't currently use fibers as keys. Re-enable this test if we
@@ -2887,7 +2889,7 @@ describe('ReactIncremental', () => {
2889 }
2890 }
2891 ReactNoop.render(<Boundary />);
2890 - expect(ReactNoop).toFlushWithoutYielding();
2892 + expect(Scheduler).toFlushWithoutYielding();
2893 }
2894
2895 // First, verify that this code path normally receives Fibers as keys,
@@ -2905,6 +2907,7 @@ describe('ReactIncremental', () => {
2907 };
2908 React = require('react');
2909 ReactNoop = require('react-noop-renderer');
2910 + Scheduler = require('scheduler');
2911 try {
2912 receivedNonExtensibleObjects = false;
2913 triggerCodePathThatUsesFibersAsMapKeys();
packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.internal.js
+59 -59
@@ -88,7 +88,7 @@ describe('ReactIncrementalErrorHandling', () => {
88 );
89
90 // Start rendering asynchronously
91 - expect(ReactNoop).toFlushAndYieldThrough([
91 + expect(Scheduler).toFlushAndYieldThrough([
92 'ErrorBoundary (try)',
93 'Indirection',
94 'Indirection',
@@ -98,9 +98,9 @@ describe('ReactIncrementalErrorHandling', () => {
98 ]);
99
100 // Still rendering async...
101 - expect(ReactNoop).toFlushAndYieldThrough(['Indirection']);
101 + expect(Scheduler).toFlushAndYieldThrough(['Indirection']);
102
103 - expect(ReactNoop).toFlushAndYieldThrough([
103 + expect(Scheduler).toFlushAndYieldThrough([
104 'Indirection',
105
106 // Call getDerivedStateFromError and re-render the error boundary, this
@@ -181,7 +181,7 @@ describe('ReactIncrementalErrorHandling', () => {
181 );
182
183 // Start rendering asynchronously
184 - expect(ReactNoop).toFlushAndYieldThrough([
184 + expect(Scheduler).toFlushAndYieldThrough([
185 'ErrorBoundary (try)',
186 'Indirection',
187 'Indirection',
@@ -191,9 +191,9 @@ describe('ReactIncrementalErrorHandling', () => {
191 ]);
192
193 // Still rendering async...
194 - expect(ReactNoop).toFlushAndYieldThrough(['Indirection']);
194 + expect(Scheduler).toFlushAndYieldThrough(['Indirection']);
195
196 - expect(ReactNoop).toFlushAndYieldThrough([
196 + expect(Scheduler).toFlushAndYieldThrough([
197 'Indirection',
198 // Now that the tree is complete, and there's no remaining work, React
199 // reverts to sync mode to retry one more time before handling the error.
@@ -236,13 +236,13 @@ describe('ReactIncrementalErrorHandling', () => {
236
237 ReactNoop.render(<App isBroken={true} />, onCommit);
238 Scheduler.advanceTime(1000);
239 - expect(ReactNoop).toFlushAndYieldThrough(['error']);
239 + expect(Scheduler).toFlushAndYieldThrough(['error']);
240 interrupt();
241
242 // This update is in a separate batch
243 ReactNoop.render(<App isBroken={false} />, onCommit);
244
245 - expect(ReactNoop).toFlushAndYield([
245 + expect(Scheduler).toFlushAndYield([
246 // The first render fails. But because there's a lower priority pending
247 // update, it doesn't throw.
248 'error',
@@ -282,7 +282,7 @@ describe('ReactIncrementalErrorHandling', () => {
282 // Initial mount
283 const parent = React.createRef(null);
284 ReactNoop.render(<Parent ref={parent} childIsBroken={false} />);
285 - expect(ReactNoop).toFlushAndYield(['Child']);
285 + expect(Scheduler).toFlushAndYield(['Child']);
286 expect(ReactNoop.getChildren()).toEqual([span('Child')]);
287
288 // Schedule a low priority update to hide the child
@@ -293,7 +293,7 @@ describe('ReactIncrementalErrorHandling', () => {
293 ReactNoop.flushSync(() => {
294 ReactNoop.render(<Parent ref={parent} childIsBroken={true} />);
295 });
296 - expect(ReactNoop).toHaveYielded([
296 + expect(Scheduler).toHaveYielded([
297 // First the sync update triggers an error
298 'Error!',
299 // Because there's a pending low priority update, we restart at the
@@ -333,10 +333,10 @@ describe('ReactIncrementalErrorHandling', () => {
333 ReactNoop.render(<Parent />, () => ReactNoop.yield('commit'));
334
335 // Render the bad component asynchronously
336 - expect(ReactNoop).toFlushAndYieldThrough(['Parent', 'BadRender']);
336 + expect(Scheduler).toFlushAndYieldThrough(['Parent', 'BadRender']);
337
338 // Finish the rest of the async work
339 - expect(ReactNoop).toFlushAndYieldThrough(['Sibling']);
339 + expect(Scheduler).toFlushAndYieldThrough(['Sibling']);
340
341 // React retries once, synchronously, before throwing.
342 ops = [];
@@ -383,7 +383,7 @@ describe('ReactIncrementalErrorHandling', () => {
383 </ErrorBoundary>,
384 );
385
386 - expect(ReactNoop).toFlushAndYield([
386 + expect(Scheduler).toFlushAndYield([
387 'ErrorBoundary',
388 'BadMount',
389 'BadMount',
@@ -420,7 +420,7 @@ describe('ReactIncrementalErrorHandling', () => {
420 <BrokenRender />
421 </ErrorBoundary>,
422 );
423 - expect(ReactNoop).toFlushWithoutYielding();
423 + expect(Scheduler).toFlushWithoutYielding();
424 expect(ReactNoop.getChildren()).toEqual([span('Caught an error: Hello.')]);
425 });
426
@@ -454,10 +454,10 @@ describe('ReactIncrementalErrorHandling', () => {
454 </ErrorBoundary>,
455 );
456
457 - expect(ReactNoop).toFlushAndYieldThrough(['ErrorBoundary render success']);
457 + expect(Scheduler).toFlushAndYieldThrough(['ErrorBoundary render success']);
458 expect(ReactNoop.getChildren()).toEqual([]);
459
460 - expect(ReactNoop).toFlushAndYield([
460 + expect(Scheduler).toFlushAndYield([
461 'BrokenRender',
462 // React retries one more time
463 'ErrorBoundary render success',
@@ -582,7 +582,7 @@ describe('ReactIncrementalErrorHandling', () => {
582 );
583
584 expect(() => {
585 - expect(ReactNoop).toFlushWithoutYielding();
585 + expect(Scheduler).toFlushWithoutYielding();
586 }).toThrow('Hello');
587 expect(ops).toEqual([
588 'RethrowErrorBoundary render',
@@ -621,12 +621,12 @@ describe('ReactIncrementalErrorHandling', () => {
621 </RethrowErrorBoundary>,
622 );
623
624 - expect(ReactNoop).toFlushAndYieldThrough(['RethrowErrorBoundary render']);
624 + expect(Scheduler).toFlushAndYieldThrough(['RethrowErrorBoundary render']);
625
626 expect(() => {
627 - expect(ReactNoop).toFlushWithoutYielding();
627 + expect(Scheduler).toFlushWithoutYielding();
628 }).toThrow('Hello');
629 - expect(ReactNoop).toHaveYielded([
629 + expect(Scheduler).toHaveYielded([
630 'BrokenRender',
631
632 // React retries one more time
@@ -723,7 +723,7 @@ describe('ReactIncrementalErrorHandling', () => {
723 throw new Error('Hello');
724 });
725 }).toThrow('Hello');
726 - expect(ReactNoop).toFlushWithoutYielding();
726 + expect(Scheduler).toFlushWithoutYielding();
727 expect(ReactNoop.getChildren()).toEqual([span('a:3')]);
728 });
729
@@ -740,7 +740,7 @@ describe('ReactIncrementalErrorHandling', () => {
740 });
741 });
742 }).toThrow('Hello');
743 - expect(ReactNoop).toFlushWithoutYielding();
743 + expect(Scheduler).toFlushWithoutYielding();
744 expect(ReactNoop.getChildren()).toEqual([span('a:5')]);
745 });
746
@@ -773,7 +773,7 @@ describe('ReactIncrementalErrorHandling', () => {
773
774 ReactNoop.render(<BrokenRender />);
775 expect(() => {
776 - expect(ReactNoop).toFlushWithoutYielding();
776 + expect(Scheduler).toFlushWithoutYielding();
777 }).toThrow('Hello');
778 expect(ops).toEqual([
779 'BrokenRender',
@@ -783,7 +783,7 @@ describe('ReactIncrementalErrorHandling', () => {
783 ]);
784 ops = [];
785 ReactNoop.render(<Foo />);
786 - expect(ReactNoop).toFlushWithoutYielding();
786 + expect(Scheduler).toFlushWithoutYielding();
787 expect(ops).toEqual(['Foo']);
788 });
789
@@ -804,12 +804,12 @@ describe('ReactIncrementalErrorHandling', () => {
804 }
805
806 ReactNoop.render(<BrokenRender throw={false} />);
807 - expect(ReactNoop).toFlushWithoutYielding();
807 + expect(Scheduler).toFlushWithoutYielding();
808 ops = [];
809
810 expect(() => {
811 ReactNoop.render(<BrokenRender throw={true} />);
812 - expect(ReactNoop).toFlushWithoutYielding();
812 + expect(Scheduler).toFlushWithoutYielding();
813 }).toThrow('Hello');
814 expect(ops).toEqual([
815 'BrokenRender',
@@ -820,7 +820,7 @@ describe('ReactIncrementalErrorHandling', () => {
820
821 ops = [];
822 ReactNoop.render(<Foo />);
823 - expect(ReactNoop).toFlushWithoutYielding();
823 + expect(Scheduler).toFlushWithoutYielding();
824 expect(ops).toEqual(['Foo']);
825 });
826
@@ -842,16 +842,16 @@ describe('ReactIncrementalErrorHandling', () => {
842 }
843
844 ReactNoop.render(<BrokenComponentWillUnmount />);
845 - expect(ReactNoop).toFlushWithoutYielding();
845 + expect(Scheduler).toFlushWithoutYielding();
846
847 expect(() => {
848 ReactNoop.render(<div />);
849 - expect(ReactNoop).toFlushWithoutYielding();
849 + expect(Scheduler).toFlushWithoutYielding();
850 }).toThrow('Hello');
851
852 ops = [];
853 ReactNoop.render(<Foo />);
854 - expect(ReactNoop).toFlushWithoutYielding();
854 + expect(Scheduler).toFlushWithoutYielding();
855 expect(ops).toEqual(['Foo']);
856 });
857
@@ -885,9 +885,9 @@ describe('ReactIncrementalErrorHandling', () => {
885 }
886
887 ReactNoop.render(<Parent />);
888 - expect(ReactNoop).toFlushWithoutYielding();
888 + expect(Scheduler).toFlushWithoutYielding();
889 ReactNoop.render(null);
890 - expect(ReactNoop).toFlushAndYield([
890 + expect(Scheduler).toFlushAndYield([
891 // Parent unmounts before the error is thrown.
892 'Parent componentWillUnmount',
893 'ThrowsOnUnmount componentWillUnmount',
@@ -924,7 +924,7 @@ describe('ReactIncrementalErrorHandling', () => {
924 }
925
926 ReactNoop.render(<Parent />);
927 - expect(ReactNoop).toFlushWithoutYielding();
927 + expect(Scheduler).toFlushWithoutYielding();
928
929 ReactNoop.flushSync(() => {
930 ReactNoop.render(<Parent />);
@@ -958,7 +958,7 @@ describe('ReactIncrementalErrorHandling', () => {
958 'a',
959 );
960 ReactNoop.renderToRootWithID(<span prop="b:1" />, 'b');
961 - expect(ReactNoop).toFlushWithoutYielding();
961 + expect(Scheduler).toFlushWithoutYielding();
962 expect(ReactNoop.getChildren('a')).toEqual([
963 span('Caught an error: Hello.'),
964 ]);
@@ -972,14 +972,14 @@ describe('ReactIncrementalErrorHandling', () => {
972
973 ReactNoop.renderToRootWithID(<BrokenRender />, 'a');
974 expect(() => {
975 - expect(ReactNoop).toFlushWithoutYielding();
975 + expect(Scheduler).toFlushWithoutYielding();
976 }).toThrow('Hello');
977 expect(ReactNoop.getChildren('a')).toEqual([]);
978
979 ReactNoop.renderToRootWithID(<BrokenRender />, 'a');
980 ReactNoop.renderToRootWithID(<span prop="b:2" />, 'b');
981 expect(() => {
982 - expect(ReactNoop).toFlushWithoutYielding();
982 + expect(Scheduler).toFlushWithoutYielding();
983 }).toThrow('Hello');
984
985 expect(ReactNoop.getChildren('a')).toEqual([]);
@@ -988,7 +988,7 @@ describe('ReactIncrementalErrorHandling', () => {
988 ReactNoop.renderToRootWithID(<span prop="a:3" />, 'a');
989 ReactNoop.renderToRootWithID(<BrokenRender />, 'b');
990 expect(() => {
991 - expect(ReactNoop).toFlushWithoutYielding();
991 + expect(Scheduler).toFlushWithoutYielding();
992 }).toThrow('Hello');
993 expect(ReactNoop.getChildren('a')).toEqual([span('a:3')]);
994 expect(ReactNoop.getChildren('b')).toEqual([]);
@@ -997,7 +997,7 @@ describe('ReactIncrementalErrorHandling', () => {
997 ReactNoop.renderToRootWithID(<BrokenRender />, 'b');
998 ReactNoop.renderToRootWithID(<span prop="c:4" />, 'c');
999 expect(() => {
1000 - expect(ReactNoop).toFlushWithoutYielding();
1000 + expect(Scheduler).toFlushWithoutYielding();
1001 }).toThrow('Hello');
1002 expect(ReactNoop.getChildren('a')).toEqual([span('a:4')]);
1003 expect(ReactNoop.getChildren('b')).toEqual([]);
@@ -1009,7 +1009,7 @@ describe('ReactIncrementalErrorHandling', () => {
1009 ReactNoop.renderToRootWithID(<span prop="d:5" />, 'd');
1010 ReactNoop.renderToRootWithID(<BrokenRender />, 'e');
1011 expect(() => {
1012 - expect(ReactNoop).toFlushWithoutYielding();
1012 + expect(Scheduler).toFlushWithoutYielding();
1013 }).toThrow('Hello');
1014 expect(ReactNoop.getChildren('a')).toEqual([span('a:5')]);
1015 expect(ReactNoop.getChildren('b')).toEqual([span('b:5')]);
@@ -1024,7 +1024,7 @@ describe('ReactIncrementalErrorHandling', () => {
1024 ReactNoop.renderToRootWithID(<BrokenRender />, 'e');
1025 ReactNoop.renderToRootWithID(<span prop="f:6" />, 'f');
1026 expect(() => {
1027 - expect(ReactNoop).toFlushWithoutYielding();
1027 + expect(Scheduler).toFlushWithoutYielding();
1028 }).toThrow('Hello');
1029 expect(ReactNoop.getChildren('a')).toEqual([]);
1030 expect(ReactNoop.getChildren('b')).toEqual([span('b:6')]);
@@ -1039,7 +1039,7 @@ describe('ReactIncrementalErrorHandling', () => {
1039 ReactNoop.unmountRootWithID('d');
1040 ReactNoop.unmountRootWithID('e');
1041 ReactNoop.unmountRootWithID('f');
1042 - expect(ReactNoop).toFlushWithoutYielding();
1042 + expect(Scheduler).toFlushWithoutYielding();
1043 expect(ReactNoop.getChildren('a')).toEqual(null);
1044 expect(ReactNoop.getChildren('b')).toEqual(null);
1045 expect(ReactNoop.getChildren('c')).toEqual(null);
@@ -1100,7 +1100,7 @@ describe('ReactIncrementalErrorHandling', () => {
1100 <Connector />
1101 </Provider>,
1102 );
1103 - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev(
1103 + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
1104 'Legacy context API has been detected within a strict-mode tree: \n\n' +
1105 'Please update the following components: Connector, Provider',
1106 {withoutStack: true},
@@ -1133,7 +1133,7 @@ describe('ReactIncrementalErrorHandling', () => {
1133 <BrokenRender />
1134 </ErrorBoundary>,
1135 );
1136 - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev([
1136 + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev([
1137 'Warning: React.createElement: type is invalid -- expected a string',
1138 // React retries once on error
1139 'Warning: React.createElement: type is invalid -- expected a string',
@@ -1175,14 +1175,14 @@ describe('ReactIncrementalErrorHandling', () => {
1175 <BrokenRender fail={false} />
1176 </ErrorBoundary>,
1177 );
1178 - expect(ReactNoop).toFlushWithoutYielding();
1178 + expect(Scheduler).toFlushWithoutYielding();
1179
1180 ReactNoop.render(
1181 <ErrorBoundary>
1182 <BrokenRender fail={true} />
1183 </ErrorBoundary>,
1184 );
1185 - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev([
1185 + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev([
1186 'Warning: React.createElement: type is invalid -- expected a string',
1187 // React retries once on error
1188 'Warning: React.createElement: type is invalid -- expected a string',
@@ -1206,7 +1206,7 @@ describe('ReactIncrementalErrorHandling', () => {
1206 'Warning: React.createElement: type is invalid -- expected a string',
1207 {withoutStack: true},
1208 );
1209 - expect(ReactNoop).toFlushAndThrow(
1209 + expect(Scheduler).toFlushAndThrow(
1210 'Element type is invalid: expected a string (for built-in components) or ' +
1211 'a class/function (for composite components) but got: undefined.' +
1212 (__DEV__
@@ -1216,7 +1216,7 @@ describe('ReactIncrementalErrorHandling', () => {
1216 );
1217
1218 ReactNoop.render(<span prop="hi" />);
1219 - expect(ReactNoop).toFlushWithoutYielding();
1219 + expect(Scheduler).toFlushWithoutYielding();
1220 expect(ReactNoop.getChildren()).toEqual([span('hi')]);
1221 });
1222
@@ -1255,11 +1255,11 @@ describe('ReactIncrementalErrorHandling', () => {
1255 </Parent>
1256 </Parent>,
1257 );
1258 - expect(ReactNoop).toFlushWithoutYielding();
1258 + expect(Scheduler).toFlushWithoutYielding();
1259
1260 inst.setState({fail: true});
1261 expect(() => {
1262 - expect(ReactNoop).toFlushWithoutYielding();
1262 + expect(Scheduler).toFlushWithoutYielding();
1263 }).toThrowError('Hello.');
1264
1265 expect(ops).toEqual([
@@ -1297,7 +1297,7 @@ describe('ReactIncrementalErrorHandling', () => {
1297 }
1298
1299 ReactNoop.render(<Foo />);
1300 - expect(ReactNoop).toFlushWithoutYielding();
1300 + expect(Scheduler).toFlushWithoutYielding();
1301 expect(ops).toEqual(['barRef attach']);
1302 expect(ReactNoop.getChildren()).toEqual([div(span('Bar'))]);
1303
@@ -1305,7 +1305,7 @@ describe('ReactIncrementalErrorHandling', () => {
1305
1306 // Unmount
1307 ReactNoop.render(<Foo hide={true} />);
1308 - expect(ReactNoop).toFlushAndThrow('Detach error');
1308 + expect(Scheduler).toFlushAndThrow('Detach error');
1309 expect(ops).toEqual([
1310 'barRef detach',
1311 // Bar should unmount even though its ref threw an error while detaching
@@ -1317,14 +1317,14 @@ describe('ReactIncrementalErrorHandling', () => {
1317
1318 it('handles error thrown by host config while working on failed root', () => {
1319 ReactNoop.render(<errorInBeginPhase />);
1320 - expect(ReactNoop).toFlushAndThrow('Error in host config.');
1320 + expect(Scheduler).toFlushAndThrow('Error in host config.');
1321 });
1322
1323 it('handles error thrown by top-level callback', () => {
1324 ReactNoop.render(<div />, () => {
1325 throw new Error('Error!');
1326 });
1327 - expect(ReactNoop).toFlushAndThrow('Error!');
1327 + expect(Scheduler).toFlushAndThrow('Error!');
1328 });
1329
1330 it('error boundaries capture non-errors', () => {
@@ -1371,7 +1371,7 @@ describe('ReactIncrementalErrorHandling', () => {
1371 </Indirection>
1372 </ErrorBoundary>,
1373 );
1374 - expect(ReactNoop).toFlushWithoutYielding();
1374 + expect(Scheduler).toFlushWithoutYielding();
1375
1376 expect(ops).toEqual([
1377 'ErrorBoundary (try)',
@@ -1442,7 +1442,7 @@ describe('ReactIncrementalErrorHandling', () => {
1442 </ErrorBoundary>,
1443 );
1444
1445 - expect(ReactNoop).toFlushAndYield([
1445 + expect(Scheduler).toFlushAndYield([
1446 'ErrorBoundary (try)',
1447 'throw',
1448 // Continue rendering siblings after BadRender throws
@@ -1492,7 +1492,7 @@ describe('ReactIncrementalErrorHandling', () => {
1492 }
1493
1494 ReactNoop.render(<Parent step={1} />);
1495 - expect(ReactNoop).toFlushAndYieldThrough([
1495 + expect(Scheduler).toFlushAndYieldThrough([
1496 'render',
1497 'throw',
1498 'render',
@@ -1534,7 +1534,7 @@ describe('ReactIncrementalErrorHandling', () => {
1534 <BrokenRender />
1535 </ErrorBoundary>,
1536 );
1537 - expect(ReactNoop).toFlushAndYield(['render error message']);
1537 + expect(Scheduler).toFlushAndYield(['render error message']);
1538 expect(ReactNoop.getChildren()).toEqual([
1539 span(
1540 'Caught an error:\n' +
@@ -1570,7 +1570,7 @@ describe('ReactIncrementalErrorHandling', () => {
1570 <BrokenRender />
1571 </ErrorBoundary>,
1572 );
1573 - expect(ReactNoop).toFlushWithoutYielding();
1573 + expect(Scheduler).toFlushWithoutYielding();
1574 expect(ReactNoop.getChildren()).toEqual([span('Caught an error: Hello')]);
1575 });
1576
@@ -1594,7 +1594,7 @@ describe('ReactIncrementalErrorHandling', () => {
1594
1595 ReactNoop.render(<Provider />);
1596 expect(() => {
1597 - expect(ReactNoop).toFlushAndThrow('Oops!');
1597 + expect(Scheduler).toFlushAndThrow('Oops!');
1598 }).toWarnDev(
1599 'Legacy context API has been detected within a strict-mode tree: \n\n' +
1600 'Please update the following components: Provider',
packages/react-reconciler/src/__tests__/ReactIncrementalErrorLogging-test.js
+6 -4
@@ -12,12 +12,14 @@
12
13 let React;
14 let ReactNoop;
15 +let Scheduler;
16
17 describe('ReactIncrementalErrorLogging', () => {
18 beforeEach(() => {
19 jest.resetModules();
20 React = require('react');
21 ReactNoop = require('react-noop-renderer');
22 + Scheduler = require('scheduler');
23 });
24
25 // Note: in this test file we won't be using toWarnDev() matchers
@@ -50,7 +52,7 @@ describe('ReactIncrementalErrorLogging', () => {
52 </span>
53 </div>,
54 );
53 - expect(ReactNoop).toFlushAndThrow('constructor error');
55 + expect(Scheduler).toFlushAndThrow('constructor error');
56 expect(console.error).toHaveBeenCalledTimes(1);
57 expect(console.error).toHaveBeenCalledWith(
58 __DEV__
@@ -86,7 +88,7 @@ describe('ReactIncrementalErrorLogging', () => {
88 </span>
89 </div>,
90 );
89 - expect(ReactNoop).toFlushAndThrow('componentDidMount error');
91 + expect(Scheduler).toFlushAndThrow('componentDidMount error');
92 expect(console.error).toHaveBeenCalledTimes(1);
93 expect(console.error).toHaveBeenCalledWith(
94 __DEV__
@@ -125,7 +127,7 @@ describe('ReactIncrementalErrorLogging', () => {
127 </span>
128 </div>,
129 );
128 - expect(ReactNoop).toFlushAndThrow('render error');
130 + expect(Scheduler).toFlushAndThrow('render error');
131 expect(logCapturedErrorCalls.length).toBe(1);
132 expect(logCapturedErrorCalls[0]).toEqual(
133 __DEV__
@@ -181,7 +183,7 @@ describe('ReactIncrementalErrorLogging', () => {
183 <Foo />
184 </ErrorBoundary>,
185 );
184 - expect(ReactNoop).toFlushAndYield(
186 + expect(Scheduler).toFlushAndYield(
187 [
188 'render: 0',
189 __DEV__ && 'render: 0', // replay
packages/react-reconciler/src/__tests__/ReactIncrementalErrorReplay-test.js
+4 -2
@@ -12,17 +12,19 @@
12
13 let React;
14 let ReactNoop;
15 +let Scheduler;
16
17 describe('ReactIncrementalErrorReplay', () => {
18 beforeEach(() => {
19 jest.resetModules();
20 React = require('react');
21 ReactNoop = require('react-noop-renderer');
22 + Scheduler = require('scheduler');
23 });
24
25 it('should fail gracefully on error in the host environment', () => {
26 ReactNoop.render(<errorInBeginPhase />);
25 - expect(ReactNoop).toFlushAndThrow('Error in host config.');
27 + expect(Scheduler).toFlushAndThrow('Error in host config.');
28 });
29
30 it("should ignore error if it doesn't throw on retry", () => {
@@ -43,6 +45,6 @@ describe('ReactIncrementalErrorReplay', () => {
45 }
46 }
47 ReactNoop.render(<App />);
46 - expect(ReactNoop).toFlushWithoutYielding();
48 + expect(Scheduler).toFlushWithoutYielding();
49 });
50 });
packages/react-reconciler/src/__tests__/ReactIncrementalPerf-test.internal.js
+33 -31
@@ -13,6 +13,7 @@
13 describe('ReactDebugFiberPerf', () => {
14 let React;
15 let ReactNoop;
16 + let Scheduler;
17 let PropTypes;
18
19 let root;
@@ -122,6 +123,7 @@ describe('ReactDebugFiberPerf', () => {
123 // Import after the polyfill is set up:
124 React = require('react');
125 ReactNoop = require('react-noop-renderer');
126 + Scheduler = require('scheduler');
127 PropTypes = require('prop-types');
128 });
129
@@ -144,7 +146,7 @@ describe('ReactDebugFiberPerf', () => {
146 </Parent>,
147 );
148 addComment('Mount');
147 - expect(ReactNoop).toFlushWithoutYielding();
149 + expect(Scheduler).toFlushWithoutYielding();
150
151 ReactNoop.render(
152 <Parent>
@@ -152,11 +154,11 @@ describe('ReactDebugFiberPerf', () => {
154 </Parent>,
155 );
156 addComment('Update');
155 - expect(ReactNoop).toFlushWithoutYielding();
157 + expect(Scheduler).toFlushWithoutYielding();
158
159 ReactNoop.render(null);
160 addComment('Unmount');
159 - expect(ReactNoop).toFlushWithoutYielding();
161 + expect(Scheduler).toFlushWithoutYielding();
162
163 expect(getFlameChart()).toMatchSnapshot();
164 });
@@ -182,7 +184,7 @@ describe('ReactDebugFiberPerf', () => {
184 </Parent>,
185 );
186 addComment('Mount');
185 - expect(ReactNoop).toFlushWithoutYielding();
187 + expect(Scheduler).toFlushWithoutYielding();
188
189 expect(getFlameChart()).toMatchSnapshot();
190 });
@@ -200,7 +202,7 @@ describe('ReactDebugFiberPerf', () => {
202 </React.unstable_Profiler>,
203 );
204 addComment('Mount');
203 - expect(ReactNoop).toFlushWithoutYielding();
205 + expect(Scheduler).toFlushWithoutYielding();
206
207 expect(getFlameChart()).toMatchSnapshot();
208 });
@@ -216,7 +218,7 @@ describe('ReactDebugFiberPerf', () => {
218 </Provider>,
219 );
220 addComment('Mount');
219 - expect(ReactNoop).toFlushWithoutYielding();
221 + expect(Scheduler).toFlushWithoutYielding();
222
223 expect(getFlameChart()).toMatchSnapshot();
224 });
@@ -248,13 +250,13 @@ describe('ReactDebugFiberPerf', () => {
250 </Parent>
251 </Parent>,
252 );
251 - expect(ReactNoop).toFlushWithoutYielding();
253 + expect(Scheduler).toFlushWithoutYielding();
254 resetFlamechart();
255
256 a.setState({});
257 b.setState({});
258 addComment('Should include just A and B, no Parents');
257 - expect(ReactNoop).toFlushWithoutYielding();
259 + expect(Scheduler).toFlushWithoutYielding();
260 expect(getFlameChart()).toMatchSnapshot();
261 });
262
@@ -274,7 +276,7 @@ describe('ReactDebugFiberPerf', () => {
276 </Parent>,
277 );
278 addComment('Should print a warning');
277 - expect(ReactNoop).toFlushWithoutYielding();
279 + expect(Scheduler).toFlushWithoutYielding();
280 expect(getFlameChart()).toMatchSnapshot();
281 });
282
@@ -291,7 +293,7 @@ describe('ReactDebugFiberPerf', () => {
293
294 ReactNoop.renderToRootWithID(<Cascading />, 'a');
295 addComment('Rendering the first root');
294 - expect(ReactNoop).toFlushWithoutYielding();
296 + expect(Scheduler).toFlushWithoutYielding();
297 expect(getFlameChart()).toMatchSnapshot();
298 });
299
@@ -314,7 +316,7 @@ describe('ReactDebugFiberPerf', () => {
316 </Parent>,
317 );
318 addComment('Should not print a warning');
317 - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev(
319 + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
320 [
321 'componentWillMount: Please update the following components ' +
322 'to use componentDidMount instead: NotCascading' +
@@ -329,7 +331,7 @@ describe('ReactDebugFiberPerf', () => {
331 </Parent>,
332 );
333 addComment('Should not print a warning');
332 - expect(ReactNoop).toFlushWithoutYielding();
334 + expect(Scheduler).toFlushWithoutYielding();
335 expect(getFlameChart()).toMatchSnapshot();
336 });
337
@@ -356,7 +358,7 @@ describe('ReactDebugFiberPerf', () => {
358 }
359 ReactNoop.render(<AllLifecycles />);
360 addComment('Mount');
359 - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev(
361 + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
362 [
363 'componentWillMount: Please update the following components ' +
364 'to use componentDidMount instead: AllLifecycles' +
@@ -371,10 +373,10 @@ describe('ReactDebugFiberPerf', () => {
373 );
374 ReactNoop.render(<AllLifecycles />);
375 addComment('Update');
374 - expect(ReactNoop).toFlushWithoutYielding();
376 + expect(Scheduler).toFlushWithoutYielding();
377 ReactNoop.render(null);
378 addComment('Unmount');
377 - expect(ReactNoop).toFlushWithoutYielding();
379 + expect(Scheduler).toFlushWithoutYielding();
380 expect(getFlameChart()).toMatchSnapshot();
381 });
382
@@ -390,7 +392,7 @@ describe('ReactDebugFiberPerf', () => {
392 );
393 });
394 addComment('Flush the child');
393 - expect(ReactNoop).toFlushWithoutYielding();
395 + expect(Scheduler).toFlushWithoutYielding();
396 expect(getFlameChart()).toMatchSnapshot();
397 });
398
@@ -430,9 +432,9 @@ describe('ReactDebugFiberPerf', () => {
432 </Parent>,
433 );
434 addComment('Start rendering through B');
433 - expect(ReactNoop).toFlushAndYieldThrough(['A', 'B']);
435 + expect(Scheduler).toFlushAndYieldThrough(['A', 'B']);
436 addComment('Complete the rest');
435 - expect(ReactNoop).toFlushAndYield(['C']);
437 + expect(Scheduler).toFlushAndYield(['C']);
438 expect(getFlameChart()).toMatchSnapshot();
439 });
440
@@ -448,7 +450,7 @@ describe('ReactDebugFiberPerf', () => {
450 );
451 try {
452 addComment('Will fatal');
451 - expect(ReactNoop).toFlushWithoutYielding();
453 + expect(Scheduler).toFlushWithoutYielding();
454 } catch (err) {
455 expect(err.message).toBe('Game over');
456 }
@@ -458,7 +460,7 @@ describe('ReactDebugFiberPerf', () => {
460 </Parent>,
461 );
462 addComment('Will reconcile from a clean state');
461 - expect(ReactNoop).toFlushWithoutYielding();
463 + expect(Scheduler).toFlushWithoutYielding();
464 expect(getFlameChart()).toMatchSnapshot();
465 });
466
@@ -494,7 +496,7 @@ describe('ReactDebugFiberPerf', () => {
496 </Parent>,
497 );
498 addComment('Stop on Baddie and restart from Boundary');
497 - expect(ReactNoop).toFlushWithoutYielding();
499 + expect(Scheduler).toFlushWithoutYielding();
500 expect(getFlameChart()).toMatchSnapshot();
501 });
502
@@ -525,7 +527,7 @@ describe('ReactDebugFiberPerf', () => {
527 <B />
528 </Parent>,
529 );
528 - expect(ReactNoop).toFlushWithoutYielding();
530 + expect(Scheduler).toFlushWithoutYielding();
531 resetFlamechart();
532
533 ReactNoop.render(
@@ -537,7 +539,7 @@ describe('ReactDebugFiberPerf', () => {
539 </Parent>,
540 );
541 addComment('The commit phase should mention A and B just once');
540 - expect(ReactNoop).toFlushWithoutYielding();
542 + expect(Scheduler).toFlushWithoutYielding();
543 ReactNoop.render(
544 <Parent>
545 <A />
@@ -548,7 +550,7 @@ describe('ReactDebugFiberPerf', () => {
550 );
551 addComment("Because of deduplication, we don't know B was cascading,");
552 addComment('but we should still see the warning for the commit phase.');
551 - expect(ReactNoop).toFlushWithoutYielding();
553 + expect(Scheduler).toFlushWithoutYielding();
554 expect(getFlameChart()).toMatchSnapshot();
555 });
556
@@ -561,7 +563,7 @@ describe('ReactDebugFiberPerf', () => {
563 {ReactNoop.createPortal(<Child />, portalContainer, null)}
564 </Parent>,
565 );
564 - expect(ReactNoop).toFlushWithoutYielding();
566 + expect(Scheduler).toFlushWithoutYielding();
567 expect(getFlameChart()).toMatchSnapshot();
568 });
569
@@ -574,7 +576,7 @@ describe('ReactDebugFiberPerf', () => {
576 <MemoFoo />
577 </Parent>,
578 );
577 - expect(ReactNoop).toFlushWithoutYielding();
579 + expect(Scheduler).toFlushWithoutYielding();
580 expect(getFlameChart()).toMatchSnapshot();
581 });
582
@@ -602,7 +604,7 @@ describe('ReactDebugFiberPerf', () => {
604 </React.Suspense>
605 </Parent>,
606 );
605 - expect(ReactNoop).toFlushWithoutYielding();
607 + expect(Scheduler).toFlushWithoutYielding();
608 expect(getFlameChart()).toMatchSnapshot();
609
610 resolve(
@@ -620,7 +622,7 @@ describe('ReactDebugFiberPerf', () => {
622 </React.Suspense>
623 </Parent>,
624 );
623 - expect(ReactNoop).toFlushWithoutYielding();
625 + expect(Scheduler).toFlushWithoutYielding();
626 expect(getFlameChart()).toMatchSnapshot();
627 });
628
@@ -651,8 +653,8 @@ describe('ReactDebugFiberPerf', () => {
653 ReactNoop.flushSync(() => {
654 ReactNoop.render(<Foo />);
655 });
654 - expect(ReactNoop).toHaveYielded(['Foo']);
655 - expect(ReactNoop).toFlushWithoutYielding();
656 + expect(Scheduler).toHaveYielded(['Foo']);
657 + expect(Scheduler).toFlushWithoutYielding();
658 expect(getFlameChart()).toMatchSnapshot();
659 });
660
@@ -663,7 +665,7 @@ describe('ReactDebugFiberPerf', () => {
665
666 ReactNoop.render(<Foo />);
667 ReactNoop.expire(6000);
666 - expect(ReactNoop).toFlushWithoutYielding();
668 + expect(Scheduler).toFlushWithoutYielding();
669 expect(getFlameChart()).toMatchSnapshot();
670 });
671 });
packages/react-reconciler/src/__tests__/ReactIncrementalReflection-test.internal.js
+16 -14
@@ -13,6 +13,7 @@
13 let React;
14 let ReactFeatureFlags;
15 let ReactNoop;
16 +let Scheduler;
17
18 describe('ReactIncrementalReflection', () => {
19 beforeEach(() => {
@@ -21,6 +22,7 @@ describe('ReactIncrementalReflection', () => {
22 ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false;
23 React = require('react');
24 ReactNoop = require('react-noop-renderer');
25 + Scheduler = require('scheduler');
26 });
27
28 function div(...children) {
@@ -62,13 +64,13 @@ describe('ReactIncrementalReflection', () => {
64 ReactNoop.render(<Foo />);
65
66 // Render part way through but don't yet commit the updates.
65 - expect(ReactNoop).toFlushAndYieldThrough(['componentWillMount: false']);
67 + expect(Scheduler).toFlushAndYieldThrough(['componentWillMount: false']);
68
69 expect(instances[0]._isMounted()).toBe(false);
70
71 // Render the rest and commit the updates.
72 expect(() =>
71 - expect(ReactNoop).toFlushAndYield(['componentDidMount: true']),
73 + expect(Scheduler).toFlushAndYield(['componentDidMount: true']),
74 ).toWarnDev(
75 'componentWillMount: Please update the following components ' +
76 'to use componentDidMount instead: Component',
@@ -107,7 +109,7 @@ describe('ReactIncrementalReflection', () => {
109 }
110
111 ReactNoop.render(<Foo mount={true} />);
110 - expect(() => expect(ReactNoop).toFlushAndYield(['Component'])).toWarnDev(
112 + expect(() => expect(Scheduler).toFlushAndYield(['Component'])).toWarnDev(
113 'componentWillMount: Please update the following components ' +
114 'to use componentDidMount instead: Component',
115 {withoutStack: true},
@@ -118,12 +120,12 @@ describe('ReactIncrementalReflection', () => {
120 ReactNoop.render(<Foo mount={false} />);
121 // Render part way through but don't yet commit the updates so it is not
122 // fully unmounted yet.
121 - expect(ReactNoop).toFlushAndYieldThrough(['Other']);
123 + expect(Scheduler).toFlushAndYieldThrough(['Other']);
124
125 expect(instances[0]._isMounted()).toBe(true);
126
127 // Finish flushing the unmount.
126 - expect(ReactNoop).toFlushAndYield(['componentWillUnmount: true']);
128 + expect(Scheduler).toFlushAndYield(['componentWillUnmount: true']);
129
130 expect(instances[0]._isMounted()).toBe(false);
131 });
@@ -185,7 +187,7 @@ describe('ReactIncrementalReflection', () => {
187
188 ReactNoop.render(<Foo step={0} />);
189 // Flush past Component but don't complete rendering everything yet.
188 - expect(ReactNoop).toFlushAndYieldThrough([
190 + expect(Scheduler).toFlushAndYieldThrough([
191 ['componentWillMount', null],
192 'render',
193 'render sibling',
@@ -197,7 +199,7 @@ describe('ReactIncrementalReflection', () => {
199 expect(findInstance(classInstance)).toBe(null);
200
201 expect(() =>
200 - expect(ReactNoop).toFlushAndYield([['componentDidMount', span()]]),
202 + expect(Scheduler).toFlushAndYield([['componentDidMount', span()]]),
203 ).toWarnDev(
204 'componentWillMount: Please update the following components ' +
205 'to use componentDidMount instead: Component' +
@@ -214,7 +216,7 @@ describe('ReactIncrementalReflection', () => {
216 // Flush next step which will cause an update but not yet render a new host
217 // node.
218 ReactNoop.render(<Foo step={1} />);
217 - expect(ReactNoop).toFlushAndYield([
219 + expect(Scheduler).toFlushAndYield([
220 ['componentWillUpdate', hostSpan],
221 'render',
222 'render sibling',
@@ -226,7 +228,7 @@ describe('ReactIncrementalReflection', () => {
228 // The next step will render a new host node but won't get committed yet.
229 // We expect this to mutate the original Fiber.
230 ReactNoop.render(<Foo step={2} />);
229 - expect(ReactNoop).toFlushAndYieldThrough([
231 + expect(Scheduler).toFlushAndYieldThrough([
232 ['componentWillUpdate', hostSpan],
233 'render',
234 'render sibling',
@@ -236,7 +238,7 @@ describe('ReactIncrementalReflection', () => {
238 expect(ReactNoop.findInstance(classInstance)).toBe(hostSpan);
239
240 // When we finally flush the tree it will get committed.
239 - expect(ReactNoop).toFlushAndYield([['componentDidUpdate', div()]]);
241 + expect(Scheduler).toFlushAndYield([['componentDidUpdate', div()]]);
242
243 const hostDiv = classInstance.div;
244 expect(hostDiv).toBeDefined();
@@ -247,7 +249,7 @@ describe('ReactIncrementalReflection', () => {
249
250 // Render to null but don't commit it yet.
251 ReactNoop.render(<Foo step={3} />);
250 - expect(ReactNoop).toFlushAndYieldThrough([
252 + expect(Scheduler).toFlushAndYieldThrough([
253 ['componentWillUpdate', hostDiv],
254 'render',
255 'render sibling',
@@ -256,14 +258,14 @@ describe('ReactIncrementalReflection', () => {
258 // This should still be the host div since the deletion is not committed.
259 expect(ReactNoop.findInstance(classInstance)).toBe(hostDiv);
260
259 - expect(ReactNoop).toFlushAndYield([['componentDidUpdate', null]]);
261 + expect(Scheduler).toFlushAndYield([['componentDidUpdate', null]]);
262
263 // This should still be the host div since the deletion is not committed.
264 expect(ReactNoop.findInstance(classInstance)).toBe(null);
265
266 // Render a div again
267 ReactNoop.render(<Foo step={4} />);
266 - expect(ReactNoop).toFlushAndYield([
268 + expect(Scheduler).toFlushAndYield([
269 ['componentWillUpdate', null],
270 'render',
271 'render sibling',
@@ -272,6 +274,6 @@ describe('ReactIncrementalReflection', () => {
274
275 // Unmount the component.
276 ReactNoop.render([]);
275 - expect(ReactNoop).toFlushAndYield([['componentWillUnmount', hostDiv]]);
277 + expect(Scheduler).toFlushAndYield([['componentWillUnmount', hostDiv]]);
278 });
279 });
packages/react-reconciler/src/__tests__/ReactIncrementalScheduling-test.internal.js
+20 -18
@@ -13,6 +13,7 @@
13 let React;
14 let ReactFeatureFlags;
15 let ReactNoop;
16 +let Scheduler;
17
18 describe('ReactIncrementalScheduling', () => {
19 beforeEach(() => {
@@ -21,6 +22,7 @@ describe('ReactIncrementalScheduling', () => {
22 ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false;
23 React = require('react');
24 ReactNoop = require('react-noop-renderer');
25 + Scheduler = require('scheduler');
26 });
27
28 function span(prop) {
@@ -31,7 +33,7 @@ describe('ReactIncrementalScheduling', () => {
33 ReactNoop.render(<span prop="1" />);
34 expect(ReactNoop.getChildren()).toEqual([]);
35
34 - expect(ReactNoop).toFlushWithoutYielding();
36 + expect(Scheduler).toFlushWithoutYielding();
37 expect(ReactNoop).toMatchRenderedOutput(<span prop="1" />);
38 });
39
@@ -40,7 +42,7 @@ describe('ReactIncrementalScheduling', () => {
42 ReactNoop.renderToRootWithID(<span prop="b:1" />, 'b');
43 ReactNoop.renderToRootWithID(<span prop="c:1" />, 'c');
44
43 - expect(ReactNoop).toFlushWithoutYielding();
45 + expect(Scheduler).toFlushWithoutYielding();
46
47 expect(ReactNoop.getChildren('a')).toEqual([span('a:1')]);
48 expect(ReactNoop.getChildren('b')).toEqual([span('b:1')]);
@@ -50,7 +52,7 @@ describe('ReactIncrementalScheduling', () => {
52 it('schedules top-level updates in order of priority', () => {
53 // Initial render.
54 ReactNoop.render(<span prop={1} />);
53 - expect(ReactNoop).toFlushWithoutYielding();
55 + expect(Scheduler).toFlushWithoutYielding();
56 expect(ReactNoop).toMatchRenderedOutput(<span prop={1} />);
57
58 ReactNoop.batchedUpdates(() => {
@@ -66,14 +68,14 @@ describe('ReactIncrementalScheduling', () => {
68
69 // The terminal value should be the last update that was scheduled,
70 // regardless of priority. In this case, that's the last sync update.
69 - expect(ReactNoop).toFlushWithoutYielding();
71 + expect(Scheduler).toFlushWithoutYielding();
72 expect(ReactNoop).toMatchRenderedOutput(<span prop={4} />);
73 });
74
75 it('schedules top-level updates with same priority in order of insertion', () => {
76 // Initial render.
77 ReactNoop.render(<span prop={1} />);
76 - expect(ReactNoop).toFlushWithoutYielding();
78 + expect(Scheduler).toFlushWithoutYielding();
79 expect(ReactNoop).toMatchRenderedOutput(<span prop={1} />);
80
81 ReactNoop.render(<span prop={2} />);
@@ -81,7 +83,7 @@ describe('ReactIncrementalScheduling', () => {
83 ReactNoop.render(<span prop={4} />);
84 ReactNoop.render(<span prop={5} />);
85
84 - expect(ReactNoop).toFlushWithoutYielding();
86 + expect(Scheduler).toFlushWithoutYielding();
87 expect(ReactNoop).toMatchRenderedOutput(<span prop={5} />);
88 });
89
@@ -102,7 +104,7 @@ describe('ReactIncrementalScheduling', () => {
104 ReactNoop.renderToRootWithID(<Text text="b:1" />, 'b');
105 ReactNoop.renderToRootWithID(<Text text="c:1" />, 'c');
106 });
105 - expect(ReactNoop).toFlushAndYield(['a:1', 'b:1', 'c:1']);
107 + expect(Scheduler).toFlushAndYield(['a:1', 'b:1', 'c:1']);
108
109 expect(ReactNoop.getChildrenAsJSX('a')).toEqual('a:1');
110 expect(ReactNoop.getChildrenAsJSX('b')).toEqual('b:1');
@@ -114,7 +116,7 @@ describe('ReactIncrementalScheduling', () => {
116 ReactNoop.renderToRootWithID(<Text text="b:2" />, 'b');
117 });
118 // Ensure it starts in the order it was scheduled
117 - expect(ReactNoop).toFlushAndYieldThrough(['c:2']);
119 + expect(Scheduler).toFlushAndYieldThrough(['c:2']);
120
121 expect(ReactNoop.getChildrenAsJSX('a')).toEqual('a:1');
122 expect(ReactNoop.getChildrenAsJSX('b')).toEqual('b:1');
@@ -124,12 +126,12 @@ describe('ReactIncrementalScheduling', () => {
126 ReactNoop.renderToRootWithID(<Text text="a:2" />, 'a');
127 });
128 // Keep performing work in the order it was scheduled
127 - expect(ReactNoop).toFlushAndYieldThrough(['b:2']);
129 + expect(Scheduler).toFlushAndYieldThrough(['b:2']);
130 expect(ReactNoop.getChildrenAsJSX('a')).toEqual('a:1');
131 expect(ReactNoop.getChildrenAsJSX('b')).toEqual('b:2');
132 expect(ReactNoop.getChildrenAsJSX('c')).toEqual('c:2');
133
132 - expect(ReactNoop).toFlushAndYieldThrough(['a:2']);
134 + expect(Scheduler).toFlushAndYieldThrough(['a:2']);
135 expect(ReactNoop.getChildrenAsJSX('a')).toEqual('a:2');
136 expect(ReactNoop.getChildrenAsJSX('b')).toEqual('b:2');
137 expect(ReactNoop.getChildrenAsJSX('c')).toEqual('c:2');
@@ -175,7 +177,7 @@ describe('ReactIncrementalScheduling', () => {
177
178 ReactNoop.render(<Foo />);
179 // Render without committing
178 - expect(ReactNoop).toFlushAndYieldThrough(['render: 0']);
180 + expect(Scheduler).toFlushAndYieldThrough(['render: 0']);
181
182 // Do one more unit of work to commit
183 expect(ReactNoop.flushNextYield()).toEqual([
@@ -188,7 +190,7 @@ describe('ReactIncrementalScheduling', () => {
190 ]);
191
192 instance.setState({tick: 2});
191 - expect(ReactNoop).toFlushAndYieldThrough(['render: 2']);
193 + expect(Scheduler).toFlushAndYieldThrough(['render: 2']);
194 expect(ReactNoop.flushNextYield()).toEqual([
195 'componentDidUpdate: 2',
196 'componentDidUpdate (before setState): 2',
@@ -243,7 +245,7 @@ describe('ReactIncrementalScheduling', () => {
245 ReactNoop.render(<Foo />);
246 });
247 // The cDM update should not have flushed yet because it has async priority.
246 - expect(ReactNoop).toHaveYielded([
248 + expect(Scheduler).toHaveYielded([
249 'render: 0',
250 'componentDidMount (before setState): 0',
251 'componentDidMount (after setState): 0',
@@ -251,13 +253,13 @@ describe('ReactIncrementalScheduling', () => {
253 expect(ReactNoop).toMatchRenderedOutput(<span prop={0} />);
254
255 // Now flush the cDM update.
254 - expect(ReactNoop).toFlushAndYield(['render: 1', 'componentDidUpdate: 1']);
256 + expect(Scheduler).toFlushAndYield(['render: 1', 'componentDidUpdate: 1']);
257 expect(ReactNoop).toMatchRenderedOutput(<span prop={1} />);
258
259 // Increment the tick to 2. This will trigger an update inside cDU. Flush
260 // the first update without flushing the second one.
261 instance.setState({tick: 2});
260 - expect(ReactNoop).toFlushAndYieldThrough([
262 + expect(Scheduler).toFlushAndYieldThrough([
263 'render: 2',
264 'componentDidUpdate: 2',
265 'componentDidUpdate (before setState): 2',
@@ -266,7 +268,7 @@ describe('ReactIncrementalScheduling', () => {
268 expect(ReactNoop).toMatchRenderedOutput(<span prop={2} />);
269
270 // Now flush the cDU update.
269 - expect(ReactNoop).toFlushAndYield(['render: 3', 'componentDidUpdate: 3']);
271 + expect(Scheduler).toFlushAndYield(['render: 3', 'componentDidUpdate: 3']);
272 expect(ReactNoop).toMatchRenderedOutput(<span prop={3} />);
273 });
274
@@ -290,7 +292,7 @@ describe('ReactIncrementalScheduling', () => {
292 ReactNoop.render(<Foo />);
293 // This should be just enough to complete all the work, but not enough to
294 // commit it.
293 - expect(ReactNoop).toFlushAndYieldThrough(['Foo']);
295 + expect(Scheduler).toFlushAndYieldThrough(['Foo']);
296 expect(ReactNoop).toMatchRenderedOutput(null);
297
298 // Do one more unit of work.
@@ -345,7 +347,7 @@ describe('ReactIncrementalScheduling', () => {
347 }
348 }
349 ReactNoop.render(<Foo />);
348 - expect(ReactNoop).toFlushWithoutYielding();
350 + expect(Scheduler).toFlushWithoutYielding();
351 expect(ReactNoop).toMatchRenderedOutput(<span prop={0} />);
352
353 ReactNoop.flushSync(() => {
packages/react-reconciler/src/__tests__/ReactIncrementalSideEffects-test.internal.js
+63 -61
@@ -13,6 +13,7 @@
13 let React;
14 let ReactFeatureFlags;
15 let ReactNoop;
16 +let Scheduler;
17
18 describe('ReactIncrementalSideEffects', () => {
19 beforeEach(() => {
@@ -21,6 +22,7 @@ describe('ReactIncrementalSideEffects', () => {
22 ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false;
23 React = require('react');
24 ReactNoop = require('react-noop-renderer');
25 + Scheduler = require('scheduler');
26 });
27
28 function div(...children) {
@@ -53,11 +55,11 @@ describe('ReactIncrementalSideEffects', () => {
55 }
56
57 ReactNoop.render(<Foo text="Hello" />);
56 - expect(ReactNoop).toFlushWithoutYielding();
58 + expect(Scheduler).toFlushWithoutYielding();
59 expect(ReactNoop.getChildren()).toEqual([div(span())]);
60
61 ReactNoop.render(<Foo text="World" />);
60 - expect(ReactNoop).toFlushWithoutYielding();
62 + expect(Scheduler).toFlushWithoutYielding();
63 expect(ReactNoop.getChildren()).toEqual([div(span(), span())]);
64 });
65
@@ -81,17 +83,17 @@ describe('ReactIncrementalSideEffects', () => {
83 }
84
85 ReactNoop.render(<Foo text="Hello" />);
84 - expect(ReactNoop).toFlushWithoutYielding();
86 + expect(Scheduler).toFlushWithoutYielding();
87 expect(ReactNoop.getChildren()).toEqual([div(span(), span('test'))]);
88
89 ReactNoop.render(<Foo text="World" />);
88 - expect(ReactNoop).toFlushWithoutYielding();
90 + expect(Scheduler).toFlushWithoutYielding();
91 expect(ReactNoop.getChildren()).toEqual([
92 div(span(), span(), div(), span('test')),
93 ]);
94
95 ReactNoop.render(<Foo text="Hi" />);
94 - expect(ReactNoop).toFlushWithoutYielding();
96 + expect(Scheduler).toFlushWithoutYielding();
97 expect(ReactNoop.getChildren()).toEqual([
98 div(span(), div(), span(), span('test')),
99 ]);
@@ -114,11 +116,11 @@ describe('ReactIncrementalSideEffects', () => {
116 }
117
118 ReactNoop.render(<Foo text="Hello" />);
117 - expect(ReactNoop).toFlushWithoutYielding();
119 + expect(Scheduler).toFlushWithoutYielding();
120 expect(ReactNoop.getChildren()).toEqual([div('Hello')]);
121
122 ReactNoop.render(<Foo text="World" />);
121 - expect(ReactNoop).toFlushWithoutYielding();
123 + expect(Scheduler).toFlushWithoutYielding();
124 expect(ReactNoop.getChildren()).toEqual([div('World', 'World', '!')]);
125 });
126
@@ -138,13 +140,13 @@ describe('ReactIncrementalSideEffects', () => {
140 }
141
142 ReactNoop.render(<Foo show={true} />);
141 - expect(ReactNoop).toFlushWithoutYielding();
143 + expect(Scheduler).toFlushWithoutYielding();
144 expect(ReactNoop.getChildren()).toEqual([
145 div(div(), span('Hello'), 'World'),
146 ]);
147
148 ReactNoop.render(<Foo show={false} />);
147 - expect(ReactNoop).toFlushWithoutYielding();
149 + expect(Scheduler).toFlushWithoutYielding();
150 expect(ReactNoop.getChildren()).toEqual([div()]);
151 });
152
@@ -180,23 +182,23 @@ describe('ReactIncrementalSideEffects', () => {
182 }
183
184 ReactNoop.render(<Foo useClass={true} />);
183 - expect(ReactNoop).toFlushWithoutYielding();
185 + expect(Scheduler).toFlushWithoutYielding();
186 expect(ReactNoop.getChildren()).toEqual([div(span('Class'), 'Trail')]);
187
188 expect(unmounted).toBe(false);
189
190 ReactNoop.render(<Foo useFunction={true} />);
189 - expect(ReactNoop).toFlushWithoutYielding();
191 + expect(Scheduler).toFlushWithoutYielding();
192 expect(ReactNoop.getChildren()).toEqual([div(span('Function'), 'Trail')]);
193
194 expect(unmounted).toBe(true);
195
196 ReactNoop.render(<Foo useText={true} />);
195 - expect(ReactNoop).toFlushWithoutYielding();
197 + expect(Scheduler).toFlushWithoutYielding();
198 expect(ReactNoop.getChildren()).toEqual([div('Text', 'Trail')]);
199
200 ReactNoop.render(<Foo />);
199 - expect(ReactNoop).toFlushWithoutYielding();
201 + expect(Scheduler).toFlushWithoutYielding();
202 expect(ReactNoop.getChildren()).toEqual([div('Trail')]);
203 });
204
@@ -230,19 +232,19 @@ describe('ReactIncrementalSideEffects', () => {
232 }
233
234 ReactNoop.render(<Foo useClass={true} />);
233 - expect(ReactNoop).toFlushWithoutYielding();
235 + expect(Scheduler).toFlushWithoutYielding();
236 expect(ReactNoop.getChildren()).toEqual([div(span('Class'), 'Trail')]);
237
238 expect(unmounted).toBe(false);
239
240 ReactNoop.render(<Foo useFunction={true} />);
239 - expect(ReactNoop).toFlushWithoutYielding();
241 + expect(Scheduler).toFlushWithoutYielding();
242 expect(ReactNoop.getChildren()).toEqual([div(span('Function'), 'Trail')]);
243
244 expect(unmounted).toBe(true);
245
246 ReactNoop.render(<Foo />);
245 - expect(ReactNoop).toFlushWithoutYielding();
247 + expect(Scheduler).toFlushWithoutYielding();
248 expect(ReactNoop.getChildren()).toEqual([div('Trail')]);
249 });
250
@@ -267,7 +269,7 @@ describe('ReactIncrementalSideEffects', () => {
269 <Foo show={true} />
270 </div>,
271 );
270 - expect(ReactNoop).toFlushWithoutYielding();
272 + expect(Scheduler).toFlushWithoutYielding();
273 expect(ReactNoop.getChildren()).toEqual([div()]);
274 expect(ReactNoop.getChildren('portalContainer')).toEqual([
275 div(),
@@ -280,7 +282,7 @@ describe('ReactIncrementalSideEffects', () => {
282 <Foo show={false} />
283 </div>,
284 );
283 - expect(ReactNoop).toFlushWithoutYielding();
285 + expect(Scheduler).toFlushWithoutYielding();
286 expect(ReactNoop.getChildren()).toEqual([div()]);
287 expect(ReactNoop.getChildren('portalContainer')).toEqual([]);
288
@@ -289,7 +291,7 @@ describe('ReactIncrementalSideEffects', () => {
291 <Foo show={true} />
292 </div>,
293 );
292 - expect(ReactNoop).toFlushWithoutYielding();
294 + expect(Scheduler).toFlushWithoutYielding();
295 expect(ReactNoop.getChildren()).toEqual([div()]);
296 expect(ReactNoop.getChildren('portalContainer')).toEqual([
297 div(),
@@ -298,17 +300,17 @@ describe('ReactIncrementalSideEffects', () => {
300 ]);
301
302 ReactNoop.render(null);
301 - expect(ReactNoop).toFlushWithoutYielding();
303 + expect(Scheduler).toFlushWithoutYielding();
304 expect(ReactNoop.getChildren()).toEqual([]);
305 expect(ReactNoop.getChildren('portalContainer')).toEqual([]);
306
307 ReactNoop.render(<Foo show={false} />);
306 - expect(ReactNoop).toFlushWithoutYielding();
308 + expect(Scheduler).toFlushWithoutYielding();
309 expect(ReactNoop.getChildren()).toEqual([]);
310 expect(ReactNoop.getChildren('portalContainer')).toEqual([]);
311
312 ReactNoop.render(<Foo show={true} />);
311 - expect(ReactNoop).toFlushWithoutYielding();
313 + expect(Scheduler).toFlushWithoutYielding();
314 expect(ReactNoop.getChildren()).toEqual([]);
315 expect(ReactNoop.getChildren('portalContainer')).toEqual([
316 div(),
@@ -317,7 +319,7 @@ describe('ReactIncrementalSideEffects', () => {
319 ]);
320
321 ReactNoop.render(null);
320 - expect(ReactNoop).toFlushWithoutYielding();
322 + expect(Scheduler).toFlushWithoutYielding();
323 expect(ReactNoop.getChildren()).toEqual([]);
324 expect(ReactNoop.getChildren('portalContainer')).toEqual([]);
325 });
@@ -343,7 +345,7 @@ describe('ReactIncrementalSideEffects', () => {
345 <Foo />
346 </div>,
347 );
346 - expect(ReactNoop).toFlushWithoutYielding();
348 + expect(Scheduler).toFlushWithoutYielding();
349 expect(ReactNoop.getChildren()).toEqual([div()]);
350 expect(ReactNoop.getChildren('portalContainer')).toEqual([
351 div(),
@@ -352,12 +354,12 @@ describe('ReactIncrementalSideEffects', () => {
354 ]);
355
356 ReactNoop.render(null);
355 - expect(ReactNoop).toFlushWithoutYielding();
357 + expect(Scheduler).toFlushWithoutYielding();
358 expect(ReactNoop.getChildren()).toEqual([]);
359 expect(ReactNoop.getChildren('portalContainer')).toEqual([]);
360
361 ReactNoop.render(<Foo />);
360 - expect(ReactNoop).toFlushWithoutYielding();
362 + expect(Scheduler).toFlushWithoutYielding();
363 expect(ReactNoop.getChildren()).toEqual([]);
364 expect(ReactNoop.getChildren('portalContainer')).toEqual([
365 div(),
@@ -366,7 +368,7 @@ describe('ReactIncrementalSideEffects', () => {
368 ]);
369
370 ReactNoop.render(null);
369 - expect(ReactNoop).toFlushWithoutYielding();
371 + expect(Scheduler).toFlushWithoutYielding();
372 expect(ReactNoop.getChildren()).toEqual([]);
373 expect(ReactNoop.getChildren('portalContainer')).toEqual([]);
374 });
@@ -391,7 +393,7 @@ describe('ReactIncrementalSideEffects', () => {
393 }
394
395 ReactNoop.render(<Foo text="Hello" />);
394 - expect(ReactNoop).toFlushAndYield(['Foo', 'Bar', 'Bar', 'Bar']);
396 + expect(Scheduler).toFlushAndYield(['Foo', 'Bar', 'Bar', 'Bar']);
397 expect(ReactNoop.getChildren()).toEqual([
398 div(div(span('Hello'), span('Hello')), span('Yo')),
399 ]);
@@ -399,7 +401,7 @@ describe('ReactIncrementalSideEffects', () => {
401 ReactNoop.render(<Foo text="World" />);
402
403 // Flush some of the work without committing
402 - expect(ReactNoop).toFlushAndYieldThrough(['Foo', 'Bar']);
404 + expect(Scheduler).toFlushAndYieldThrough(['Foo', 'Bar']);
405 expect(ReactNoop.getChildren()).toEqual([
406 div(div(span('Hello'), span('Hello')), span('Yo')),
407 ]);
@@ -423,7 +425,7 @@ describe('ReactIncrementalSideEffects', () => {
425 }
426
427 ReactNoop.render(<Foo text="foo" />);
426 - expect(ReactNoop).toFlushAndYield(['Foo', 'Middle']);
428 + expect(Scheduler).toFlushAndYield(['Foo', 'Middle']);
429
430 expect(ReactNoop.getChildrenAsJSX()).toEqual(
431 <div>
@@ -434,7 +436,7 @@ describe('ReactIncrementalSideEffects', () => {
436 );
437
438 ReactNoop.render(<Foo text="bar" />, () => ReactNoop.yield('commit'));
437 - expect(ReactNoop).toFlushAndYieldThrough(['Foo', 'commit']);
439 + expect(Scheduler).toFlushAndYieldThrough(['Foo', 'commit']);
440 expect(ReactNoop.getChildrenAsJSX()).toEqual(
441 <div>
442 <div hidden={true}>
@@ -443,7 +445,7 @@ describe('ReactIncrementalSideEffects', () => {
445 </div>,
446 );
447
446 - expect(ReactNoop).toFlushAndYield(['Middle']);
448 + expect(Scheduler).toFlushAndYield(['Middle']);
449 expect(ReactNoop.getChildrenAsJSX()).toEqual(
450 <div>
451 <div hidden={true}>
@@ -484,7 +486,7 @@ describe('ReactIncrementalSideEffects', () => {
486
487 // Init
488 ReactNoop.render(<Foo text="foo" step={0} />);
487 - expect(ReactNoop).toFlushAndYield(['Foo', 'Bar', 'Bar']);
489 + expect(Scheduler).toFlushAndYield(['Foo', 'Bar', 'Bar']);
490
491 expect(ReactNoop.getChildrenAsJSX()).toEqual(
492 <div hidden={true}>
@@ -500,7 +502,7 @@ describe('ReactIncrementalSideEffects', () => {
502 ReactNoop.render(<Foo text="bar" step={1} />, () =>
503 ReactNoop.yield('commit'),
504 );
503 - expect(ReactNoop).toFlushAndYieldThrough(['Foo', 'commit', 'Bar']);
505 + expect(Scheduler).toFlushAndYieldThrough(['Foo', 'commit', 'Bar']);
506
507 // The tree remains unchanged.
508 expect(ReactNoop.getChildrenAsJSX()).toEqual(
@@ -516,7 +518,7 @@ describe('ReactIncrementalSideEffects', () => {
518 // render some higher priority work. The middle content will bailout so
519 // it remains untouched which means that it should reuse it next time.
520 ReactNoop.render(<Foo text="foo" step={1} />);
519 - expect(ReactNoop).toFlushAndYield(['Foo', 'Bar', 'Bar']);
521 + expect(Scheduler).toFlushAndYield(['Foo', 'Bar', 'Bar']);
522
523 // Since we did nothing to the middle subtree during the interruption,
524 // we should be able to reuse the reconciliation work that we already did
@@ -569,7 +571,7 @@ describe('ReactIncrementalSideEffects', () => {
571
572 // Init
573 ReactNoop.render(<Foo text="foo" step={0} />);
572 - expect(ReactNoop).toFlushAndYield(['Foo', 'Content', 'Bar', 'Bar']);
574 + expect(Scheduler).toFlushAndYield(['Foo', 'Content', 'Bar', 'Bar']);
575
576 expect(ReactNoop.getChildrenAsJSX()).toEqual(
577 <div hidden={true}>
@@ -583,7 +585,7 @@ describe('ReactIncrementalSideEffects', () => {
585 // Make a quick update which will schedule low priority work to
586 // update the middle content.
587 ReactNoop.render(<Foo text="bar" step={1} />);
586 - expect(ReactNoop).toFlushAndYieldThrough(['Foo', 'Content', 'Bar']);
588 + expect(Scheduler).toFlushAndYieldThrough(['Foo', 'Content', 'Bar']);
589
590 // The tree remains unchanged.
591 expect(ReactNoop.getChildrenAsJSX()).toEqual(
@@ -599,7 +601,7 @@ describe('ReactIncrementalSideEffects', () => {
601 // render some higher priority work. The middle content will bailout so
602 // it remains untouched which means that it should reuse it next time.
603 ReactNoop.render(<Foo text="foo" step={1} />);
602 - expect(ReactNoop).toFlushAndYield(['Foo', 'Content', 'Bar', 'Bar']);
604 + expect(Scheduler).toFlushAndYield(['Foo', 'Content', 'Bar', 'Bar']);
605
606 // Since we did nothing to the middle subtree during the interruption,
607 // we should be able to reuse the reconciliation work that we already did
@@ -622,7 +624,7 @@ describe('ReactIncrementalSideEffects', () => {
624 }
625 ReactNoop.render(<Foo step={1} />);
626 // This should be just enough to complete the tree without committing it
625 - expect(ReactNoop).toFlushAndYieldThrough(['Foo']);
627 + expect(Scheduler).toFlushAndYieldThrough(['Foo']);
628 expect(ReactNoop.getChildrenAsJSX()).toEqual(null);
629 // To confirm, perform one more unit of work. The tree should now
630 // be flushed.
@@ -631,7 +633,7 @@ describe('ReactIncrementalSideEffects', () => {
633
634 ReactNoop.render(<Foo step={2} />);
635 // This should be just enough to complete the tree without committing it
634 - expect(ReactNoop).toFlushAndYieldThrough(['Foo']);
636 + expect(Scheduler).toFlushAndYieldThrough(['Foo']);
637 expect(ReactNoop.getChildrenAsJSX()).toEqual(<span prop={1} />);
638 // This time, before we commit the tree, we update the root component with
639 // new props
@@ -643,7 +645,7 @@ describe('ReactIncrementalSideEffects', () => {
645 expect(ReactNoop.getChildrenAsJSX()).toEqual(<span prop={2} />);
646 // If we flush the rest of the work, we should get another commit that
647 // renders 3. If it renders 2 again, that means an update was dropped.
646 - expect(ReactNoop).toFlushWithoutYielding();
648 + expect(Scheduler).toFlushWithoutYielding();
649 expect(ReactNoop.getChildrenAsJSX()).toEqual(<span prop={3} />);
650 });
651
@@ -657,7 +659,7 @@ describe('ReactIncrementalSideEffects', () => {
659 }
660
661 ReactNoop.render(<Foo />);
660 - expect(ReactNoop).toFlushWithoutYielding();
662 + expect(Scheduler).toFlushWithoutYielding();
663 expect(ReactNoop.getChildrenAsJSX()).toEqual(
664 <div hidden={true}>
665 <span prop={1} />
@@ -723,7 +725,7 @@ describe('ReactIncrementalSideEffects', () => {
725 ),
726 ]);
727 ReactNoop.render(<Foo tick={3} idx={1} />);
726 - expect(ReactNoop).toFlushWithoutYielding();
728 + expect(Scheduler).toFlushWithoutYielding();
729 expect(ReactNoop.getChildren()).toEqual([
730 div(
731 span(3),
@@ -800,7 +802,7 @@ describe('ReactIncrementalSideEffects', () => {
802 expect(ops).toEqual(['Foo']);
803 ops = [];
804
803 - expect(ReactNoop).toFlushWithoutYielding();
805 + expect(Scheduler).toFlushWithoutYielding();
806 expect(ReactNoop.getChildren()).toEqual([
807 div(
808 span(1),
@@ -867,7 +869,7 @@ describe('ReactIncrementalSideEffects', () => {
869
870 // We should now be able to reuse some of the work we've already done
871 // and replay those side-effects.
870 - expect(ReactNoop).toFlushWithoutYielding();
872 + expect(Scheduler).toFlushWithoutYielding();
873 expect(ReactNoop.getChildren()).toEqual([
874 div(
875 span(3),
@@ -917,7 +919,7 @@ describe('ReactIncrementalSideEffects', () => {
919 );
920 }
921 ReactNoop.render(<Foo tick={0} idx={0} />);
920 - expect(ReactNoop).toFlushAndYield(['Foo', 'Bar', 'Bar', 'Bar']);
922 + expect(Scheduler).toFlushAndYield(['Foo', 'Bar', 'Bar', 'Bar']);
923 expect(ReactNoop.getChildrenAsJSX()).toEqual(
924 <div>
925 <span prop={0} />
@@ -930,7 +932,7 @@ describe('ReactIncrementalSideEffects', () => {
932 );
933
934 ReactNoop.render(<Foo tick={1} idx={1} />);
933 - expect(ReactNoop).toFlushAndYieldThrough(['Foo', 'Bar', 'Bar']);
935 + expect(Scheduler).toFlushAndYieldThrough(['Foo', 'Bar', 'Bar']);
936 expect(ReactNoop.getChildrenAsJSX()).toEqual(
937 <div>
938 {/* Updated */}
@@ -948,7 +950,7 @@ describe('ReactIncrementalSideEffects', () => {
950 // This should not be enough time to render the content of all the hidden
951 // items. Including the set state since that is deprioritized.
952 // ReactNoop.flushDeferredPri(35);
951 - expect(ReactNoop).toFlushAndYieldThrough(['Bar']);
953 + expect(Scheduler).toFlushAndYieldThrough(['Bar']);
954 expect(ReactNoop.getChildrenAsJSX()).toEqual(
955 <div>
956 {/* Updated */}
@@ -964,7 +966,7 @@ describe('ReactIncrementalSideEffects', () => {
966
967 // However, once we render fully, we will have enough time to finish it all
968 // at once.
967 - expect(ReactNoop).toFlushAndYield(['Bar', 'Bar', 'Bar']);
969 + expect(Scheduler).toFlushAndYield(['Bar', 'Bar', 'Bar']);
970 expect(ReactNoop.getChildrenAsJSX()).toEqual(
971 <div>
972 <span prop={1} />
@@ -995,14 +997,14 @@ describe('ReactIncrementalSideEffects', () => {
997 }
998
999 ReactNoop.render(<Foo />);
998 - expect(ReactNoop).toFlushWithoutYielding();
1000 + expect(Scheduler).toFlushWithoutYielding();
1001 expect(ReactNoop.getChildren()).toEqual([span('foo')]);
1002 let called = false;
1003 instance.setState({text: 'bar'}, () => {
1004 expect(ReactNoop.getChildren()).toEqual([span('bar')]);
1005 called = true;
1006 });
1005 - expect(ReactNoop).toFlushWithoutYielding();
1007 + expect(Scheduler).toFlushWithoutYielding();
1008 expect(called).toBe(true);
1009 });
1010
@@ -1023,13 +1025,13 @@ describe('ReactIncrementalSideEffects', () => {
1025 }
1026
1027 ReactNoop.render(<Foo />);
1026 - expect(ReactNoop).toFlushWithoutYielding();
1028 + expect(Scheduler).toFlushWithoutYielding();
1029 expect(ReactNoop.getChildren()).toEqual([span('foo')]);
1030 let called = false;
1031 instance.setState({}, () => {
1032 called = true;
1033 });
1032 - expect(ReactNoop).toFlushWithoutYielding();
1034 + expect(Scheduler).toFlushWithoutYielding();
1035 expect(called).toBe(true);
1036 });
1037
@@ -1077,11 +1079,11 @@ describe('ReactIncrementalSideEffects', () => {
1079 }
1080
1081 ReactNoop.render(<Foo show={true} />);
1080 - expect(ReactNoop).toFlushWithoutYielding();
1082 + expect(Scheduler).toFlushWithoutYielding();
1083 expect(ops).toEqual([]);
1084
1085 ReactNoop.render(<Foo show={false} />);
1084 - expect(ReactNoop).toFlushWithoutYielding();
1086 + expect(Scheduler).toFlushWithoutYielding();
1087 expect(ops).toEqual([
1088 'A',
1089 'Wrapper',
@@ -1140,7 +1142,7 @@ describe('ReactIncrementalSideEffects', () => {
1142 }
1143
1144 ReactNoop.render(<Foo />);
1143 - expect(ReactNoop).toFlushWithoutYielding();
1145 + expect(Scheduler).toFlushWithoutYielding();
1146 expect(ops).toEqual([
1147 'mount:A',
1148 'mount:B',
@@ -1156,7 +1158,7 @@ describe('ReactIncrementalSideEffects', () => {
1158 ops = [];
1159
1160 ReactNoop.render(<Foo />);
1159 - expect(ReactNoop).toFlushWithoutYielding();
1161 + expect(Scheduler).toFlushWithoutYielding();
1162 expect(ops).toEqual([
1163 'update:A',
1164 'update:B',
@@ -1197,7 +1199,7 @@ describe('ReactIncrementalSideEffects', () => {
1199 }
1200
1201 ReactNoop.render(<Foo show={true} />);
1200 - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev(
1202 + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
1203 'Warning: Function components cannot be given refs. ' +
1204 'Attempts to access this ref will fail. ' +
1205 'Did you mean to use React.forwardRef()?\n\n' +
@@ -1217,7 +1219,7 @@ describe('ReactIncrementalSideEffects', () => {
1219
1220 // Refs that switch function instances get reinvoked
1221 ReactNoop.render(<Foo show={true} />);
1220 - expect(ReactNoop).toFlushWithoutYielding();
1222 + expect(Scheduler).toFlushWithoutYielding();
1223 expect(ops).toEqual([
1224 // detach all refs that switched handlers first.
1225 null,
@@ -1230,7 +1232,7 @@ describe('ReactIncrementalSideEffects', () => {
1232 ops = [];
1233
1234 ReactNoop.render(<Foo show={false} />);
1233 - expect(ReactNoop).toFlushWithoutYielding();
1235 + expect(Scheduler).toFlushWithoutYielding();
1236 expect(ops).toEqual([
1237 // unmount
1238 null,
@@ -1261,7 +1263,7 @@ describe('ReactIncrementalSideEffects', () => {
1263 }
1264
1265 ReactNoop.render(<Foo />);
1264 - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev(
1266 + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
1267 'Warning: A string ref, "bar", has been found within a strict mode tree.',
1268 );
1269
packages/react-reconciler/src/__tests__/ReactIncrementalUpdates-test.internal.js
+42 -42
@@ -50,9 +50,9 @@ describe('ReactIncrementalUpdates', () => {
50 }
51
52 ReactNoop.render(<Foo />);
53 - expect(ReactNoop).toFlushAndYieldThrough(['commit']);
53 + expect(Scheduler).toFlushAndYieldThrough(['commit']);
54 expect(state).toEqual({a: 'a'});
55 - expect(ReactNoop).toFlushWithoutYielding();
55 + expect(Scheduler).toFlushWithoutYielding();
56 expect(state).toEqual({a: 'a', b: 'b', c: 'c'});
57 });
58
@@ -73,7 +73,7 @@ describe('ReactIncrementalUpdates', () => {
73 }
74
75 ReactNoop.render(<Foo />);
76 - expect(ReactNoop).toFlushWithoutYielding();
76 + expect(Scheduler).toFlushWithoutYielding();
77 expect(state).toEqual({a: 'a', b: 'b', c: 'c'});
78 });
79
@@ -96,7 +96,7 @@ describe('ReactIncrementalUpdates', () => {
96 }
97
98 ReactNoop.render(<Foo />);
99 - expect(ReactNoop).toFlushWithoutYielding();
99 + expect(Scheduler).toFlushWithoutYielding();
100
101 ReactNoop.flushSync(() => {
102 ReactNoop.deferredUpdates(() => {
@@ -123,7 +123,7 @@ describe('ReactIncrementalUpdates', () => {
123
124 ops = [];
125
126 - expect(ReactNoop).toFlushWithoutYielding();
126 + expect(Scheduler).toFlushWithoutYielding();
127 // Now the rest of the updates are flushed, including the replaceState.
128 expect(instance.state).toEqual({c: 'c', d: 'd'});
129 expect(ops).toEqual(['render', 'componentDidUpdate']);
@@ -146,7 +146,7 @@ describe('ReactIncrementalUpdates', () => {
146 }
147
148 ReactNoop.render(<Foo />);
149 - expect(ReactNoop).toFlushWithoutYielding();
149 + expect(Scheduler).toFlushWithoutYielding();
150
151 function createUpdate(letter) {
152 return () => {
@@ -163,7 +163,7 @@ describe('ReactIncrementalUpdates', () => {
163 instance.setState(createUpdate('c'));
164
165 // Begin the updates but don't flush them yet
166 - expect(ReactNoop).toFlushAndYieldThrough(['a', 'b', 'c']);
166 + expect(Scheduler).toFlushAndYieldThrough(['a', 'b', 'c']);
167 expect(ReactNoop.getChildren()).toEqual([span('')]);
168
169 // Schedule some more updates at different priorities
@@ -175,13 +175,13 @@ describe('ReactIncrementalUpdates', () => {
175 instance.setState(createUpdate('g'));
176
177 // The sync updates should have flushed, but not the async ones
178 - expect(ReactNoop).toHaveYielded(['e', 'f']);
178 + expect(Scheduler).toHaveYielded(['e', 'f']);
179 expect(ReactNoop.getChildren()).toEqual([span('ef')]);
180
181 // Now flush the remaining work. Even though e and f were already processed,
182 // they should be processed again, to ensure that the terminal state
183 // is deterministic.
184 - expect(ReactNoop).toFlushAndYield([
184 + expect(Scheduler).toFlushAndYield([
185 'a',
186 'b',
187 'c',
@@ -217,7 +217,7 @@ describe('ReactIncrementalUpdates', () => {
217 }
218
219 ReactNoop.render(<Foo />);
220 - expect(ReactNoop).toFlushWithoutYielding();
220 + expect(Scheduler).toFlushWithoutYielding();
221
222 function createUpdate(letter) {
223 return () => {
@@ -234,7 +234,7 @@ describe('ReactIncrementalUpdates', () => {
234 instance.setState(createUpdate('c'));
235
236 // Begin the updates but don't flush them yet
237 - expect(ReactNoop).toFlushAndYieldThrough(['a', 'b', 'c']);
237 + expect(Scheduler).toFlushAndYieldThrough(['a', 'b', 'c']);
238 expect(ReactNoop.getChildren()).toEqual([span('')]);
239
240 // Schedule some more updates at different priorities{
@@ -249,13 +249,13 @@ describe('ReactIncrementalUpdates', () => {
249
250 // The sync updates should have flushed, but not the async ones. Update d
251 // was dropped and replaced by e.
252 - expect(ReactNoop).toHaveYielded(['e', 'f']);
252 + expect(Scheduler).toHaveYielded(['e', 'f']);
253 expect(ReactNoop.getChildren()).toEqual([span('f')]);
254
255 // Now flush the remaining work. Even though e and f were already processed,
256 // they should be processed again, to ensure that the terminal state
257 // is deterministic.
258 - expect(ReactNoop).toFlushAndYield([
258 + expect(Scheduler).toFlushAndYield([
259 'a',
260 'b',
261 'c',
@@ -284,7 +284,7 @@ describe('ReactIncrementalUpdates', () => {
284 }
285 }
286 ReactNoop.render(<Foo />);
287 - expect(ReactNoop).toFlushWithoutYielding();
287 + expect(Scheduler).toFlushWithoutYielding();
288
289 instance.setState({a: 'a'});
290 instance.setState({b: 'b'});
@@ -293,7 +293,7 @@ describe('ReactIncrementalUpdates', () => {
293 instance.updater.enqueueReplaceState(instance, previousState => ({
294 previousState,
295 }));
296 - expect(ReactNoop).toFlushWithoutYielding();
296 + expect(Scheduler).toFlushWithoutYielding();
297 expect(instance.state).toEqual({previousState: {a: 'a', b: 'b'}});
298 });
299
@@ -317,7 +317,7 @@ describe('ReactIncrementalUpdates', () => {
317 }
318
319 ReactNoop.render(<Foo />);
320 - expect(ReactNoop).toFlushWithoutYielding();
320 + expect(Scheduler).toFlushWithoutYielding();
321 expect(ops).toEqual([
322 'render',
323 'did mount',
@@ -345,7 +345,7 @@ describe('ReactIncrementalUpdates', () => {
345 }
346 }
347 ReactNoop.render(<Foo />);
348 - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev(
348 + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
349 'componentWillReceiveProps: Please update the following components ' +
350 'to use static getDerivedStateFromProps instead: Foo',
351 {withoutStack: true},
@@ -376,7 +376,7 @@ describe('ReactIncrementalUpdates', () => {
376 }
377
378 ReactNoop.render(<Foo />);
379 - expect(ReactNoop).toFlushWithoutYielding();
379 + expect(Scheduler).toFlushWithoutYielding();
380
381 instance.setState(function a() {
382 ops.push('setState updater');
@@ -384,7 +384,7 @@ describe('ReactIncrementalUpdates', () => {
384 return {a: 'a'};
385 });
386
387 - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev(
387 + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
388 'An update (setState, replaceState, or forceUpdate) was scheduled ' +
389 'from inside an update function. Update functions should be pure, ' +
390 'with zero side-effects. Consider using componentDidUpdate or a ' +
@@ -406,7 +406,7 @@ describe('ReactIncrementalUpdates', () => {
406 this.setState({a: 'a'});
407 return {b: 'b'};
408 });
409 - expect(ReactNoop).toFlushWithoutYielding();
409 + expect(Scheduler).toFlushWithoutYielding();
410 });
411
412 it('getDerivedStateFromProps should update base state of updateQueue (based on product bug)', () => {
@@ -478,22 +478,22 @@ describe('ReactIncrementalUpdates', () => {
478 // updates in separate batches are all flushed in the same callback
479 ReactNoop.render(<App label="" />);
480 Scheduler.advanceTime(1000);
481 - expect(ReactNoop).toFlushAndYieldThrough(['Render: ']);
481 + expect(Scheduler).toFlushAndYieldThrough(['Render: ']);
482 interrupt();
483
484 ReactNoop.render(<App label="he" />);
485 Scheduler.advanceTime(1000);
486 - expect(ReactNoop).toFlushAndYieldThrough(['Render: ']);
486 + expect(Scheduler).toFlushAndYieldThrough(['Render: ']);
487 interrupt();
488
489 ReactNoop.render(<App label="hell" />);
490 Scheduler.advanceTime(1000);
491 - expect(ReactNoop).toFlushAndYieldThrough(['Render: ']);
491 + expect(Scheduler).toFlushAndYieldThrough(['Render: ']);
492 interrupt();
493
494 ReactNoop.render(<App label="hello" />);
495 Scheduler.advanceTime(1000);
496 - expect(ReactNoop).toFlushAndYieldThrough(['Render: ']);
496 + expect(Scheduler).toFlushAndYieldThrough(['Render: ']);
497 interrupt();
498
499 // Each update flushes in a separate commit.
@@ -502,7 +502,7 @@ describe('ReactIncrementalUpdates', () => {
502 // implementation detail. The important part of this unit test is what
503 // happens when they expire, in which case they really should be batched to
504 // avoid blocking the main thread for a long time.
505 - expect(ReactNoop).toFlushAndYield([
505 + expect(Scheduler).toFlushAndYield([
506 'Render: ',
507 'Commit: ',
508 'Render: he',
@@ -517,29 +517,29 @@ describe('ReactIncrementalUpdates', () => {
517 // instead of flushing them normally.
518 ReactNoop.render(<App label="" />);
519 Scheduler.advanceTime(1000);
520 - expect(ReactNoop).toFlushAndYieldThrough(['Render: ']);
520 + expect(Scheduler).toFlushAndYieldThrough(['Render: ']);
521 interrupt();
522
523 ReactNoop.render(<App label="go" />);
524 Scheduler.advanceTime(1000);
525 - expect(ReactNoop).toFlushAndYieldThrough(['Render: ']);
525 + expect(Scheduler).toFlushAndYieldThrough(['Render: ']);
526 interrupt();
527
528 ReactNoop.render(<App label="good" />);
529 Scheduler.advanceTime(1000);
530 - expect(ReactNoop).toFlushAndYieldThrough(['Render: ']);
530 + expect(Scheduler).toFlushAndYieldThrough(['Render: ']);
531 interrupt();
532
533 ReactNoop.render(<App label="goodbye" />);
534 Scheduler.advanceTime(1000);
535 - expect(ReactNoop).toFlushAndYieldThrough(['Render: ']);
535 + expect(Scheduler).toFlushAndYieldThrough(['Render: ']);
536 interrupt();
537
538 // All the updates should render and commit in a single batch.
539 Scheduler.advanceTime(10000);
540 - expect(ReactNoop).toHaveYielded(['Render: goodbye']);
540 + expect(Scheduler).toHaveYielded(['Render: goodbye']);
541 // Passive effect
542 - expect(ReactNoop).toFlushAndYield(['Commit: goodbye']);
542 + expect(Scheduler).toFlushAndYield(['Commit: goodbye']);
543 });
544
545 it('flushes all expired updates in a single batch across multiple roots', () => {
@@ -565,25 +565,25 @@ describe('ReactIncrementalUpdates', () => {
565 ReactNoop.renderToRootWithID(<App label="" />, 'a');
566 ReactNoop.renderToRootWithID(<App label="" />, 'b');
567 Scheduler.advanceTime(1000);
568 - expect(ReactNoop).toFlushAndYieldThrough(['Render: ']);
568 + expect(Scheduler).toFlushAndYieldThrough(['Render: ']);
569 interrupt();
570
571 ReactNoop.renderToRootWithID(<App label="he" />, 'a');
572 ReactNoop.renderToRootWithID(<App label="he" />, 'b');
573 Scheduler.advanceTime(1000);
574 - expect(ReactNoop).toFlushAndYieldThrough(['Render: ']);
574 + expect(Scheduler).toFlushAndYieldThrough(['Render: ']);
575 interrupt();
576
577 ReactNoop.renderToRootWithID(<App label="hell" />, 'a');
578 ReactNoop.renderToRootWithID(<App label="hell" />, 'b');
579 Scheduler.advanceTime(1000);
580 - expect(ReactNoop).toFlushAndYieldThrough(['Render: ']);
580 + expect(Scheduler).toFlushAndYieldThrough(['Render: ']);
581 interrupt();
582
583 ReactNoop.renderToRootWithID(<App label="hello" />, 'a');
584 ReactNoop.renderToRootWithID(<App label="hello" />, 'b');
585 Scheduler.advanceTime(1000);
586 - expect(ReactNoop).toFlushAndYieldThrough(['Render: ']);
586 + expect(Scheduler).toFlushAndYieldThrough(['Render: ']);
587 interrupt();
588
589 // Each update flushes in a separate commit.
@@ -592,7 +592,7 @@ describe('ReactIncrementalUpdates', () => {
592 // implementation detail. The important part of this unit test is what
593 // happens when they expire, in which case they really should be batched to
594 // avoid blocking the main thread for a long time.
595 - expect(ReactNoop).toFlushAndYield([
595 + expect(Scheduler).toFlushAndYield([
596 'Render: ',
597 'Commit: ',
598 'Render: ',
@@ -616,35 +616,35 @@ describe('ReactIncrementalUpdates', () => {
616 ReactNoop.renderToRootWithID(<App label="" />, 'a');
617 ReactNoop.renderToRootWithID(<App label="" />, 'b');
618 Scheduler.advanceTime(1000);
619 - expect(ReactNoop).toFlushAndYieldThrough(['Render: ']);
619 + expect(Scheduler).toFlushAndYieldThrough(['Render: ']);
620 interrupt();
621
622 ReactNoop.renderToRootWithID(<App label="go" />, 'a');
623 ReactNoop.renderToRootWithID(<App label="go" />, 'b');
624 Scheduler.advanceTime(1000);
625 - expect(ReactNoop).toFlushAndYieldThrough(['Render: ']);
625 + expect(Scheduler).toFlushAndYieldThrough(['Render: ']);
626 interrupt();
627
628 ReactNoop.renderToRootWithID(<App label="good" />, 'a');
629 ReactNoop.renderToRootWithID(<App label="good" />, 'b');
630 Scheduler.advanceTime(1000);
631 - expect(ReactNoop).toFlushAndYieldThrough(['Render: ']);
631 + expect(Scheduler).toFlushAndYieldThrough(['Render: ']);
632 interrupt();
633
634 ReactNoop.renderToRootWithID(<App label="goodbye" />, 'a');
635 ReactNoop.renderToRootWithID(<App label="goodbye" />, 'b');
636 Scheduler.advanceTime(1000);
637 - expect(ReactNoop).toFlushAndYieldThrough(['Render: ']);
637 + expect(Scheduler).toFlushAndYieldThrough(['Render: ']);
638 interrupt();
639
640 // All the updates should render and commit in a single batch.
641 Scheduler.advanceTime(10000);
642 - expect(ReactNoop).toHaveYielded([
642 + expect(Scheduler).toHaveYielded([
643 'Render: goodbye',
644 'Commit: goodbye',
645 'Render: goodbye',
646 ]);
647 // Passive effect
648 - expect(ReactNoop).toFlushAndYield(['Commit: goodbye']);
648 + expect(Scheduler).toFlushAndYield(['Commit: goodbye']);
649 });
650 });
packages/react-reconciler/src/__tests__/ReactLazy-test.internal.js
+57 -47
@@ -45,12 +45,12 @@ describe('ReactLazy', () => {
45 },
46 );
47
48 - expect(root).toFlushAndYield(['Loading...']);
48 + expect(Scheduler).toFlushAndYield(['Loading...']);
49 expect(root).toMatchRenderedOutput(null);
50
51 await Promise.resolve();
52
53 - expect(root).toFlushAndYield(['Hi']);
53 + expect(Scheduler).toFlushAndYield(['Hi']);
54 expect(root).toMatchRenderedOutput('Hi');
55
56 // Should not suspend on update
@@ -59,7 +59,7 @@ describe('ReactLazy', () => {
59 <LazyText text="Hi again" />
60 </Suspense>,
61 );
62 - expect(root).toFlushAndYield(['Hi again']);
62 + expect(Scheduler).toFlushAndYield(['Hi again']);
63 expect(root).toMatchRenderedOutput('Hi again');
64 });
65
@@ -76,7 +76,7 @@ describe('ReactLazy', () => {
76 </Suspense>,
77 );
78
79 - expect(ReactTestRenderer).toHaveYielded(['Hi']);
79 + expect(Scheduler).toHaveYielded(['Hi']);
80 expect(root).toMatchRenderedOutput('Hi');
81 });
82
@@ -106,7 +106,7 @@ describe('ReactLazy', () => {
106 </Suspense>
107 </ErrorBoundary>,
108 );
109 - expect(ReactTestRenderer).toHaveYielded([]);
109 + expect(Scheduler).toHaveYielded([]);
110 expect(root).toMatchRenderedOutput('Error: oh no');
111 });
112
@@ -135,19 +135,19 @@ describe('ReactLazy', () => {
135 },
136 );
137
138 - expect(root).toFlushAndYield(['Loading...']);
138 + expect(Scheduler).toFlushAndYield(['Loading...']);
139 expect(root).toMatchRenderedOutput(null);
140
141 jest.advanceTimersByTime(1000);
142 await promiseForFoo;
143
144 - expect(root).toFlushAndYield(['Foo', 'Loading...']);
144 + expect(Scheduler).toFlushAndYield(['Foo', 'Loading...']);
145 expect(root).toMatchRenderedOutput(null);
146
147 jest.advanceTimersByTime(1000);
148 await promiseForBar;
149
150 - expect(root).toFlushAndYield(['Foo', 'Bar']);
150 + expect(Scheduler).toFlushAndYield(['Foo', 'Bar']);
151 expect(root).toMatchRenderedOutput('FooBar');
152 });
153
@@ -164,7 +164,7 @@ describe('ReactLazy', () => {
164 unstable_isConcurrent: true,
165 },
166 );
167 - expect(root).toFlushAndYield(['Loading...']);
167 + expect(Scheduler).toFlushAndYield(['Loading...']);
168 expect(root).toMatchRenderedOutput(null);
169
170 await Promise.resolve();
@@ -175,7 +175,7 @@ describe('ReactLazy', () => {
175 'Expected the result of a dynamic import() call',
176 );
177 }
178 - expect(root).toFlushAndThrow('Element type is invalid');
178 + expect(Scheduler).toFlushAndThrow('Element type is invalid');
179 });
180
181 it('throws if promise rejects', async () => {
@@ -192,14 +192,14 @@ describe('ReactLazy', () => {
192 },
193 );
194
195 - expect(root).toFlushAndYield(['Loading...']);
195 + expect(Scheduler).toFlushAndYield(['Loading...']);
196 expect(root).toMatchRenderedOutput(null);
197
198 try {
199 await Promise.resolve();
200 } catch (e) {}
201
202 - expect(root).toFlushAndThrow('Bad network');
202 + expect(Scheduler).toFlushAndThrow('Bad network');
203 });
204
205 it('mount and reorder', async () => {
@@ -238,18 +238,28 @@ describe('ReactLazy', () => {
238 unstable_isConcurrent: true,
239 });
240
241 - expect(root).toFlushAndYield(['Loading...']);
241 + expect(Scheduler).toFlushAndYield(['Loading...']);
242 expect(root).toMatchRenderedOutput(null);
243
244 await LazyChildA;
245 await LazyChildB;
246
247 - expect(root).toFlushAndYield(['A', 'B', 'Did mount: A', 'Did mount: B']);
247 + expect(Scheduler).toFlushAndYield([
248 + 'A',
249 + 'B',
250 + 'Did mount: A',
251 + 'Did mount: B',
252 + ]);
253 expect(root).toMatchRenderedOutput('AB');
254
255 // Swap the position of A and B
256 root.update(<Parent swap={true} />);
252 - expect(root).toFlushAndYield(['B', 'A', 'Did update: B', 'Did update: A']);
257 + expect(Scheduler).toFlushAndYield([
258 + 'B',
259 + 'A',
260 + 'Did update: B',
261 + 'Did update: A',
262 + ]);
263 expect(root).toMatchRenderedOutput('BA');
264 });
265
@@ -269,12 +279,12 @@ describe('ReactLazy', () => {
279 },
280 );
281
272 - expect(root).toFlushAndYield(['Loading...']);
282 + expect(Scheduler).toFlushAndYield(['Loading...']);
283 expect(root).toMatchRenderedOutput(null);
284
285 await Promise.resolve();
286
277 - expect(root).toFlushAndYield(['Hi']);
287 + expect(Scheduler).toFlushAndYield(['Hi']);
288 expect(root).toMatchRenderedOutput('Hi');
289
290 T.defaultProps = {text: 'Hi again'};
@@ -283,7 +293,7 @@ describe('ReactLazy', () => {
293 <LazyText />
294 </Suspense>,
295 );
286 - expect(root).toFlushAndYield(['Hi again']);
296 + expect(Scheduler).toFlushAndYield(['Hi again']);
297 expect(root).toMatchRenderedOutput('Hi again');
298 });
299
@@ -319,17 +329,17 @@ describe('ReactLazy', () => {
329 unstable_isConcurrent: true,
330 },
331 );
322 - expect(root).toFlushAndYield(['Loading...']);
332 + expect(Scheduler).toFlushAndYield(['Loading...']);
333 expect(root).toMatchRenderedOutput(null);
334
335 await Promise.resolve();
336
327 - expect(root).toFlushAndYield(['Lazy', 'Sibling', 'A']);
337 + expect(Scheduler).toFlushAndYield(['Lazy', 'Sibling', 'A']);
338 expect(root).toMatchRenderedOutput('SiblingA');
339
340 // Lazy should not re-render
341 stateful.current.setState({text: 'B'});
332 - expect(root).toFlushAndYield(['B']);
342 + expect(Scheduler).toFlushAndYield(['B']);
343 expect(root).toMatchRenderedOutput('SiblingB');
344 });
345
@@ -392,12 +402,12 @@ describe('ReactLazy', () => {
402 },
403 );
404
395 - expect(root).toFlushAndYield(['Loading...']);
405 + expect(Scheduler).toFlushAndYield(['Loading...']);
406 expect(root).toMatchRenderedOutput(null);
407
408 await Promise.resolve();
409
400 - expect(root).toFlushAndYield([
410 + expect(Scheduler).toFlushAndYield([
411 'constructor: A',
412 'getDerivedStateFromProps: A',
413 'A1',
@@ -409,7 +419,7 @@ describe('ReactLazy', () => {
419 <LazyClass num={2} />
420 </Suspense>,
421 );
412 - expect(root).toFlushAndYield([
422 + expect(Scheduler).toFlushAndYield([
423 'getDerivedStateFromProps: A',
424 'shouldComponentUpdate: A -> A',
425 'A2',
@@ -423,7 +433,7 @@ describe('ReactLazy', () => {
433 <LazyClass num={3} />
434 </Suspense>,
435 );
426 - expect(root).toFlushAndYield([
436 + expect(Scheduler).toFlushAndYield([
437 'getDerivedStateFromProps: A',
438 'shouldComponentUpdate: A -> A',
439 'A3',
@@ -469,8 +479,8 @@ describe('ReactLazy', () => {
479 </Suspense>,
480 );
481
472 - expect(ReactTestRenderer).toHaveYielded(['Loading...']);
473 - expect(root).toFlushAndYield([]);
482 + expect(Scheduler).toHaveYielded(['Loading...']);
483 + expect(Scheduler).toFlushAndYield([]);
484 expect(root).toMatchRenderedOutput('Loading...');
485
486 await Promise.resolve();
@@ -480,14 +490,14 @@ describe('ReactLazy', () => {
490 <LazyClass num={2} />
491 </Suspense>,
492 );
483 - expect(ReactTestRenderer).toHaveYielded([
493 + expect(Scheduler).toHaveYielded([
494 'UNSAFE_componentWillMount: A',
495 'A1',
496 'UNSAFE_componentWillReceiveProps: A -> A',
497 'UNSAFE_componentWillUpdate: A -> A',
498 'A2',
499 ]);
490 - expect(root).toFlushAndYield([]);
500 + expect(Scheduler).toFlushAndYield([]);
501 expect(root).toMatchRenderedOutput('A2');
502
503 root.update(
@@ -495,12 +505,12 @@ describe('ReactLazy', () => {
505 <LazyClass num={3} />
506 </Suspense>,
507 );
498 - expect(ReactTestRenderer).toHaveYielded([
508 + expect(Scheduler).toHaveYielded([
509 'UNSAFE_componentWillReceiveProps: A -> A',
510 'UNSAFE_componentWillUpdate: A -> A',
511 'A3',
512 ]);
503 - expect(root).toFlushAndYield([]);
513 + expect(Scheduler).toFlushAndYield([]);
514 expect(root).toMatchRenderedOutput('A3');
515 });
516
@@ -529,11 +539,11 @@ describe('ReactLazy', () => {
539 },
540 );
541
532 - expect(root).toFlushAndYield(['Loading...']);
542 + expect(Scheduler).toFlushAndYield(['Loading...']);
543 expect(root).toMatchRenderedOutput(null);
544
545 await Promise.resolve();
536 - expect(root).toFlushAndYield(['Hi Bye']);
546 + expect(Scheduler).toFlushAndYield(['Hi Bye']);
547 expect(root).toMatchRenderedOutput('Hi Bye');
548
549 root.update(
@@ -541,7 +551,7 @@ describe('ReactLazy', () => {
551 <LazyText outer="World" />
552 </Suspense>,
553 );
544 - expect(root).toFlushAndYield(['Hi World']);
554 + expect(Scheduler).toFlushAndYield(['Hi World']);
555 expect(root).toMatchRenderedOutput('Hi World');
556
557 root.update(
@@ -549,7 +559,7 @@ describe('ReactLazy', () => {
559 <LazyText inner="Friends" />
560 </Suspense>,
561 );
552 - expect(root).toFlushAndYield(['Friends Bye']);
562 + expect(Scheduler).toFlushAndYield(['Friends Bye']);
563 expect(root).toMatchRenderedOutput('Friends Bye');
564 });
565
@@ -565,7 +575,7 @@ describe('ReactLazy', () => {
575 },
576 );
577
568 - expect(root).toFlushAndYield(['Loading...']);
578 + expect(Scheduler).toFlushAndYield(['Loading...']);
579 expect(root).toMatchRenderedOutput(null);
580
581 await Promise.resolve();
@@ -593,7 +603,7 @@ describe('ReactLazy', () => {
603 },
604 );
605
596 - expect(root).toFlushAndYield(['Loading...']);
606 + expect(Scheduler).toFlushAndYield(['Loading...']);
607 expect(root).toMatchRenderedOutput(null);
608
609 await Promise.resolve();
@@ -643,7 +653,7 @@ describe('ReactLazy', () => {
653 },
654 );
655
646 - expect(root).toFlushAndYield(['Loading...']);
656 + expect(Scheduler).toFlushAndYield(['Loading...']);
657 expect(root).toMatchRenderedOutput(null);
658
659 // Mount
@@ -829,7 +839,7 @@ describe('ReactLazy', () => {
839 },
840 );
841
832 - expect(root).toFlushAndYield(['Loading...']);
842 + expect(Scheduler).toFlushAndYield(['Loading...']);
843 expect(root).toMatchRenderedOutput(null);
844
845 // Mount
@@ -871,13 +881,13 @@ describe('ReactLazy', () => {
881 },
882 );
883
874 - expect(root).toFlushAndYield(['Started loading', 'Loading...']);
884 + expect(Scheduler).toFlushAndYield(['Started loading', 'Loading...']);
885 expect(root).toMatchRenderedOutput(null);
886
887 await Promise.resolve();
888
889 expect(() => {
880 - expect(root).toFlushAndYield(['A', 'B']);
890 + expect(Scheduler).toFlushAndYield(['A', 'B']);
891 }).toWarnDev(' in Text (at **)\n' + ' in Foo (at **)');
892 expect(root).toMatchRenderedOutput(<div>AB</div>);
893 });
@@ -917,13 +927,13 @@ describe('ReactLazy', () => {
927 },
928 );
929
920 - expect(root).toFlushAndYield(['Loading...']);
930 + expect(Scheduler).toFlushAndYield(['Loading...']);
931 expect(root).toMatchRenderedOutput(null);
932 expect(ref.current).toBe(null);
933
934 await Promise.resolve();
935
926 - expect(root).toFlushAndYield(['Foo', 'forwardRef', 'Bar']);
936 + expect(Scheduler).toFlushAndYield(['Foo', 'forwardRef', 'Bar']);
937 expect(root).toMatchRenderedOutput('FooBar');
938 expect(ref.current).not.toBe(null);
939 });
@@ -945,7 +955,7 @@ describe('ReactLazy', () => {
955 unstable_isConcurrent: true,
956 },
957 );
948 - expect(root).toFlushAndYield(['Loading...']);
958 + expect(Scheduler).toFlushAndYield(['Loading...']);
959 expect(root).toMatchRenderedOutput(null);
960
961 // Mount
@@ -1029,7 +1039,7 @@ describe('ReactLazy', () => {
1039 unstable_isConcurrent: true,
1040 },
1041 );
1032 - expect(root).toFlushAndYield(['Loading...']);
1042 + expect(Scheduler).toFlushAndYield(['Loading...']);
1043 expect(root).toMatchRenderedOutput(null);
1044
1045 // Mount
@@ -1072,11 +1082,11 @@ describe('ReactLazy', () => {
1082 },
1083 );
1084
1075 - expect(root).toFlushAndYield(['Loading...']);
1085 + expect(Scheduler).toFlushAndYield(['Loading...']);
1086 expect(root).toMatchRenderedOutput(null);
1087 await Promise.resolve();
1088 expect(() => {
1079 - expect(root).toFlushAndYield([]);
1089 + expect(Scheduler).toFlushAndYield([]);
1090 }).toWarnDev('Function components cannot be given refs');
1091 });
1092 });
packages/react-reconciler/src/__tests__/ReactMemo-test.internal.js
+31 -29
@@ -17,6 +17,7 @@ let React;
17 let ReactFeatureFlags;
18 let ReactNoop;
19 let Suspense;
20 +let Scheduler;
21
22 describe('memo', () => {
23 beforeEach(() => {
@@ -26,6 +27,7 @@ describe('memo', () => {
27 PropTypes = require('prop-types');
28 React = require('react');
29 ReactNoop = require('react-noop-renderer');
30 + Scheduler = require('scheduler');
31 ({Suspense} = React);
32 });
33
@@ -54,7 +56,7 @@ describe('memo', () => {
56 return <App ref={() => {}} />;
57 }
58 ReactNoop.render(<Outer />);
57 - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev([
59 + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev([
60 'Warning: Function components cannot be given refs. Attempts to access ' +
61 'this ref will fail.',
62 ]);
@@ -72,7 +74,7 @@ describe('memo', () => {
74 return <App ref={() => {}} />;
75 }
76 ReactNoop.render(<Outer />);
75 - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev([
77 + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev([
78 'Warning: Function components cannot be given refs. Attempts to access ' +
79 'this ref will fail.',
80 ]);
@@ -106,9 +108,9 @@ describe('memo', () => {
108 <Counter count={0} />
109 </Suspense>,
110 );
109 - expect(ReactNoop).toFlushAndYield(['Loading...']);
111 + expect(Scheduler).toFlushAndYield(['Loading...']);
112 await Promise.resolve();
111 - expect(ReactNoop).toFlushAndYield([0]);
113 + expect(Scheduler).toFlushAndYield([0]);
114 expect(ReactNoop.getChildren()).toEqual([span(0)]);
115
116 // Should bail out because props have not changed
@@ -117,7 +119,7 @@ describe('memo', () => {
119 <Counter count={0} />
120 </Suspense>,
121 );
120 - expect(ReactNoop).toFlushAndYield([]);
122 + expect(Scheduler).toFlushAndYield([]);
123 expect(ReactNoop.getChildren()).toEqual([span(0)]);
124
125 // Should update because count prop changed
@@ -126,7 +128,7 @@ describe('memo', () => {
128 <Counter count={1} />
129 </Suspense>,
130 );
129 - expect(ReactNoop).toFlushAndYield([1]);
131 + expect(Scheduler).toFlushAndYield([1]);
132 expect(ReactNoop.getChildren()).toEqual([span(1)]);
133 });
134
@@ -161,19 +163,19 @@ describe('memo', () => {
163
164 const parent = React.createRef(null);
165 ReactNoop.render(<Parent ref={parent} />);
164 - expect(ReactNoop).toFlushAndYield(['Loading...']);
166 + expect(Scheduler).toFlushAndYield(['Loading...']);
167 await Promise.resolve();
166 - expect(ReactNoop).toFlushAndYield(['Count: 0']);
168 + expect(Scheduler).toFlushAndYield(['Count: 0']);
169 expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
170
171 // Should bail out because props have not changed
172 ReactNoop.render(<Parent ref={parent} />);
171 - expect(ReactNoop).toFlushAndYield([]);
173 + expect(Scheduler).toFlushAndYield([]);
174 expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
175
176 // Should update because there was a context change
177 parent.current.setState({count: 1});
176 - expect(ReactNoop).toFlushAndYield(['Count: 1']);
178 + expect(Scheduler).toFlushAndYield(['Count: 1']);
179 expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]);
180 });
181
@@ -193,9 +195,9 @@ describe('memo', () => {
195 <Counter count={0} />
196 </Suspense>,
197 );
196 - expect(ReactNoop).toFlushAndYield(['Loading...']);
198 + expect(Scheduler).toFlushAndYield(['Loading...']);
199 await Promise.resolve();
198 - expect(ReactNoop).toFlushAndYield([0]);
200 + expect(Scheduler).toFlushAndYield([0]);
201 expect(ReactNoop.getChildren()).toEqual([span(0)]);
202
203 // Should bail out because props have not changed
@@ -204,7 +206,7 @@ describe('memo', () => {
206 <Counter count={0} />
207 </Suspense>,
208 );
207 - expect(ReactNoop).toFlushAndYield(['Old count: 0, New count: 0']);
209 + expect(Scheduler).toFlushAndYield(['Old count: 0, New count: 0']);
210 expect(ReactNoop.getChildren()).toEqual([span(0)]);
211
212 // Should update because count prop changed
@@ -213,7 +215,7 @@ describe('memo', () => {
215 <Counter count={1} />
216 </Suspense>,
217 );
216 - expect(ReactNoop).toFlushAndYield(['Old count: 0, New count: 1', 1]);
218 + expect(Scheduler).toFlushAndYield(['Old count: 0, New count: 1', 1]);
219 expect(ReactNoop.getChildren()).toEqual([span(1)]);
220 });
221
@@ -231,9 +233,9 @@ describe('memo', () => {
233 <Counter count={0} />
234 </Suspense>,
235 );
234 - expect(ReactNoop).toFlushAndYield(['Loading...']);
236 + expect(Scheduler).toFlushAndYield(['Loading...']);
237 await Promise.resolve();
236 - expect(ReactNoop).toFlushAndYield(['0!']);
238 + expect(Scheduler).toFlushAndYield(['0!']);
239 expect(ReactNoop.getChildren()).toEqual([span('0!')]);
240
241 // Should bail out because props have not changed
@@ -242,7 +244,7 @@ describe('memo', () => {
244 <Counter count={0} />
245 </Suspense>,
246 );
245 - expect(ReactNoop).toFlushAndYield([]);
247 + expect(Scheduler).toFlushAndYield([]);
248 expect(ReactNoop.getChildren()).toEqual([span('0!')]);
249
250 // Should update because count prop changed
@@ -251,7 +253,7 @@ describe('memo', () => {
253 <Counter count={1} />
254 </Suspense>,
255 );
254 - expect(ReactNoop).toFlushAndYield(['1!']);
256 + expect(Scheduler).toFlushAndYield(['1!']);
257 expect(ReactNoop.getChildren()).toEqual([span('1!')]);
258 });
259
@@ -284,9 +286,9 @@ describe('memo', () => {
286 <Counter e={5} />
287 </Suspense>,
288 );
287 - expect(ReactNoop).toFlushAndYield(['Loading...']);
289 + expect(Scheduler).toFlushAndYield(['Loading...']);
290 await Promise.resolve();
289 - expect(ReactNoop).toFlushAndYield([15]);
291 + expect(Scheduler).toFlushAndYield([15]);
292 expect(ReactNoop.getChildren()).toEqual([span(15)]);
293
294 // Should bail out because props have not changed
@@ -295,7 +297,7 @@ describe('memo', () => {
297 <Counter e={5} />
298 </Suspense>,
299 );
298 - expect(ReactNoop).toFlushAndYield([]);
300 + expect(Scheduler).toFlushAndYield([]);
301 expect(ReactNoop.getChildren()).toEqual([span(15)]);
302
303 // Should update because count prop changed
@@ -304,7 +306,7 @@ describe('memo', () => {
306 <Counter e={10} />
307 </Suspense>,
308 );
307 - expect(ReactNoop).toFlushAndYield([20]);
309 + expect(Scheduler).toFlushAndYield([20]);
310 expect(ReactNoop.getChildren()).toEqual([span(20)]);
311 });
312
@@ -334,7 +336,7 @@ describe('memo', () => {
336 // Mount
337 expect(() => {
338 ReactNoop.render(<Fn inner="2" />);
337 - expect(ReactNoop).toFlushWithoutYielding();
339 + expect(Scheduler).toFlushWithoutYielding();
340 }).toWarnDev(
341 'Invalid prop `inner` of type `string` supplied to `FnInner`, expected `number`.',
342 );
@@ -342,7 +344,7 @@ describe('memo', () => {
344 // Update
345 expect(() => {
346 ReactNoop.render(<Fn inner={false} />);
345 - expect(ReactNoop).toFlushWithoutYielding();
347 + expect(Scheduler).toFlushWithoutYielding();
348 }).toWarnDev(
349 'Invalid prop `inner` of type `boolean` supplied to `FnInner`, expected `number`.',
350 );
@@ -358,7 +360,7 @@ describe('memo', () => {
360 // Mount
361 expect(() => {
362 ReactNoop.render(<Fn outer="3" />);
361 - expect(ReactNoop).toFlushWithoutYielding();
363 + expect(Scheduler).toFlushWithoutYielding();
364 }).toWarnDev(
365 // Outer props are checked in createElement
366 'Invalid prop `outer` of type `string` supplied to `FnInner`, expected `number`.',
@@ -367,7 +369,7 @@ describe('memo', () => {
369 // Update
370 expect(() => {
371 ReactNoop.render(<Fn outer={false} />);
370 - expect(ReactNoop).toFlushWithoutYielding();
372 + expect(Scheduler).toFlushWithoutYielding();
373 }).toWarnDev(
374 // Outer props are checked in createElement
375 'Invalid prop `outer` of type `boolean` supplied to `FnInner`, expected `number`.',
@@ -389,12 +391,12 @@ describe('memo', () => {
391
392 // No warning expected because defaultProps satisfy both.
393 ReactNoop.render(<Outer />);
392 - expect(ReactNoop).toFlushWithoutYielding();
394 + expect(Scheduler).toFlushWithoutYielding();
395
396 // Mount
397 expect(() => {
398 ReactNoop.render(<Outer inner="2" middle="3" outer="4" />);
397 - expect(ReactNoop).toFlushWithoutYielding();
399 + expect(Scheduler).toFlushWithoutYielding();
400 }).toWarnDev([
401 'Invalid prop `outer` of type `string` supplied to `Inner`, expected `number`.',
402 'Invalid prop `middle` of type `string` supplied to `Inner`, expected `number`.',
@@ -406,7 +408,7 @@ describe('memo', () => {
408 ReactNoop.render(
409 <Outer inner={false} middle={false} outer={false} />,
410 );
409 - expect(ReactNoop).toFlushWithoutYielding();
411 + expect(Scheduler).toFlushWithoutYielding();
412 }).toWarnDev([
413 'Invalid prop `outer` of type `boolean` supplied to `Inner`, expected `number`.',
414 'Invalid prop `middle` of type `boolean` supplied to `Inner`, expected `number`.',
packages/react-reconciler/src/__tests__/ReactNewContext-test.internal.js
+72 -71
@@ -146,12 +146,12 @@ describe('ReactNewContext', () => {
146 }
147
148 ReactNoop.render(<App value={2} />);
149 - expect(ReactNoop).toFlushWithoutYielding();
149 + expect(Scheduler).toFlushWithoutYielding();
150 expect(ReactNoop.getChildren()).toEqual([span('Result: 2')]);
151
152 // Update
153 ReactNoop.render(<App value={3} />);
154 - expect(ReactNoop).toFlushWithoutYielding();
154 + expect(Scheduler).toFlushWithoutYielding();
155 expect(ReactNoop.getChildren()).toEqual([span('Result: 3')]);
156 });
157
@@ -204,7 +204,7 @@ describe('ReactNewContext', () => {
204 }
205
206 ReactNoop.render(<App value={2} />);
207 - expect(ReactNoop).toFlushAndYield([
207 + expect(Scheduler).toFlushAndYield([
208 'App',
209 'Provider',
210 'Indirection',
@@ -216,7 +216,7 @@ describe('ReactNewContext', () => {
216
217 // Update
218 ReactNoop.render(<App value={3} />);
219 - expect(ReactNoop).toFlushAndYield([
219 + expect(Scheduler).toFlushAndYield([
220 'App',
221 'Provider',
222 'Consumer render prop',
@@ -273,7 +273,7 @@ describe('ReactNewContext', () => {
273 }
274
275 ReactNoop.render(<App value={2} />);
276 - expect(ReactNoop).toFlushAndYield([
276 + expect(Scheduler).toFlushAndYield([
277 'App',
278 'Provider',
279 'Indirection',
@@ -285,7 +285,7 @@ describe('ReactNewContext', () => {
285
286 // Update with the same context value
287 ReactNoop.render(<App value={2} />);
288 - expect(ReactNoop).toFlushAndYield([
288 + expect(Scheduler).toFlushAndYield([
289 'App',
290 'Provider',
291 // Don't call render prop again
@@ -340,12 +340,12 @@ describe('ReactNewContext', () => {
340 }
341
342 ReactNoop.render(<App value={2} />);
343 - expect(ReactNoop).toFlushWithoutYielding();
343 + expect(Scheduler).toFlushWithoutYielding();
344 expect(ReactNoop.getChildren()).toEqual([span('Result: 8')]);
345
346 // Update
347 ReactNoop.render(<App value={3} />);
348 - expect(ReactNoop).toFlushWithoutYielding();
348 + expect(Scheduler).toFlushWithoutYielding();
349 expect(ReactNoop.getChildren()).toEqual([span('Result: 12')]);
350 });
351
@@ -384,7 +384,7 @@ describe('ReactNewContext', () => {
384 </BarConsumer>
385 </React.Fragment>,
386 );
387 - expect(ReactNoop).toFlushWithoutYielding();
387 + expect(Scheduler).toFlushWithoutYielding();
388 });
389
390 it('multiple consumers in different branches', () => {
@@ -435,7 +435,7 @@ describe('ReactNewContext', () => {
435 }
436
437 ReactNoop.render(<App value={2} />);
438 - expect(ReactNoop).toFlushWithoutYielding();
438 + expect(Scheduler).toFlushWithoutYielding();
439 expect(ReactNoop.getChildren()).toEqual([
440 span('Result: 4'),
441 span('Result: 2'),
@@ -443,7 +443,7 @@ describe('ReactNewContext', () => {
443
444 // Update
445 ReactNoop.render(<App value={3} />);
446 - expect(ReactNoop).toFlushWithoutYielding();
446 + expect(Scheduler).toFlushWithoutYielding();
447 expect(ReactNoop.getChildren()).toEqual([
448 span('Result: 6'),
449 span('Result: 3'),
@@ -451,7 +451,7 @@ describe('ReactNewContext', () => {
451
452 // Another update
453 ReactNoop.render(<App value={4} />);
454 - expect(ReactNoop).toFlushWithoutYielding();
454 + expect(Scheduler).toFlushWithoutYielding();
455 expect(ReactNoop.getChildren()).toEqual([
456 span('Result: 8'),
457 span('Result: 4'),
@@ -507,7 +507,7 @@ describe('ReactNewContext', () => {
507 }
508
509 ReactNoop.render(<App value={NaN} />);
510 - expect(ReactNoop).toFlushAndYield([
510 + expect(Scheduler).toFlushAndYield([
511 'App',
512 'Provider',
513 'Indirection',
@@ -519,7 +519,7 @@ describe('ReactNewContext', () => {
519
520 // Update
521 ReactNoop.render(<App value={NaN} />);
522 - expect(ReactNoop).toFlushAndYield([
522 + expect(Scheduler).toFlushAndYield([
523 'App',
524 'Provider',
525 // Consumer should not re-render again
@@ -573,7 +573,7 @@ describe('ReactNewContext', () => {
573 }
574
575 ReactNoop.render(<App value="A" />);
576 - expect(ReactNoop).toFlushWithoutYielding();
576 + expect(Scheduler).toFlushWithoutYielding();
577 expect(ReactNoop.getChildren()).toEqual([
578 // The second provider should use the default value.
579 span('Result: Does not unwind'),
@@ -648,7 +648,7 @@ describe('ReactNewContext', () => {
648 }
649
650 ReactNoop.render(<App foo={1} bar={1} />);
651 - expect(ReactNoop).toFlushAndYield(['Foo', 'Bar']);
651 + expect(Scheduler).toFlushAndYield(['Foo', 'Bar']);
652 expect(ReactNoop.getChildren()).toEqual([
653 span('Foo: 1'),
654 span('Bar: 1'),
@@ -656,7 +656,7 @@ describe('ReactNewContext', () => {
656
657 // Update only foo
658 ReactNoop.render(<App foo={2} bar={1} />);
659 - expect(ReactNoop).toFlushAndYield(['Foo']);
659 + expect(Scheduler).toFlushAndYield(['Foo']);
660 expect(ReactNoop.getChildren()).toEqual([
661 span('Foo: 2'),
662 span('Bar: 1'),
@@ -664,7 +664,7 @@ describe('ReactNewContext', () => {
664
665 // Update only bar
666 ReactNoop.render(<App foo={2} bar={2} />);
667 - expect(ReactNoop).toFlushAndYield(['Bar']);
667 + expect(Scheduler).toFlushAndYield(['Bar']);
668 expect(ReactNoop.getChildren()).toEqual([
669 span('Foo: 2'),
670 span('Bar: 2'),
@@ -672,7 +672,7 @@ describe('ReactNewContext', () => {
672
673 // Update both
674 ReactNoop.render(<App foo={3} bar={3} />);
675 - expect(ReactNoop).toFlushAndYield(['Foo', 'Bar']);
675 + expect(Scheduler).toFlushAndYield(['Foo', 'Bar']);
676 expect(ReactNoop.getChildren()).toEqual([
677 span('Foo: 3'),
678 span('Bar: 3'),
@@ -765,7 +765,7 @@ describe('ReactNewContext', () => {
765 }
766
767 ReactNoop.render(<App foo={1} bar={1} />);
768 - expect(ReactNoop).toFlushAndYield(['Foo', 'Bar', 'Foo']);
768 + expect(Scheduler).toFlushAndYield(['Foo', 'Bar', 'Foo']);
769 expect(ReactNoop.getChildren()).toEqual([
770 span('Foo: 1'),
771 span('Bar: 1'),
@@ -774,7 +774,7 @@ describe('ReactNewContext', () => {
774
775 // Update only foo
776 ReactNoop.render(<App foo={2} bar={1} />);
777 - expect(ReactNoop).toFlushAndYield(['Foo', 'Foo']);
777 + expect(Scheduler).toFlushAndYield(['Foo', 'Foo']);
778 expect(ReactNoop.getChildren()).toEqual([
779 span('Foo: 2'),
780 span('Bar: 1'),
@@ -783,7 +783,7 @@ describe('ReactNewContext', () => {
783
784 // Update only bar
785 ReactNoop.render(<App foo={2} bar={2} />);
786 - expect(ReactNoop).toFlushAndYield(['Bar']);
786 + expect(Scheduler).toFlushAndYield(['Bar']);
787 expect(ReactNoop.getChildren()).toEqual([
788 span('Foo: 2'),
789 span('Bar: 2'),
@@ -792,7 +792,7 @@ describe('ReactNewContext', () => {
792
793 // Update both
794 ReactNoop.render(<App foo={3} bar={3} />);
795 - expect(ReactNoop).toFlushAndYield(['Foo', 'Bar', 'Foo']);
795 + expect(Scheduler).toFlushAndYield(['Foo', 'Bar', 'Foo']);
796 expect(ReactNoop.getChildren()).toEqual([
797 span('Foo: 3'),
798 span('Bar: 3'),
@@ -834,11 +834,11 @@ describe('ReactNewContext', () => {
834
835 // Initial mount
836 ReactNoop.render(<App value={1} />);
837 - expect(ReactNoop).toFlushAndYield(['Consumer render prop', 'Child']);
837 + expect(Scheduler).toFlushAndYield(['Consumer render prop', 'Child']);
838 expect(ReactNoop.getChildren()).toEqual([span('Context: 1, Step: 0')]);
839
840 child.setState({step: 1});
841 - expect(ReactNoop).toFlushAndYield(['Child']);
841 + expect(Scheduler).toFlushAndYield(['Child']);
842 expect(ReactNoop.getChildren()).toEqual([span('Context: 1, Step: 1')]);
843 });
844
@@ -887,7 +887,7 @@ describe('ReactNewContext', () => {
887
888 // Initial mount
889 ReactNoop.render(<App value={1} />);
890 - expect(ReactNoop).toFlushAndYield([
890 + expect(Scheduler).toFlushAndYield([
891 'App',
892 'PureIndirection',
893 'ChildWithInlineRenderCallback',
@@ -899,12 +899,12 @@ describe('ReactNewContext', () => {
899
900 // Update (bailout)
901 ReactNoop.render(<App value={1} />);
902 - expect(ReactNoop).toFlushAndYield(['App']);
902 + expect(Scheduler).toFlushAndYield(['App']);
903 expect(ReactNoop.getChildren()).toEqual([span(1), span(1)]);
904
905 // Update (no bailout)
906 ReactNoop.render(<App value={2} />);
907 - expect(ReactNoop).toFlushAndYield(['App', 'Consumer', 'Consumer']);
907 + expect(Scheduler).toFlushAndYield(['App', 'Consumer', 'Consumer']);
908 expect(ReactNoop.getChildren()).toEqual([span(2), span(2)]);
909 });
910
@@ -923,7 +923,7 @@ describe('ReactNewContext', () => {
923 }
924
925 ReactNoop.render(<App theme="dark" />);
926 - expect(ReactNoop).toFlushAndYield(['dark']);
926 + expect(Scheduler).toFlushAndYield(['dark']);
927 expect(ReactNoop.getChildrenAsJSX()).toEqual(
928 <div hidden={true}>
929 <span prop="dark" />
@@ -931,7 +931,7 @@ describe('ReactNewContext', () => {
931 );
932
933 ReactNoop.render(<App theme="light" />);
934 - expect(ReactNoop).toFlushAndYield(['light']);
934 + expect(Scheduler).toFlushAndYield(['light']);
935 expect(ReactNoop.getChildrenAsJSX()).toEqual(
936 <div hidden={true}>
937 <span prop="light" />
@@ -970,11 +970,11 @@ describe('ReactNewContext', () => {
970 }
971
972 ReactNoop.render(<App reverse={false} />);
973 - expect(ReactNoop).toFlushWithoutYielding();
973 + expect(Scheduler).toFlushWithoutYielding();
974 ReactNoop.render(<App reverse={true} />);
975 - expect(ReactNoop).toFlushWithoutYielding();
975 + expect(Scheduler).toFlushWithoutYielding();
976 ReactNoop.render(<App reverse={false} />);
977 - expect(ReactNoop).toFlushWithoutYielding();
977 + expect(Scheduler).toFlushWithoutYielding();
978 });
979
980 // This is a regression case for https://github.com/facebook/react/issues/12686
@@ -1027,14 +1027,14 @@ describe('ReactNewContext', () => {
1027 // Initial mount
1028 let inst;
1029 ReactNoop.render(<App ref={ref => (inst = ref)} />);
1030 - expect(ReactNoop).toFlushAndYield(['App']);
1030 + expect(Scheduler).toFlushAndYield(['App']);
1031 expect(ReactNoop.getChildren()).toEqual([
1032 span('static 1'),
1033 span('static 2'),
1034 ]);
1035 // Update the first time
1036 inst.setState({step: 1});
1037 - expect(ReactNoop).toFlushAndYield(['App', 'Consumer']);
1037 + expect(Scheduler).toFlushAndYield(['App', 'Consumer']);
1038 expect(ReactNoop.getChildren()).toEqual([
1039 span('static 1'),
1040 span('static 2'),
@@ -1042,7 +1042,7 @@ describe('ReactNewContext', () => {
1042 ]);
1043 // Update the second time
1044 inst.setState({step: 2});
1045 - expect(ReactNoop).toFlushAndYield(['App', 'Consumer']);
1045 + expect(Scheduler).toFlushAndYield(['App', 'Consumer']);
1046 expect(ReactNoop.getChildren()).toEqual([
1047 span('static 1'),
1048 span('static 2'),
@@ -1064,11 +1064,11 @@ describe('ReactNewContext', () => {
1064 }
1065
1066 ReactNoop.render(<App value={1} />);
1067 - expect(ReactNoop).toFlushWithoutYielding();
1067 + expect(Scheduler).toFlushWithoutYielding();
1068
1069 // Update
1070 ReactNoop.render(<App value={2} />);
1071 - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev(
1071 + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
1072 'calculateChangedBits: Expected the return value to be a 31-bit ' +
1073 'integer. Instead received: 4294967295',
1074 );
@@ -1094,17 +1094,18 @@ describe('ReactNewContext', () => {
1094
1095 ReactNoop.render(<App value={1} />);
1096 // Render past the Provider, but don't commit yet
1097 - expect(ReactNoop).toFlushAndYieldThrough(['Foo']);
1097 + expect(Scheduler).toFlushAndYieldThrough(['Foo']);
1098
1099 // Get a new copy of ReactNoop
1100 jest.resetModules();
1101 ReactFeatureFlags = require('shared/ReactFeatureFlags');
1102 React = require('react');
1103 ReactNoop = require('react-noop-renderer');
1104 + Scheduler = require('scheduler');
1105
1106 // Render the provider again using a different renderer
1107 ReactNoop.render(<App value={1} />);
1107 - expect(ReactNoop).toFlushAndYield(['Foo', 'Foo']);
1108 + expect(Scheduler).toFlushAndYield(['Foo', 'Foo']);
1109
1110 if (__DEV__) {
1111 expect(console.error.calls.argsFor(0)[0]).toContain(
@@ -1133,12 +1134,12 @@ describe('ReactNewContext', () => {
1134
1135 // Initial mount
1136 ReactNoop.render(<App value={1} />);
1136 - expect(ReactNoop).toFlushAndYield(['App', 'Child']);
1137 + expect(Scheduler).toFlushAndYield(['App', 'Child']);
1138 expect(ReactNoop.getChildren()).toEqual([span('Child')]);
1139
1140 // Update
1141 ReactNoop.render(<App value={1} />);
1141 - expect(ReactNoop).toFlushAndYield([
1142 + expect(Scheduler).toFlushAndYield([
1143 'App',
1144 // Child does not re-render
1145 ]);
@@ -1193,7 +1194,7 @@ describe('ReactNewContext', () => {
1194 </LegacyProvider>,
1195 );
1196 expect(() => {
1196 - expect(ReactNoop).toFlushAndYield(['LegacyProvider', 'App', 'Child']);
1197 + expect(Scheduler).toFlushAndYield(['LegacyProvider', 'App', 'Child']);
1198 }).toWarnDev(
1199 'Legacy context API has been detected within a strict-mode tree: \n\n' +
1200 'Please update the following components: LegacyProvider',
@@ -1203,17 +1204,17 @@ describe('ReactNewContext', () => {
1204
1205 // Update App with same value (should bail out)
1206 appRef.current.setState({value: 1});
1206 - expect(ReactNoop).toFlushAndYield(['App']);
1207 + expect(Scheduler).toFlushAndYield(['App']);
1208 expect(ReactNoop.getChildren()).toEqual([span('Child')]);
1209
1210 // Update LegacyProvider (should not bail out)
1211 legacyProviderRef.current.setState({value: 1});
1211 - expect(ReactNoop).toFlushAndYield(['LegacyProvider', 'App', 'Child']);
1212 + expect(Scheduler).toFlushAndYield(['LegacyProvider', 'App', 'Child']);
1213 expect(ReactNoop.getChildren()).toEqual([span('Child')]);
1214
1215 // Update App with same value (should bail out)
1216 appRef.current.setState({value: 1});
1216 - expect(ReactNoop).toFlushAndYield(['App']);
1217 + expect(Scheduler).toFlushAndYield(['App']);
1218 expect(ReactNoop.getChildren()).toEqual([span('Child')]);
1219 });
1220 });
@@ -1223,7 +1224,7 @@ describe('ReactNewContext', () => {
1224 spyOnDev(console, 'error');
1225 const Context = React.createContext(0);
1226 ReactNoop.render(<Context.Consumer />);
1226 - expect(ReactNoop).toFlushAndThrow('render is not a function');
1227 + expect(Scheduler).toFlushAndThrow('render is not a function');
1228 if (__DEV__) {
1229 expect(console.error.calls.argsFor(0)[0]).toContain(
1230 'A context consumer was rendered with multiple children, or a child ' +
@@ -1269,17 +1270,17 @@ describe('ReactNewContext', () => {
1270 }
1271
1272 ReactNoop.render(<App foo={1} bar={1} />);
1272 - expect(ReactNoop).toFlushAndYield(['Foo: 1, Bar: 1']);
1273 + expect(Scheduler).toFlushAndYield(['Foo: 1, Bar: 1']);
1274 expect(ReactNoop.getChildren()).toEqual([span('Foo: 1, Bar: 1')]);
1275
1276 // Update foo
1277 ReactNoop.render(<App foo={2} bar={1} />);
1277 - expect(ReactNoop).toFlushAndYield(['Foo: 2, Bar: 1']);
1278 + expect(Scheduler).toFlushAndYield(['Foo: 2, Bar: 1']);
1279 expect(ReactNoop.getChildren()).toEqual([span('Foo: 2, Bar: 1')]);
1280
1281 // Update bar
1282 ReactNoop.render(<App foo={2} bar={2} />);
1282 - expect(ReactNoop).toFlushAndYield(['Foo: 2, Bar: 2']);
1283 + expect(Scheduler).toFlushAndYield(['Foo: 2, Bar: 2']);
1284 expect(ReactNoop.getChildren()).toEqual([span('Foo: 2, Bar: 2')]);
1285 });
1286
@@ -1315,12 +1316,12 @@ describe('ReactNewContext', () => {
1316 // Initial mount
1317 let inst;
1318 ReactNoop.render(<App value={1} ref={ref => (inst = ref)} />);
1318 - expect(ReactNoop).toFlushAndYield(['App', 'App#renderConsumer']);
1319 + expect(Scheduler).toFlushAndYield(['App', 'App#renderConsumer']);
1320 expect(ReactNoop.getChildren()).toEqual([span('hello')]);
1321
1322 // Update
1323 inst.setState({text: 'goodbye'});
1323 - expect(ReactNoop).toFlushAndYield(['App', 'App#renderConsumer']);
1324 + expect(Scheduler).toFlushAndYield(['App', 'App#renderConsumer']);
1325 expect(ReactNoop.getChildren()).toEqual([span('goodbye')]);
1326 });
1327 });
@@ -1386,7 +1387,7 @@ describe('ReactNewContext', () => {
1387 }
1388
1389 ReactNoop.render(<App foo={1} bar={1} baz={1} />);
1389 - expect(ReactNoop).toFlushAndYield(['Foo: 1, Bar: 1', 'Baz: 1']);
1390 + expect(Scheduler).toFlushAndYield(['Foo: 1, Bar: 1', 'Baz: 1']);
1391 expect(ReactNoop.getChildren()).toEqual([
1392 span('Foo: 1, Bar: 1'),
1393 span('Baz: 1'),
@@ -1394,7 +1395,7 @@ describe('ReactNewContext', () => {
1395
1396 // Update only foo
1397 ReactNoop.render(<App foo={2} bar={1} baz={1} />);
1397 - expect(ReactNoop).toFlushAndYield(['Foo: 2, Bar: 1']);
1398 + expect(Scheduler).toFlushAndYield(['Foo: 2, Bar: 1']);
1399 expect(ReactNoop.getChildren()).toEqual([
1400 span('Foo: 2, Bar: 1'),
1401 span('Baz: 1'),
@@ -1402,7 +1403,7 @@ describe('ReactNewContext', () => {
1403
1404 // Update only bar
1405 ReactNoop.render(<App foo={2} bar={2} baz={1} />);
1405 - expect(ReactNoop).toFlushAndYield(['Foo: 2, Bar: 2']);
1406 + expect(Scheduler).toFlushAndYield(['Foo: 2, Bar: 2']);
1407 expect(ReactNoop.getChildren()).toEqual([
1408 span('Foo: 2, Bar: 2'),
1409 span('Baz: 1'),
@@ -1410,7 +1411,7 @@ describe('ReactNewContext', () => {
1411
1412 // Update only baz
1413 ReactNoop.render(<App foo={2} bar={2} baz={2} />);
1413 - expect(ReactNoop).toFlushAndYield(['Baz: 2']);
1414 + expect(Scheduler).toFlushAndYield(['Baz: 2']);
1415 expect(ReactNoop.getChildren()).toEqual([
1416 span('Foo: 2, Bar: 2'),
1417 span('Baz: 2'),
@@ -1455,12 +1456,12 @@ describe('ReactNewContext', () => {
1456 // Initial mount
1457 let inst;
1458 ReactNoop.render(<App value={1} ref={ref => (inst = ref)} />);
1458 - expect(ReactNoop).toFlushAndYield(['App', 'App#renderConsumer']);
1459 + expect(Scheduler).toFlushAndYield(['App', 'App#renderConsumer']);
1460 expect(ReactNoop.getChildren()).toEqual([span('hello')]);
1461
1462 // Update
1463 inst.setState({text: 'goodbye'});
1463 - expect(ReactNoop).toFlushAndYield(['App', 'App#renderConsumer']);
1464 + expect(Scheduler).toFlushAndYield(['App', 'App#renderConsumer']);
1465 expect(ReactNoop.getChildren()).toEqual([span('goodbye')]);
1466 });
1467
@@ -1478,7 +1479,7 @@ describe('ReactNewContext', () => {
1479 }
1480
1481 ReactNoop.render(<Cls />);
1481 - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev(
1482 + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
1483 [
1484 'Context can only be read while React is rendering',
1485 'Cannot update during an existing state transition',
@@ -1497,7 +1498,7 @@ describe('ReactNewContext', () => {
1498 return [Context].map(useContext);
1499 }
1500 ReactNoop.render(<Foo />);
1500 - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev(
1501 + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
1502 'useContext() second argument is reserved for future ' +
1503 'use in React. Passing it is not supported. ' +
1504 'You passed: 0.\n\n' +
@@ -1515,7 +1516,7 @@ describe('ReactNewContext', () => {
1516 }
1517 }
1518 ReactNoop.render(<Foo />);
1518 - expect(ReactNoop).toFlushAndThrow(
1519 + expect(Scheduler).toFlushAndThrow(
1520 'Hooks can only be called inside the body of a function component.',
1521 );
1522 });
@@ -1526,7 +1527,7 @@ describe('ReactNewContext', () => {
1527 return useContext(Context.Consumer);
1528 }
1529 ReactNoop.render(<Foo />);
1529 - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev(
1530 + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
1531 'Calling useContext(Context.Consumer) is not supported, may cause bugs, ' +
1532 'and will be removed in a future major release. ' +
1533 'Did you mean to call useContext(Context) instead?',
@@ -1540,7 +1541,7 @@ describe('ReactNewContext', () => {
1541 return null;
1542 }
1543 ReactNoop.render(<Foo />);
1543 - expect(() => expect(ReactNoop).toFlushWithoutYielding()).toWarnDev(
1544 + expect(() => expect(Scheduler).toFlushWithoutYielding()).toWarnDev(
1545 'Calling useContext(Context.Provider) is not supported. ' +
1546 'Did you mean to call useContext(Context) instead?',
1547 );
@@ -1582,12 +1583,12 @@ describe('ReactNewContext', () => {
1583 // Initial mount
1584 let inst;
1585 ReactNoop.render(<App value={1} ref={ref => (inst = ref)} />);
1585 - expect(ReactNoop).toFlushAndYield(['App', 'App#renderConsumer']);
1586 + expect(Scheduler).toFlushAndYield(['App', 'App#renderConsumer']);
1587 expect(ReactNoop.getChildren()).toEqual([span('hello')]);
1588
1589 // Update
1590 inst.setState({text: 'goodbye'});
1590 - expect(ReactNoop).toFlushAndYield(['App', 'App#renderConsumer']);
1591 + expect(Scheduler).toFlushAndYield(['App', 'App#renderConsumer']);
1592 expect(ReactNoop.getChildren()).toEqual([span('goodbye')]);
1593 });
1594 });
@@ -1602,14 +1603,14 @@ describe('ReactNewContext', () => {
1603 <Context.Provider />
1604 </errorInCompletePhase>,
1605 );
1605 - expect(ReactNoop).toFlushAndThrow('Error in host config.');
1606 + expect(Scheduler).toFlushAndThrow('Error in host config.');
1607
1608 ReactNoop.render(
1609 <Context.Provider value={10}>
1610 <Context.Consumer>{value => <span prop={value} />}</Context.Consumer>
1611 </Context.Provider>,
1612 );
1612 - expect(ReactNoop).toFlushWithoutYielding();
1613 + expect(Scheduler).toFlushWithoutYielding();
1614 expect(ReactNoop.getChildren()).toEqual([span(10)]);
1615 });
1616
@@ -1841,7 +1842,7 @@ Context fuzz tester error! Copy and paste the following line into the test suite
1842
1843 expect(() => {
1844 ReactNoop.render(<Component />);
1844 - expect(ReactNoop).toFlushWithoutYielding();
1845 + expect(Scheduler).toFlushWithoutYielding();
1846 }).toWarnDev(
1847 'Rendering <Context> directly is not supported and will be removed in ' +
1848 'a future major release. Did you mean to render <Context.Consumer> instead?',
@@ -1867,7 +1868,7 @@ Context fuzz tester error! Copy and paste the following line into the test suite
1868 }
1869
1870 ReactNoop.render(<Component />);
1870 - expect(ReactNoop).toFlushWithoutYielding();
1871 + expect(Scheduler).toFlushWithoutYielding();
1872 });
1873
1874 it('should warn with an error message when using nested context consumers in DEV', () => {
@@ -1888,7 +1889,7 @@ Context fuzz tester error! Copy and paste the following line into the test suite
1889
1890 expect(() => {
1891 ReactNoop.render(<Component />);
1891 - expect(ReactNoop).toFlushWithoutYielding();
1892 + expect(Scheduler).toFlushWithoutYielding();
1893 }).toWarnDev(
1894 'Rendering <Context.Consumer.Consumer> is not supported and will be removed in ' +
1895 'a future major release. Did you mean to render <Context.Consumer> instead?',
@@ -1912,7 +1913,7 @@ Context fuzz tester error! Copy and paste the following line into the test suite
1913
1914 expect(() => {
1915 ReactNoop.render(<Component />);
1915 - expect(ReactNoop).toFlushWithoutYielding();
1916 + expect(Scheduler).toFlushWithoutYielding();
1917 }).toWarnDev(
1918 'Rendering <Context.Consumer.Provider> is not supported and will be removed in ' +
1919 'a future major release. Did you mean to render <Context.Provider> instead?',
packages/react-reconciler/src/__tests__/ReactPersistent-test.js
+11 -9
@@ -12,6 +12,7 @@
12
13 let React;
14 let ReactNoopPersistent;
15 +let Scheduler;
16
17 describe('ReactPersistent', () => {
18 beforeEach(() => {
@@ -19,6 +20,7 @@ describe('ReactPersistent', () => {
20
21 React = require('react');
22 ReactNoopPersistent = require('react-noop-renderer/persistent');
23 + Scheduler = require('scheduler');
24 });
25
26 // Inlined from shared folder so we can run this test on a bundle.
@@ -66,12 +68,12 @@ describe('ReactPersistent', () => {
68 }
69
70 render(<Foo text="Hello" />);
69 - expect(ReactNoopPersistent).toFlushWithoutYielding();
71 + expect(Scheduler).toFlushWithoutYielding();
72 const originalChildren = getChildren();
73 expect(originalChildren).toEqual([div(span())]);
74
75 render(<Foo text="World" />);
74 - expect(ReactNoopPersistent).toFlushWithoutYielding();
76 + expect(Scheduler).toFlushWithoutYielding();
77 const newChildren = getChildren();
78 expect(newChildren).toEqual([div(span(), span())]);
79
@@ -100,12 +102,12 @@ describe('ReactPersistent', () => {
102 }
103
104 render(<Foo text="Hello" />);
103 - expect(ReactNoopPersistent).toFlushWithoutYielding();
105 + expect(Scheduler).toFlushWithoutYielding();
106 const originalChildren = getChildren();
107 expect(originalChildren).toEqual([div(span('Hello'))]);
108
109 render(<Foo text="World" />);
108 - expect(ReactNoopPersistent).toFlushWithoutYielding();
110 + expect(Scheduler).toFlushWithoutYielding();
111 const newChildren = getChildren();
112 expect(newChildren).toEqual([div(span('Hello'), span('World'))]);
113
@@ -126,12 +128,12 @@ describe('ReactPersistent', () => {
128 }
129
130 render(<Foo text="Hello" />);
129 - expect(ReactNoopPersistent).toFlushWithoutYielding();
131 + expect(Scheduler).toFlushWithoutYielding();
132 const originalChildren = getChildren();
133 expect(originalChildren).toEqual([div('Hello', span())]);
134
135 render(<Foo text="World" />);
134 - expect(ReactNoopPersistent).toFlushWithoutYielding();
136 + expect(Scheduler).toFlushWithoutYielding();
137 const newChildren = getChildren();
138 expect(newChildren).toEqual([div('World', span())]);
139
@@ -167,7 +169,7 @@ describe('ReactPersistent', () => {
169 const portalContainer = {rootID: 'persistent-portal-test', children: []};
170 const emptyPortalChildSet = portalContainer.children;
171 render(<Parent>{createPortal(<Child />, portalContainer, null)}</Parent>);
170 - expect(ReactNoopPersistent).toFlushWithoutYielding();
172 + expect(Scheduler).toFlushWithoutYielding();
173
174 expect(emptyPortalChildSet).toEqual([]);
175
@@ -181,7 +183,7 @@ describe('ReactPersistent', () => {
183 {createPortal(<Child>Hello {'World'}</Child>, portalContainer, null)}
184 </Parent>,
185 );
184 - expect(ReactNoopPersistent).toFlushWithoutYielding();
186 + expect(Scheduler).toFlushWithoutYielding();
187
188 const newChildren = getChildren();
189 expect(newChildren).toEqual([div()]);
@@ -198,7 +200,7 @@ describe('ReactPersistent', () => {
200
201 // Deleting the Portal, should clear its children
202 render(<Parent />);
201 - expect(ReactNoopPersistent).toFlushWithoutYielding();
203 + expect(Scheduler).toFlushWithoutYielding();
204
205 const clearedPortalChildren = portalContainer.children;
206 expect(clearedPortalChildren).toEqual([]);
packages/react-reconciler/src/__tests__/ReactSuspense-test.internal.js
+69 -81
@@ -111,7 +111,7 @@ describe('ReactSuspense', () => {
111 unstable_isConcurrent: true,
112 });
113
114 - expect(root).toFlushAndYield([
114 + expect(Scheduler).toFlushAndYield([
115 'Foo',
116 'Bar',
117 // A suspends
@@ -125,14 +125,14 @@ describe('ReactSuspense', () => {
125 // Flush some of the time
126 jest.advanceTimersByTime(50);
127 // Still nothing...
128 - expect(root).toFlushWithoutYielding();
128 + expect(Scheduler).toFlushWithoutYielding();
129 expect(root).toMatchRenderedOutput(null);
130
131 // Flush the promise completely
132 jest.advanceTimersByTime(50);
133 // Renders successfully
134 - expect(ReactTestRenderer).toHaveYielded(['Promise resolved [A]']);
135 - expect(root).toFlushAndYield(['Foo', 'Bar', 'A', 'B']);
134 + expect(Scheduler).toHaveYielded(['Promise resolved [A]']);
135 + expect(Scheduler).toFlushAndYield(['Foo', 'Bar', 'A', 'B']);
136 expect(root).toMatchRenderedOutput('AB');
137 });
138
@@ -152,7 +152,7 @@ describe('ReactSuspense', () => {
152 },
153 );
154
155 - expect(root).toFlushAndYield([
155 + expect(Scheduler).toFlushAndYield([
156 'Suspend! [A]',
157 'Loading A...',
158 'Suspend! [B]',
@@ -162,7 +162,7 @@ describe('ReactSuspense', () => {
162
163 // Advance time by enough to timeout both components and commit their placeholders
164 jest.advanceTimersByTime(4000);
165 - expect(root).toFlushWithoutYielding();
165 + expect(Scheduler).toFlushWithoutYielding();
166 expect(root).toMatchRenderedOutput('Loading A...Loading B...');
167
168 // Advance time by enough that the first Suspense's promise resolves and
@@ -170,15 +170,15 @@ describe('ReactSuspense', () => {
170 // show the placeholder
171 jest.advanceTimersByTime(1000);
172 // TODO: Should we throw if you forget to call toHaveYielded?
173 - expect(ReactTestRenderer).toHaveYielded(['Promise resolved [A]']);
174 - expect(root).toFlushAndYield(['A']);
173 + expect(Scheduler).toHaveYielded(['Promise resolved [A]']);
174 + expect(Scheduler).toFlushAndYield(['A']);
175 expect(root).toMatchRenderedOutput('ALoading B...');
176
177 // Advance time by enough that the second Suspense's promise resolves
178 // and switches back to the normal view
179 jest.advanceTimersByTime(1000);
180 - expect(ReactTestRenderer).toHaveYielded(['Promise resolved [B]']);
181 - expect(root).toFlushAndYield(['B']);
180 + expect(Scheduler).toHaveYielded(['Promise resolved [B]']);
181 + expect(Scheduler).toFlushAndYield(['B']);
182 expect(root).toMatchRenderedOutput('AB');
183 });
184
@@ -220,14 +220,14 @@ describe('ReactSuspense', () => {
220 },
221 );
222
223 - expect(root).toFlushAndYieldThrough(['Suspend!']);
223 + expect(Scheduler).toFlushAndYieldThrough(['Suspend!']);
224
225 // The promise resolves before the current render phase has completed
226 resolveThenable();
227 - expect(ReactTestRenderer).toHaveYielded([]);
227 + expect(Scheduler).toHaveYielded([]);
228
229 // Start over from the root, instead of continuing.
230 - expect(root).toFlushAndYield([
230 + expect(Scheduler).toFlushAndYield([
231 // Async renders again *before* Sibling
232 'Async',
233 'Sibling',
@@ -260,12 +260,12 @@ describe('ReactSuspense', () => {
260 </Suspense>,
261 );
262
263 - expect(ReactTestRenderer).toHaveYielded(['Loading...']);
263 + expect(Scheduler).toHaveYielded(['Loading...']);
264 expect(root).toMatchRenderedOutput('Loading...');
265
266 await LazyClass;
267
268 - expect(ReactTestRenderer).toHaveYielded(['Hi', 'Did mount: Hi']);
268 + expect(Scheduler).toHaveYielded(['Hi', 'Did mount: Hi']);
269 expect(root).toMatchRenderedOutput('Hi');
270 });
271
@@ -281,20 +281,20 @@ describe('ReactSuspense', () => {
281 },
282 );
283
284 - expect(root).toFlushAndYield([
284 + expect(Scheduler).toFlushAndYield([
285 'Suspend! [Hi]',
286 // The outer fallback should be rendered, because the inner one does not
287 // have a `fallback` prop
288 'Loading...',
289 ]);
290 jest.advanceTimersByTime(1000);
291 - expect(ReactTestRenderer).toHaveYielded([]);
292 - expect(root).toFlushAndYield([]);
291 + expect(Scheduler).toHaveYielded([]);
292 + expect(Scheduler).toFlushAndYield([]);
293 expect(root).toMatchRenderedOutput('Loading...');
294
295 jest.advanceTimersByTime(5000);
296 - expect(ReactTestRenderer).toHaveYielded(['Promise resolved [Hi]']);
297 - expect(root).toFlushAndYield(['Hi']);
296 + expect(Scheduler).toHaveYielded(['Promise resolved [Hi]']);
297 + expect(Scheduler).toFlushAndYield(['Hi']);
298 expect(root).toMatchRenderedOutput('Hi');
299 });
300
@@ -380,7 +380,7 @@ describe('ReactSuspense', () => {
380
381 const root = ReactTestRenderer.create(<App />);
382
383 - expect(ReactTestRenderer).toHaveYielded([
383 + expect(Scheduler).toHaveYielded([
384 'A',
385 'Suspend! [B:1]',
386 'C',
@@ -395,7 +395,7 @@ describe('ReactSuspense', () => {
395 expect(root).toMatchRenderedOutput('Loading...');
396
397 jest.advanceTimersByTime(100);
398 - expect(ReactTestRenderer).toHaveYielded([
398 + expect(Scheduler).toHaveYielded([
399 'Promise resolved [B:1]',
400 'B:1',
401 'Unmount [Loading...]',
@@ -406,7 +406,7 @@ describe('ReactSuspense', () => {
406 expect(root).toMatchRenderedOutput('AB:1C');
407
408 instance.setState({step: 2});
409 - expect(ReactTestRenderer).toHaveYielded([
409 + expect(Scheduler).toHaveYielded([
410 'Suspend! [B:2]',
411 'Loading...',
412 'Mount [Loading...]',
@@ -415,7 +415,7 @@ describe('ReactSuspense', () => {
415
416 jest.advanceTimersByTime(100);
417
418 - expect(ReactTestRenderer).toHaveYielded([
418 + expect(Scheduler).toHaveYielded([
419 'Promise resolved [B:2]',
420 'B:2',
421 'Unmount [Loading...]',
@@ -445,18 +445,18 @@ describe('ReactSuspense', () => {
445
446 const root = ReactTestRenderer.create(<App text="A" />);
447
448 - expect(ReactTestRenderer).toHaveYielded([
448 + expect(Scheduler).toHaveYielded([
449 'Stateful: 1',
450 'Suspend! [A]',
451 'Loading...',
452 ]);
453
454 jest.advanceTimersByTime(1000);
455 - expect(ReactTestRenderer).toHaveYielded(['Promise resolved [A]', 'A']);
455 + expect(Scheduler).toHaveYielded(['Promise resolved [A]', 'A']);
456 expect(root).toMatchRenderedOutput('Stateful: 1A');
457
458 root.update(<App text="B" />);
459 - expect(ReactTestRenderer).toHaveYielded([
459 + expect(Scheduler).toHaveYielded([
460 'Stateful: 1',
461 'Suspend! [B]',
462 'Loading...',
@@ -464,11 +464,11 @@ describe('ReactSuspense', () => {
464 expect(root).toMatchRenderedOutput('Loading...');
465
466 instance.setState({step: 2});
467 - expect(ReactTestRenderer).toHaveYielded(['Stateful: 2', 'Suspend! [B]']);
467 + expect(Scheduler).toHaveYielded(['Stateful: 2', 'Suspend! [B]']);
468 expect(root).toMatchRenderedOutput('Loading...');
469
470 jest.advanceTimersByTime(1000);
471 - expect(ReactTestRenderer).toHaveYielded(['Promise resolved [B]', 'B']);
471 + expect(Scheduler).toHaveYielded(['Promise resolved [B]', 'B']);
472 expect(root).toMatchRenderedOutput('Stateful: 2B');
473 });
474
@@ -501,18 +501,18 @@ describe('ReactSuspense', () => {
501
502 const root = ReactTestRenderer.create(<App text="A" />);
503
504 - expect(ReactTestRenderer).toHaveYielded([
504 + expect(Scheduler).toHaveYielded([
505 'Stateful: 1',
506 'Suspend! [A]',
507 'Loading...',
508 ]);
509
510 jest.advanceTimersByTime(1000);
511 - expect(ReactTestRenderer).toHaveYielded(['Promise resolved [A]', 'A']);
511 + expect(Scheduler).toHaveYielded(['Promise resolved [A]', 'A']);
512 expect(root).toMatchRenderedOutput('Stateful: 1A');
513
514 root.update(<App text="B" />);
515 - expect(ReactTestRenderer).toHaveYielded([
515 + expect(Scheduler).toHaveYielded([
516 'Stateful: 1',
517 'Suspend! [B]',
518 'Loading...',
@@ -520,7 +520,7 @@ describe('ReactSuspense', () => {
520 expect(root).toMatchRenderedOutput('Loading...');
521
522 instance.setState({step: 2});
523 - expect(ReactTestRenderer).toHaveYielded([
523 + expect(Scheduler).toHaveYielded([
524 'Stateful: 2',
525
526 // The suspended component should suspend again. If it doesn't, the
@@ -531,7 +531,7 @@ describe('ReactSuspense', () => {
531 expect(root).toMatchRenderedOutput('Loading...');
532
533 jest.advanceTimersByTime(1000);
534 - expect(ReactTestRenderer).toHaveYielded(['Promise resolved [B]', 'B']);
534 + expect(Scheduler).toHaveYielded(['Promise resolved [B]', 'B']);
535 expect(root).toMatchRenderedOutput('Stateful: 2B');
536 });
537
@@ -567,10 +567,10 @@ describe('ReactSuspense', () => {
567 }
568
569 const root = ReactTestRenderer.create(<App text="A" />);
570 - expect(ReactTestRenderer).toHaveYielded(['Suspend! [A]', 'Loading...']);
570 + expect(Scheduler).toHaveYielded(['Suspend! [A]', 'Loading...']);
571 root.update(<Text text="B" />);
572 // Should not fire componentWillUnmount
573 - expect(ReactTestRenderer).toHaveYielded(['B']);
573 + expect(Scheduler).toHaveYielded(['B']);
574 expect(root).toMatchRenderedOutput('B');
575 });
576
@@ -610,9 +610,9 @@ describe('ReactSuspense', () => {
610 }
611
612 ReactTestRenderer.create(<App text="A" />);
613 - expect(ReactTestRenderer).toHaveYielded(['Suspend! [A]', 'Loading...']);
613 + expect(Scheduler).toHaveYielded(['Suspend! [A]', 'Loading...']);
614 jest.advanceTimersByTime(500);
615 - expect(ReactTestRenderer).toHaveYielded([
615 + expect(Scheduler).toHaveYielded([
616 'Promise resolved [A]',
617 'A',
618 'Did commit: A',
@@ -642,29 +642,29 @@ describe('ReactSuspense', () => {
642 });
643
644 // Initial render
645 - expect(root).toFlushAndYield(['Suspend! [Step: 1]', 'Loading...']);
645 + expect(Scheduler).toFlushAndYield(['Suspend! [Step: 1]', 'Loading...']);
646 jest.advanceTimersByTime(1000);
647 - expect(ReactTestRenderer).toHaveYielded(['Promise resolved [Step: 1]']);
648 - expect(root).toFlushAndYield(['Step: 1']);
647 + expect(Scheduler).toHaveYielded(['Promise resolved [Step: 1]']);
648 + expect(Scheduler).toFlushAndYield(['Step: 1']);
649 expect(root).toMatchRenderedOutput('Step: 1');
650
651 // Update that suspends
652 instance.setState({step: 2});
653 - expect(root).toFlushAndYield(['Suspend! [Step: 2]', 'Loading...']);
653 + expect(Scheduler).toFlushAndYield(['Suspend! [Step: 2]', 'Loading...']);
654 jest.advanceTimersByTime(500);
655 expect(root).toMatchRenderedOutput('Loading...');
656
657 // Update while still suspended
658 instance.setState({step: 3});
659 - expect(root).toFlushAndYield(['Suspend! [Step: 3]']);
659 + expect(Scheduler).toFlushAndYield(['Suspend! [Step: 3]']);
660 expect(root).toMatchRenderedOutput('Loading...');
661
662 jest.advanceTimersByTime(1000);
663 - expect(ReactTestRenderer).toHaveYielded([
663 + expect(Scheduler).toHaveYielded([
664 'Promise resolved [Step: 2]',
665 'Promise resolved [Step: 3]',
666 ]);
667 - expect(root).toFlushAndYield(['Step: 3']);
667 + expect(Scheduler).toFlushAndYield(['Step: 3']);
668 expect(root).toMatchRenderedOutput('Step: 3');
669 });
670
@@ -692,28 +692,28 @@ describe('ReactSuspense', () => {
692 const root = ReactTestRenderer.create(<App />);
693
694 // Initial render
695 - expect(ReactTestRenderer).toHaveYielded([
695 + expect(Scheduler).toHaveYielded([
696 'Suspend! [Child 1]',
697 'Suspend! [Child 2]',
698 'Suspend! [Child 3]',
699 'Loading...',
700 ]);
701 - expect(root).toFlushAndYield([]);
701 + expect(Scheduler).toFlushAndYield([]);
702 jest.advanceTimersByTime(1000);
703 - expect(ReactTestRenderer).toHaveYielded([
703 + expect(Scheduler).toHaveYielded([
704 'Promise resolved [Child 1]',
705 'Child 1',
706 'Suspend! [Child 2]',
707 'Suspend! [Child 3]',
708 ]);
709 jest.advanceTimersByTime(1000);
710 - expect(ReactTestRenderer).toHaveYielded([
710 + expect(Scheduler).toHaveYielded([
711 'Promise resolved [Child 2]',
712 'Child 2',
713 'Suspend! [Child 3]',
714 ]);
715 jest.advanceTimersByTime(1000);
716 - expect(ReactTestRenderer).toHaveYielded([
716 + expect(Scheduler).toHaveYielded([
717 'Promise resolved [Child 3]',
718 'Child 3',
719 ]);
@@ -737,17 +737,17 @@ describe('ReactSuspense', () => {
737 unstable_isConcurrent: true,
738 });
739
740 - expect(root).toFlushAndYield([
740 + expect(Scheduler).toFlushAndYield([
741 'Suspend! [Child 1]',
742 'Suspend! [Child 2]',
743 'Loading...',
744 ]);
745 jest.advanceTimersByTime(1000);
746 - expect(ReactTestRenderer).toHaveYielded(['Promise resolved [Child 1]']);
747 - expect(root).toFlushAndYield(['Child 1', 'Suspend! [Child 2]']);
746 + expect(Scheduler).toHaveYielded(['Promise resolved [Child 1]']);
747 + expect(Scheduler).toFlushAndYield(['Child 1', 'Suspend! [Child 2]']);
748 jest.advanceTimersByTime(6000);
749 - expect(ReactTestRenderer).toHaveYielded(['Promise resolved [Child 2]']);
750 - expect(root).toFlushAndYield(['Child 1', 'Child 2']);
749 + expect(Scheduler).toHaveYielded(['Promise resolved [Child 2]']);
750 + expect(Scheduler).toFlushAndYield(['Child 1', 'Child 2']);
751 expect(root).toMatchRenderedOutput(['Child 1', 'Child 2'].join(''));
752 });
753
@@ -768,45 +768,36 @@ describe('ReactSuspense', () => {
768 }
769
770 const root = ReactTestRenderer.create(<App />);
771 - expect(ReactTestRenderer).toHaveYielded([
771 + expect(Scheduler).toHaveYielded([
772 'Suspend! [Tab: 0]',
773 ' + sibling',
774 'Loading...',
775 ]);
776 expect(root).toMatchRenderedOutput('Loading...');
777 jest.advanceTimersByTime(1000);
778 - expect(ReactTestRenderer).toHaveYielded([
779 - 'Promise resolved [Tab: 0]',
780 - 'Tab: 0',
781 - ]);
778 + expect(Scheduler).toHaveYielded(['Promise resolved [Tab: 0]', 'Tab: 0']);
779 expect(root).toMatchRenderedOutput('Tab: 0 + sibling');
780
781 act(() => setTab(1));
785 - expect(ReactTestRenderer).toHaveYielded([
782 + expect(Scheduler).toHaveYielded([
783 'Suspend! [Tab: 1]',
784 ' + sibling',
785 'Loading...',
786 ]);
787 expect(root).toMatchRenderedOutput('Loading...');
788 jest.advanceTimersByTime(1000);
792 - expect(ReactTestRenderer).toHaveYielded([
793 - 'Promise resolved [Tab: 1]',
794 - 'Tab: 1',
795 - ]);
789 + expect(Scheduler).toHaveYielded(['Promise resolved [Tab: 1]', 'Tab: 1']);
790 expect(root).toMatchRenderedOutput('Tab: 1 + sibling');
791
792 act(() => setTab(2));
799 - expect(ReactTestRenderer).toHaveYielded([
793 + expect(Scheduler).toHaveYielded([
794 'Suspend! [Tab: 2]',
795 ' + sibling',
796 'Loading...',
797 ]);
798 expect(root).toMatchRenderedOutput('Loading...');
799 jest.advanceTimersByTime(1000);
806 - expect(ReactTestRenderer).toHaveYielded([
807 - 'Promise resolved [Tab: 2]',
808 - 'Tab: 2',
809 - ]);
800 + expect(Scheduler).toHaveYielded(['Promise resolved [Tab: 2]', 'Tab: 2']);
801 expect(root).toMatchRenderedOutput('Tab: 2 + sibling');
802 });
803
@@ -840,20 +831,17 @@ describe('ReactSuspense', () => {
831 </Suspense>,
832 );
833
843 - expect(ReactTestRenderer).toHaveYielded(['Suspend! [A:0]', 'Loading...']);
834 + expect(Scheduler).toHaveYielded(['Suspend! [A:0]', 'Loading...']);
835 jest.advanceTimersByTime(1000);
845 - expect(ReactTestRenderer).toHaveYielded([
846 - 'Promise resolved [A:0]',
847 - 'A:0',
848 - ]);
836 + expect(Scheduler).toHaveYielded(['Promise resolved [A:0]', 'A:0']);
837 expect(root).toMatchRenderedOutput('A:0');
838
839 act(() => setStep(1));
852 - expect(ReactTestRenderer).toHaveYielded(['Suspend! [A:1]', 'Loading...']);
840 + expect(Scheduler).toHaveYielded(['Suspend! [A:1]', 'Loading...']);
841 expect(root).toMatchRenderedOutput('Loading...');
842
843 root.update(null);
856 - expect(root).toFlushWithoutYielding();
844 + expect(Scheduler).toFlushWithoutYielding();
845 jest.advanceTimersByTime(1000);
846 });
847
@@ -872,7 +860,7 @@ describe('ReactSuspense', () => {
860
861 root.update(<App />);
862
875 - expect(ReactTestRenderer).toHaveYielded([
863 + expect(Scheduler).toHaveYielded([
864 'Suspend! [A]',
865 'Suspend! [B]',
866 'Suspend! [C]',
@@ -882,7 +870,7 @@ describe('ReactSuspense', () => {
870 // Resolve A
871 jest.advanceTimersByTime(1000);
872
885 - expect(ReactTestRenderer).toHaveYielded([
873 + expect(Scheduler).toHaveYielded([
874 'Promise resolved [A]',
875 'A',
876 // The promises for B and C have now been thrown twice
@@ -893,7 +881,7 @@ describe('ReactSuspense', () => {
881 // Resolve B
882 jest.advanceTimersByTime(1000);
883
896 - expect(ReactTestRenderer).toHaveYielded([
884 + expect(Scheduler).toHaveYielded([
885 'Promise resolved [B]',
886 // Even though the promise for B was thrown twice, we should only
887 // re-render once.
@@ -904,7 +892,7 @@ describe('ReactSuspense', () => {
892
893 // Resolve C
894 jest.advanceTimersByTime(1000);
907 - expect(ReactTestRenderer).toHaveYielded([
895 + expect(Scheduler).toHaveYielded([
896 'Promise resolved [C]',
897 // Even though the promise for C was thrown three times, we should only
898 // re-render once.
packages/react-reconciler/src/__tests__/ReactSuspensePlaceholder-test.internal.js
+41 -25
@@ -138,13 +138,18 @@ function runPlaceholderTests(suiteLabel, loadReactNoop) {
138 unstable_isConcurrent: true,
139 });
140
141 - expect(root).toFlushAndYield(['A', 'Suspend! [B]', 'C', 'Loading...']);
141 + expect(Scheduler).toFlushAndYield([
142 + 'A',
143 + 'Suspend! [B]',
144 + 'C',
145 + 'Loading...',
146 + ]);
147 expect(root).toMatchRenderedOutput(null);
148
149 jest.advanceTimersByTime(1000);
145 - expect(ReactTestRenderer).toHaveYielded(['Promise resolved [B]']);
150 + expect(Scheduler).toHaveYielded(['Promise resolved [B]']);
151
147 - expect(root).toFlushAndYield(['A', 'B', 'C']);
152 + expect(Scheduler).toFlushAndYield(['A', 'B', 'C']);
153
154 expect(root).toMatchRenderedOutput(
155 <React.Fragment>
@@ -156,17 +161,17 @@ function runPlaceholderTests(suiteLabel, loadReactNoop) {
161
162 // Update
163 root.update(<App middleText="B2" />);
159 - expect(root).toFlushAndYield(['Suspend! [B2]', 'C', 'Loading...']);
164 + expect(Scheduler).toFlushAndYield(['Suspend! [B2]', 'C', 'Loading...']);
165
166 // Time out the update
167 jest.advanceTimersByTime(750);
163 - expect(root).toFlushAndYield([]);
168 + expect(Scheduler).toFlushAndYield([]);
169 expect(root).toMatchRenderedOutput('Loading...');
170
171 // Resolve the promise
172 jest.advanceTimersByTime(1000);
168 - expect(ReactTestRenderer).toHaveYielded(['Promise resolved [B2]']);
169 - expect(root).toFlushAndYield(['B2', 'C']);
173 + expect(Scheduler).toHaveYielded(['Promise resolved [B2]']);
174 + expect(Scheduler).toFlushAndYield(['B2', 'C']);
175
176 // Render the final update. A should still be hidden, because it was
177 // given a `hidden` prop.
@@ -195,27 +200,37 @@ function runPlaceholderTests(suiteLabel, loadReactNoop) {
200 unstable_isConcurrent: true,
201 });
202
198 - expect(root).toFlushAndYield(['A', 'Suspend! [B]', 'C', 'Loading...']);
203 + expect(Scheduler).toFlushAndYield([
204 + 'A',
205 + 'Suspend! [B]',
206 + 'C',
207 + 'Loading...',
208 + ]);
209
210 expect(root).toMatchRenderedOutput(null);
211
212 jest.advanceTimersByTime(1000);
203 - expect(ReactTestRenderer).toHaveYielded(['Promise resolved [B]']);
204 - expect(root).toFlushAndYield(['A', 'B', 'C']);
213 + expect(Scheduler).toHaveYielded(['Promise resolved [B]']);
214 + expect(Scheduler).toFlushAndYield(['A', 'B', 'C']);
215 expect(root).toMatchRenderedOutput('ABC');
216
217 // Update
218 root.update(<App middleText="B2" />);
209 - expect(root).toFlushAndYield(['A', 'Suspend! [B2]', 'C', 'Loading...']);
219 + expect(Scheduler).toFlushAndYield([
220 + 'A',
221 + 'Suspend! [B2]',
222 + 'C',
223 + 'Loading...',
224 + ]);
225 // Time out the update
226 jest.advanceTimersByTime(750);
212 - expect(root).toFlushAndYield([]);
227 + expect(Scheduler).toFlushAndYield([]);
228 expect(root).toMatchRenderedOutput('Loading...');
229
230 // Resolve the promise
231 jest.advanceTimersByTime(1000);
217 - expect(ReactTestRenderer).toHaveYielded(['Promise resolved [B2]']);
218 - expect(root).toFlushAndYield(['A', 'B2', 'C']);
232 + expect(Scheduler).toHaveYielded(['Promise resolved [B2]']);
233 + expect(Scheduler).toFlushAndYield(['A', 'B2', 'C']);
234
235 // Render the final update. A should still be hidden, because it was
236 // given a `hidden` prop.
@@ -284,7 +299,7 @@ function runPlaceholderTests(suiteLabel, loadReactNoop) {
299 unstable_isConcurrent: true,
300 });
301
287 - expect(root).toFlushAndYield([
302 + expect(Scheduler).toFlushAndYield([
303 'App',
304 'Suspending',
305 'Suspend! [Loaded]',
@@ -306,10 +321,8 @@ function runPlaceholderTests(suiteLabel, loadReactNoop) {
321
322 // Resolve the pending promise.
323 jest.advanceTimersByTime(250);
309 - expect(ReactTestRenderer).toHaveYielded([
310 - 'Promise resolved [Loaded]',
311 - ]);
312 - expect(root).toFlushAndYield(['Suspending', 'Loaded', 'Text']);
324 + expect(Scheduler).toHaveYielded(['Promise resolved [Loaded]']);
325 + expect(Scheduler).toFlushAndYield(['Suspending', 'Loaded', 'Text']);
326 expect(root).toMatchRenderedOutput('LoadedText');
327 expect(onRender).toHaveBeenCalledTimes(2);
328
@@ -375,7 +388,7 @@ function runPlaceholderTests(suiteLabel, loadReactNoop) {
388 },
389 );
390
378 - expect(root).toFlushAndYield(['App', 'Text']);
391 + expect(Scheduler).toFlushAndYield(['App', 'Text']);
392 expect(root).toMatchRenderedOutput('Text');
393 expect(onRender).toHaveBeenCalledTimes(1);
394
@@ -385,7 +398,7 @@ function runPlaceholderTests(suiteLabel, loadReactNoop) {
398 expect(onRender.mock.calls[0][3]).toBe(5);
399
400 root.update(<App shouldSuspend={true} textRenderDuration={5} />);
388 - expect(root).toFlushAndYield([
401 + expect(Scheduler).toFlushAndYield([
402 'App',
403 'Suspending',
404 'Suspend! [Loaded]',
@@ -411,7 +424,7 @@ function runPlaceholderTests(suiteLabel, loadReactNoop) {
424 root.update(
425 <App shouldSuspend={true} text="New" textRenderDuration={6} />,
426 );
414 - expect(root).toFlushAndYield([
427 + expect(Scheduler).toFlushAndYield([
428 'App',
429 'Suspending',
430 'Suspend! [Loaded]',
@@ -423,10 +436,13 @@ function runPlaceholderTests(suiteLabel, loadReactNoop) {
436
437 // Resolve the pending promise.
438 jest.advanceTimersByTime(250);
426 - expect(ReactTestRenderer).toHaveYielded([
427 - 'Promise resolved [Loaded]',
439 + expect(Scheduler).toHaveYielded(['Promise resolved [Loaded]']);
440 + expect(Scheduler).toFlushAndYield([
441 + 'App',
442 + 'Suspending',
443 + 'Loaded',
444 + 'New',
445 ]);
429 - expect(root).toFlushAndYield(['App', 'Suspending', 'Loaded', 'New']);
446 expect(onRender).toHaveBeenCalledTimes(3);
447
448 // When the suspending data is resolved and our final UI is rendered,
packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.internal.js
+90 -90
@@ -108,7 +108,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
108 }
109
110 ReactNoop.render(<Foo />);
111 - expect(ReactNoop).toFlushAndYield([
111 + expect(Scheduler).toFlushAndYield([
112 'Foo',
113 'Bar',
114 // A suspends
@@ -122,14 +122,14 @@ describe('ReactSuspenseWithNoopRenderer', () => {
122 // Flush some of the time
123 await advanceTimers(50);
124 // Still nothing...
125 - expect(ReactNoop).toFlushWithoutYielding();
125 + expect(Scheduler).toFlushWithoutYielding();
126 expect(ReactNoop.getChildren()).toEqual([]);
127
128 // Flush the promise completely
129 await advanceTimers(50);
130 // Renders successfully
131 - expect(ReactNoop).toHaveYielded(['Promise resolved [A]']);
132 - expect(ReactNoop).toFlushAndYield(['Foo', 'Bar', 'A', 'B']);
131 + expect(Scheduler).toHaveYielded(['Promise resolved [A]']);
132 + expect(Scheduler).toFlushAndYield(['Foo', 'Bar', 'A', 'B']);
133 expect(ReactNoop.getChildren()).toEqual([span('A'), span('B')]);
134 });
135
@@ -145,7 +145,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
145 </Suspense>
146 </Fragment>,
147 );
148 - expect(ReactNoop).toFlushAndYield([
148 + expect(Scheduler).toFlushAndYield([
149 'Suspend! [A]',
150 'Loading A...',
151 'Suspend! [B]',
@@ -157,7 +157,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
157 ReactNoop.expire(4000);
158 await advanceTimers(4000);
159
160 - expect(ReactNoop).toFlushWithoutYielding();
160 + expect(Scheduler).toFlushWithoutYielding();
161 expect(ReactNoop.getChildren()).toEqual([
162 span('Loading A...'),
163 span('Loading B...'),
@@ -169,8 +169,8 @@ describe('ReactSuspenseWithNoopRenderer', () => {
169 ReactNoop.expire(1000);
170 await advanceTimers(1000);
171
172 - expect(ReactNoop).toHaveYielded(['Promise resolved [A]']);
173 - expect(ReactNoop).toFlushAndYield(['A']);
172 + expect(Scheduler).toHaveYielded(['Promise resolved [A]']);
173 + expect(Scheduler).toFlushAndYield(['A']);
174 expect(ReactNoop.getChildren()).toEqual([span('A'), span('Loading B...')]);
175
176 // Advance time by enough that the second Suspense's promise resolves
@@ -178,8 +178,8 @@ describe('ReactSuspenseWithNoopRenderer', () => {
178 ReactNoop.expire(1000);
179 await advanceTimers(1000);
180
181 - expect(ReactNoop).toHaveYielded(['Promise resolved [B]']);
182 - expect(ReactNoop).toFlushAndYield(['B']);
181 + expect(Scheduler).toHaveYielded(['Promise resolved [B]']);
182 + expect(Scheduler).toFlushAndYield(['B']);
183 expect(ReactNoop.getChildren()).toEqual([span('A'), span('B')]);
184 });
185
@@ -193,7 +193,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
193 </Suspense>,
194 );
195 // B suspends. Continue rendering the remaining siblings.
196 - expect(ReactNoop).toFlushAndYield([
196 + expect(Scheduler).toFlushAndYield([
197 'A',
198 'Suspend! [B]',
199 'C',
@@ -206,8 +206,8 @@ describe('ReactSuspenseWithNoopRenderer', () => {
206 // Wait for data to resolve
207 await advanceTimers(100);
208 // Renders successfully
209 - expect(ReactNoop).toHaveYielded(['Promise resolved [B]']);
210 - expect(ReactNoop).toFlushAndYield(['A', 'B', 'C', 'D']);
209 + expect(Scheduler).toHaveYielded(['Promise resolved [B]']);
210 + expect(Scheduler).toFlushAndYield(['A', 'B', 'C', 'D']);
211 expect(ReactNoop.getChildren()).toEqual([
212 span('A'),
213 span('B'),
@@ -245,7 +245,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
245 }
246
247 ReactNoop.render(<App />);
248 - expect(ReactNoop).toFlushAndYield(['Suspend! [Result]', 'Loading...']);
248 + expect(Scheduler).toFlushAndYield(['Suspend! [Result]', 'Loading...']);
249 expect(ReactNoop.getChildren()).toEqual([]);
250
251 textResourceShouldFail = true;
@@ -253,9 +253,9 @@ describe('ReactSuspenseWithNoopRenderer', () => {
253 await advanceTimers(1000);
254 textResourceShouldFail = false;
255
256 - expect(ReactNoop).toHaveYielded(['Promise rejected [Result]']);
256 + expect(Scheduler).toHaveYielded(['Promise rejected [Result]']);
257
258 - expect(ReactNoop).toFlushAndYield([
258 + expect(Scheduler).toFlushAndYield([
259 'Error! [Result]',
260
261 // React retries one more time
@@ -298,12 +298,12 @@ describe('ReactSuspenseWithNoopRenderer', () => {
298 }
299
300 ReactNoop.render(<App />);
301 - expect(ReactNoop).toFlushAndYield(['Suspend! [Result]', 'Loading...']);
301 + expect(Scheduler).toFlushAndYield(['Suspend! [Result]', 'Loading...']);
302 expect(ReactNoop.getChildren()).toEqual([]);
303
304 ReactNoop.expire(2000);
305 await advanceTimers(2000);
306 - expect(ReactNoop).toFlushWithoutYielding();
306 + expect(Scheduler).toFlushWithoutYielding();
307 expect(ReactNoop.getChildren()).toEqual([span('Loading...')]);
308
309 textResourceShouldFail = true;
@@ -311,8 +311,8 @@ describe('ReactSuspenseWithNoopRenderer', () => {
311 await advanceTimers(1000);
312 textResourceShouldFail = false;
313
314 - expect(ReactNoop).toHaveYielded(['Promise rejected [Result]']);
315 - expect(ReactNoop).toFlushAndYield([
314 + expect(Scheduler).toHaveYielded(['Promise rejected [Result]']);
315 + expect(Scheduler).toFlushAndYield([
316 'Error! [Result]',
317
318 // React retries one more time
@@ -339,15 +339,15 @@ describe('ReactSuspenseWithNoopRenderer', () => {
339
340 // Initial mount
341 ReactNoop.render(<App highPri="A" lowPri="1" />);
342 - expect(ReactNoop).toFlushAndYield(['A', 'Suspend! [1]', 'Loading...']);
342 + expect(Scheduler).toFlushAndYield(['A', 'Suspend! [1]', 'Loading...']);
343 await advanceTimers(0);
344 - expect(ReactNoop).toHaveYielded(['Promise resolved [1]']);
345 - expect(ReactNoop).toFlushAndYield(['A', '1']);
344 + expect(Scheduler).toHaveYielded(['Promise resolved [1]']);
345 + expect(Scheduler).toFlushAndYield(['A', '1']);
346 expect(ReactNoop.getChildren()).toEqual([span('A'), span('1')]);
347
348 // Update the low-pri text
349 ReactNoop.render(<App highPri="A" lowPri="2" />);
350 - expect(ReactNoop).toFlushAndYield([
350 + expect(Scheduler).toFlushAndYield([
351 'A',
352 // Suspends
353 'Suspend! [2]',
@@ -359,12 +359,12 @@ describe('ReactSuspenseWithNoopRenderer', () => {
359 ReactNoop.flushSync(() => {
360 ReactNoop.render(<App highPri="B" lowPri="1" />);
361 });
362 - expect(ReactNoop).toHaveYielded(['B', '1']);
362 + expect(Scheduler).toHaveYielded(['B', '1']);
363 expect(ReactNoop.getChildren()).toEqual([span('B'), span('1')]);
364
365 // Unblock the low-pri text and finish
366 await advanceTimers(0);
367 - expect(ReactNoop).toHaveYielded(['Promise resolved [2]']);
367 + expect(Scheduler).toHaveYielded(['Promise resolved [2]']);
368 expect(ReactNoop.getChildren()).toEqual([span('B'), span('1')]);
369 });
370
@@ -379,18 +379,18 @@ describe('ReactSuspenseWithNoopRenderer', () => {
379 }
380
381 ReactNoop.render(<App showB={false} />);
382 - expect(ReactNoop).toFlushAndYield(['Suspend! [A]', 'Loading...']);
382 + expect(Scheduler).toFlushAndYield(['Suspend! [A]', 'Loading...']);
383 expect(ReactNoop.getChildren()).toEqual([]);
384
385 // Advance React's virtual time by enough to fall into a new async bucket.
386 ReactNoop.expire(1200);
387 ReactNoop.render(<App showB={true} />);
388 - expect(ReactNoop).toFlushAndYield(['Suspend! [A]', 'B', 'Loading...']);
388 + expect(Scheduler).toFlushAndYield(['Suspend! [A]', 'B', 'Loading...']);
389 expect(ReactNoop.getChildren()).toEqual([]);
390
391 await advanceTimers(0);
392 - expect(ReactNoop).toHaveYielded(['Promise resolved [A]']);
393 - expect(ReactNoop).toFlushAndYield(['A', 'B']);
392 + expect(Scheduler).toHaveYielded(['Promise resolved [A]']);
393 + expect(Scheduler).toFlushAndYield(['A', 'B']);
394 expect(ReactNoop.getChildren()).toEqual([span('A'), span('B')]);
395 });
396
@@ -415,7 +415,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
415 // Low pri
416 ReactNoop.render(<App hide={true} />);
417
418 - expect(ReactNoop).toFlushAndYield([
418 + expect(Scheduler).toFlushAndYield([
419 // The first update suspends
420 'Suspend! [Async]',
421 // but we have another pending update that we can work on
@@ -434,7 +434,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
434 </Fragment>,
435 );
436
437 - expect(ReactNoop).toFlushAndYield([
437 + expect(Scheduler).toFlushAndYield([
438 // The async child suspends
439 'Suspend! [Async]',
440 // Render the placeholder
@@ -457,8 +457,8 @@ describe('ReactSuspenseWithNoopRenderer', () => {
457
458 // Once the promise resolves, we render the suspended view
459 await advanceTimers(10000);
460 - expect(ReactNoop).toHaveYielded(['Promise resolved [Async]']);
461 - expect(ReactNoop).toFlushAndYield(['Async']);
460 + expect(Scheduler).toHaveYielded(['Promise resolved [Async]']);
461 + expect(Scheduler).toFlushAndYield(['Async']);
462 expect(ReactNoop.getChildren()).toEqual([span('Async'), span('Sync')]);
463 });
464
@@ -479,7 +479,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
479 </Fragment>,
480 );
481
482 - expect(ReactNoop).toFlushAndYield([
482 + expect(Scheduler).toFlushAndYield([
483 'Sync',
484 // The async content suspends
485 'Suspend! [Outer content]',
@@ -494,7 +494,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
494 // We should see the outer loading placeholder.
495 ReactNoop.expire(1500);
496 await advanceTimers(1500);
497 - expect(ReactNoop).toFlushWithoutYielding();
497 + expect(Scheduler).toFlushWithoutYielding();
498 expect(ReactNoop.getChildren()).toEqual([
499 span('Sync'),
500 span('Loading outer...'),
@@ -507,8 +507,8 @@ describe('ReactSuspenseWithNoopRenderer', () => {
507 // timed out at 1.5 seconds. So, 2 seconds have elapsed since the
508 // placeholder timed out. That means we still haven't reached the 2.5 second
509 // threshold of the inner placeholder.
510 - expect(ReactNoop).toHaveYielded(['Promise resolved [Outer content]']);
511 - expect(ReactNoop).toFlushAndYield([
510 + expect(Scheduler).toHaveYielded(['Promise resolved [Outer content]']);
511 + expect(Scheduler).toFlushAndYield([
512 'Outer content',
513 'Suspend! [Inner content]',
514 'Loading inner...',
@@ -533,8 +533,8 @@ describe('ReactSuspenseWithNoopRenderer', () => {
533 // Finally, flush the inner promise. We should see the complete screen.
534 ReactNoop.expire(1000);
535 await advanceTimers(1000);
536 - expect(ReactNoop).toHaveYielded(['Promise resolved [Inner content]']);
537 - expect(ReactNoop).toFlushAndYield(['Inner content']);
536 + expect(Scheduler).toHaveYielded(['Promise resolved [Inner content]']);
537 + expect(Scheduler).toFlushAndYield(['Inner content']);
538 expect(ReactNoop.getChildren()).toEqual([
539 span('Sync'),
540 span('Outer content'),
@@ -554,7 +554,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
554 </Fragment>,
555 ),
556 );
557 - expect(ReactNoop).toHaveYielded([
557 + expect(Scheduler).toHaveYielded([
558 // The async child suspends
559 'Suspend! [Async]',
560 // We immediately render the fallback UI
@@ -567,8 +567,8 @@ describe('ReactSuspenseWithNoopRenderer', () => {
567
568 // Once the promise resolves, we render the suspended view
569 await advanceTimers(0);
570 - expect(ReactNoop).toHaveYielded(['Promise resolved [Async]']);
571 - expect(ReactNoop).toFlushAndYield(['Async']);
570 + expect(Scheduler).toHaveYielded(['Promise resolved [Async]']);
571 + expect(Scheduler).toFlushAndYield(['Async']);
572 expect(ReactNoop.getChildren()).toEqual([span('Async'), span('Sync')]);
573 });
574
@@ -585,7 +585,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
585 </Fragment>,
586 ),
587 );
588 - expect(ReactNoop).toHaveYielded([
588 + expect(Scheduler).toHaveYielded([
589 'Suspend! [Async]',
590 'Suspend! [Loading (inner)...]',
591 'Sync',
@@ -605,7 +605,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
605 </Fragment>,
606 );
607
608 - expect(ReactNoop).toFlushAndYield([
608 + expect(Scheduler).toFlushAndYield([
609 // The async child suspends
610 'Suspend! [Async]',
611 'Loading...',
@@ -620,13 +620,13 @@ describe('ReactSuspenseWithNoopRenderer', () => {
620 // expiration time.
621 ReactNoop.expire(2000);
622 await advanceTimers(2000);
623 - expect(ReactNoop).toFlushWithoutYielding();
623 + expect(Scheduler).toFlushWithoutYielding();
624 expect(ReactNoop.getChildren()).toEqual([span('Loading...'), span('Sync')]);
625
626 // Once the promise resolves, we render the suspended view
627 await advanceTimers(1000);
628 - expect(ReactNoop).toHaveYielded(['Promise resolved [Async]']);
629 - expect(ReactNoop).toFlushAndYield(['Async']);
628 + expect(Scheduler).toHaveYielded(['Promise resolved [Async]']);
629 + expect(Scheduler).toFlushAndYield(['Async']);
630 expect(ReactNoop.getChildren()).toEqual([span('Async'), span('Sync')]);
631 });
632
@@ -641,8 +641,8 @@ describe('ReactSuspenseWithNoopRenderer', () => {
641 expect(Scheduler).toHaveYielded([]);
642 // Before we have a chance to flush, the promise resolves.
643 await advanceTimers(2000);
644 - expect(ReactNoop).toHaveYielded(['Promise resolved [Async]']);
645 - expect(ReactNoop).toFlushAndYield(['Async']);
644 + expect(Scheduler).toHaveYielded(['Promise resolved [Async]']);
645 + expect(Scheduler).toFlushAndYield(['Async']);
646 expect(ReactNoop.getChildren()).toEqual([span('Async')]);
647 });
648
@@ -671,11 +671,11 @@ describe('ReactSuspenseWithNoopRenderer', () => {
671
672 await advanceTimers(100);
673
674 - expect(ReactNoop).toHaveYielded([
674 + expect(Scheduler).toHaveYielded([
675 'Promise resolved [A]',
676 'Promise resolved [B]',
677 ]);
678 - expect(ReactNoop).toFlushAndYield(['A', 'B']);
678 + expect(Scheduler).toFlushAndYield(['A', 'B']);
679 expect(ReactNoop.getChildren()).toEqual([span('A'), span('B')]);
680 });
681
@@ -685,7 +685,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
685 <AsyncText text="Async" ms={100} />
686 </Suspense>,
687 );
688 - expect(ReactNoop).toFlushAndYield(['Suspend! [Async]', 'Loading...']);
688 + expect(Scheduler).toFlushAndYield(['Suspend! [Async]', 'Loading...']);
689 expect(ReactNoop.getChildren()).toEqual([]);
690
691 // Advance time by an amount slightly smaller than what's necessary to
@@ -693,14 +693,14 @@ describe('ReactSuspenseWithNoopRenderer', () => {
693 await advanceTimers(99);
694
695 // Nothing has rendered yet
696 - expect(ReactNoop).toFlushWithoutYielding();
696 + expect(Scheduler).toFlushWithoutYielding();
697 expect(ReactNoop.getChildren()).toEqual([]);
698
699 // Resolve the promise
700 await advanceTimers(1);
701 // We can now resume rendering
702 - expect(ReactNoop).toHaveYielded(['Promise resolved [Async]']);
703 - expect(ReactNoop).toFlushAndYield(['Async']);
702 + expect(Scheduler).toHaveYielded(['Promise resolved [Async]']);
703 + expect(Scheduler).toFlushAndYield(['Async']);
704 expect(ReactNoop.getChildren()).toEqual([span('Async')]);
705 });
706
@@ -720,20 +720,20 @@ describe('ReactSuspenseWithNoopRenderer', () => {
720 // Schedule an update
721 ReactNoop.render(<App text="A" />);
722 // The update should suspend.
723 - expect(ReactNoop).toFlushAndYield(['Suspend! [A]', 'Loading...']);
723 + expect(Scheduler).toFlushAndYield(['Suspend! [A]', 'Loading...']);
724 expect(ReactNoop.getChildren()).toEqual([]);
725
726 // Advance time until right before it expires. This number may need to
727 // change if the default expiration for low priority updates is adjusted.
728 await advanceTimers(4999);
729 ReactNoop.expire(4999);
730 - expect(ReactNoop).toFlushWithoutYielding();
730 + expect(Scheduler).toFlushWithoutYielding();
731 expect(ReactNoop.getChildren()).toEqual([]);
732
733 // Schedule another low priority update.
734 ReactNoop.render(<App text="B" />);
735 // This update should also suspend.
736 - expect(ReactNoop).toFlushAndYield(['Suspend! [B]', 'Loading...']);
736 + expect(Scheduler).toFlushAndYield(['Suspend! [B]', 'Loading...']);
737 expect(ReactNoop.getChildren()).toEqual([]);
738
739 // Schedule a high priority update. Its expiration time will fall between
@@ -741,17 +741,17 @@ describe('ReactSuspenseWithNoopRenderer', () => {
741 ReactNoop.interactiveUpdates(() => {
742 ReactNoop.render(<App text="C" />);
743 });
744 - expect(ReactNoop).toFlushAndYield(['C']);
744 + expect(Scheduler).toFlushAndYield(['C']);
745 expect(ReactNoop.getChildren()).toEqual([span('C')]);
746
747 await advanceTimers(10000);
748 // Flush the remaining work.
749 - expect(ReactNoop).toHaveYielded([
749 + expect(Scheduler).toHaveYielded([
750 'Promise resolved [A]',
751 'Promise resolved [B]',
752 ]);
753 // Nothing else to render.
754 - expect(ReactNoop).toFlushWithoutYielding();
754 + expect(Scheduler).toFlushWithoutYielding();
755 expect(ReactNoop.getChildren()).toEqual([span('C')]);
756 });
757
@@ -786,7 +786,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
786 Scheduler.advanceTime(10000);
787 jest.advanceTimersByTime(10000);
788
789 - expect(ReactNoop).toHaveYielded([
789 + expect(Scheduler).toHaveYielded([
790 'Suspend! [goodbye]',
791 'Loading...',
792 'Commit: goodbye',
@@ -795,10 +795,10 @@ describe('ReactSuspenseWithNoopRenderer', () => {
795
796 Scheduler.advanceTime(20000);
797 await advanceTimers(20000);
798 - expect(ReactNoop).toHaveYielded(['Promise resolved [goodbye]']);
798 + expect(Scheduler).toHaveYielded(['Promise resolved [goodbye]']);
799 expect(ReactNoop.getChildren()).toEqual([span('Loading...')]);
800
801 - expect(ReactNoop).toFlushAndYield(['goodbye']);
801 + expect(Scheduler).toFlushAndYield(['goodbye']);
802 expect(ReactNoop.getChildren()).toEqual([span('goodbye')]);
803 });
804
@@ -831,17 +831,17 @@ describe('ReactSuspenseWithNoopRenderer', () => {
831
832 it('works', async () => {
833 ReactNoop.render(<DebouncedText text="A" ms={1000} />);
834 - expect(ReactNoop).toFlushAndYield(['A']);
834 + expect(Scheduler).toFlushAndYield(['A']);
835 expect(ReactNoop.getChildren()).toEqual([]);
836
837 await advanceTimers(800);
838 ReactNoop.expire(800);
839 - expect(ReactNoop).toFlushWithoutYielding();
839 + expect(Scheduler).toFlushWithoutYielding();
840 expect(ReactNoop.getChildren()).toEqual([]);
841
842 await advanceTimers(1000);
843 ReactNoop.expire(1000);
844 - expect(ReactNoop).toFlushWithoutYielding();
844 + expect(Scheduler).toFlushWithoutYielding();
845 expect(ReactNoop.getChildren()).toEqual([span('A')]);
846 });
847 });
@@ -858,12 +858,12 @@ describe('ReactSuspenseWithNoopRenderer', () => {
858
859 // Times out immediately, ignoring the specified threshold.
860 ReactNoop.renderLegacySyncRoot(<App />);
861 - expect(ReactNoop).toHaveYielded(['Suspend! [Result]', 'Loading...']);
861 + expect(Scheduler).toHaveYielded(['Suspend! [Result]', 'Loading...']);
862 expect(ReactNoop.getChildren()).toEqual([span('Loading...')]);
863
864 ReactNoop.expire(100);
865 await advanceTimers(100);
866 - expect(ReactNoop).toHaveYielded(['Promise resolved [Result]', 'Result']);
866 + expect(Scheduler).toHaveYielded(['Promise resolved [Result]', 'Result']);
867
868 expect(ReactNoop.getChildren()).toEqual([span('Result')]);
869 });
@@ -901,7 +901,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
901 // Initial mount. This is synchronous, because the root is sync.
902 ReactNoop.renderLegacySyncRoot(<App />);
903 await advanceTimers(100);
904 - expect(ReactNoop).toHaveYielded([
904 + expect(Scheduler).toHaveYielded([
905 'Suspend! [Step: 1]',
906 'Sibling',
907 'Loading (1)',
@@ -924,7 +924,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
924
925 // Suspend during an async render.
926 expect(ReactNoop.flushNextYield()).toEqual(['Suspend! [Step: 2]']);
927 - expect(ReactNoop).toFlushAndYield([
927 + expect(Scheduler).toFlushAndYield([
928 'Loading (1)',
929 'Loading (2)',
930 'Loading (3)',
@@ -941,7 +941,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
941 );
942
943 await advanceTimers(100);
944 - expect(ReactNoop).toHaveYielded([
944 + expect(Scheduler).toHaveYielded([
945 'Promise resolved [Step: 2]',
946 'Step: 2',
947 ]);
@@ -1004,7 +1004,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
1004 ReactNoop.yield('Did mount'),
1005 );
1006 await advanceTimers(100);
1007 - expect(ReactNoop).toHaveYielded([
1007 + expect(Scheduler).toHaveYielded([
1008 'Before',
1009 'Suspend! [Async: 1]',
1010 'After',
@@ -1037,14 +1037,14 @@ describe('ReactSuspenseWithNoopRenderer', () => {
1037 );
1038
1039 // Start rendering asynchronously
1040 - expect(ReactNoop).toFlushAndYieldThrough(['Before']);
1040 + expect(Scheduler).toFlushAndYieldThrough(['Before']);
1041
1042 // Now render the next child, which suspends
1043 expect(ReactNoop.flushNextYield()).toEqual([
1044 // This child suspends
1045 'Suspend! [Async: 2]',
1046 ]);
1047 - expect(ReactNoop).toFlushAndYield([
1047 + expect(Scheduler).toFlushAndYield([
1048 'After',
1049 'Loading...',
1050 'Before',
@@ -1069,7 +1069,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
1069 // When the placeholder is pinged, the boundary must be re-rendered
1070 // synchronously.
1071 await advanceTimers(100);
1072 - expect(ReactNoop).toHaveYielded([
1072 + expect(Scheduler).toHaveYielded([
1073 'Promise resolved [Async: 2]',
1074 'Async: 2',
1075 ]);
@@ -1139,7 +1139,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
1139 ReactNoop.yield('Did mount'),
1140 );
1141 await advanceTimers(100);
1142 - expect(ReactNoop).toHaveYielded([
1142 + expect(Scheduler).toHaveYielded([
1143 'Before',
1144 'Suspend! [Async: 1]',
1145 'After',
@@ -1172,14 +1172,14 @@ describe('ReactSuspenseWithNoopRenderer', () => {
1172 );
1173
1174 // Start rendering asynchronously
1175 - expect(ReactNoop).toFlushAndYieldThrough(['Before']);
1175 + expect(Scheduler).toFlushAndYieldThrough(['Before']);
1176
1177 // Now render the next child, which suspends
1178 expect(ReactNoop.flushNextYield()).toEqual([
1179 // This child suspends
1180 'Suspend! [Async: 2]',
1181 ]);
1182 - expect(ReactNoop).toFlushAndYield([
1182 + expect(Scheduler).toFlushAndYield([
1183 'After',
1184 'Loading...',
1185 'Before',
@@ -1204,7 +1204,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
1204 // When the placeholder is pinged, the boundary must be re-rendered
1205 // synchronously.
1206 await advanceTimers(100);
1207 - expect(ReactNoop).toHaveYielded([
1207 + expect(Scheduler).toHaveYielded([
1208 'Promise resolved [Async: 2]',
1209 'Async: 2',
1210 ]);
@@ -1263,7 +1263,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
1263 ReactNoop.renderLegacySyncRoot(<App />, () =>
1264 ReactNoop.yield('Commit root'),
1265 );
1266 - expect(ReactNoop).toHaveYielded([
1266 + expect(Scheduler).toHaveYielded([
1267 'A',
1268 'Suspend! [B]',
1269 'C',
@@ -1287,7 +1287,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
1287
1288 ReactNoop.expire(1000);
1289 await advanceTimers(1000);
1290 - expect(ReactNoop).toHaveYielded(['Promise resolved [B]', 'B']);
1290 + expect(Scheduler).toHaveYielded(['Promise resolved [B]', 'B']);
1291
1292 expect(ReactNoop).toMatchRenderedOutput(
1293 <React.Fragment>
@@ -1331,7 +1331,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
1331 </Suspense>,
1332 );
1333
1334 - expect(ReactNoop).toHaveYielded([
1334 + expect(Scheduler).toHaveYielded([
1335 'constructor',
1336 'Suspend! [Hi]',
1337 'Loading...',
@@ -1339,7 +1339,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
1339 expect(ReactNoop.getChildren()).toEqual([span('Loading...')]);
1340
1341 await advanceTimers(1000);
1342 - expect(ReactNoop).toHaveYielded([
1342 + expect(Scheduler).toHaveYielded([
1343 'Promise resolved [Hi]',
1344 'constructor',
1345 'Hi',
@@ -1375,7 +1375,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
1375
1376 ReactNoop.renderLegacySyncRoot(<Demo />);
1377
1378 - expect(ReactNoop).toHaveYielded([
1378 + expect(Scheduler).toHaveYielded([
1379 'Suspend! [Hi]',
1380 'Loading...',
1381 // Re-render due to lifecycle update
@@ -1383,7 +1383,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
1383 ]);
1384 expect(ReactNoop.getChildren()).toEqual([span('Loading...')]);
1385 await advanceTimers(100);
1386 - expect(ReactNoop).toHaveYielded(['Promise resolved [Hi]', 'Hi']);
1386 + expect(Scheduler).toHaveYielded(['Promise resolved [Hi]', 'Hi']);
1387 expect(ReactNoop.getChildren()).toEqual([span('Hi')]);
1388 });
1389
@@ -1414,7 +1414,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
1414
1415 ReactNoop.renderLegacySyncRoot(<App middleText="B" />);
1416
1417 - expect(ReactNoop).toHaveYielded([
1417 + expect(Scheduler).toHaveYielded([
1418 'Suspend! [Hi]',
1419 'Loading...',
1420 // The child should have already been hidden
@@ -1423,7 +1423,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
1423
1424 await advanceTimers(1000);
1425
1426 - expect(ReactNoop).toHaveYielded(['Promise resolved [Hi]', 'Hi']);
1426 + expect(Scheduler).toHaveYielded(['Promise resolved [Hi]', 'Hi']);
1427 });
1428 });
1429
@@ -1486,7 +1486,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
1486 ReactNoop.renderLegacySyncRoot(<App />, () =>
1487 ReactNoop.yield('Commit root'),
1488 );
1489 - expect(ReactNoop).toHaveYielded([
1489 + expect(Scheduler).toHaveYielded([
1490 'A',
1491 'Suspend! [B]',
1492 'C',
packages/react-reconciler/src/__tests__/ReactTopLevelFragment-test.js
+12 -10
@@ -12,6 +12,7 @@
12
13 let React;
14 let ReactNoop;
15 +let Scheduler;
16
17 // This is a new feature in Fiber so I put it in its own test file. It could
18 // probably move to one of the other test files once it is official.
@@ -20,6 +21,7 @@ describe('ReactTopLevelFragment', function() {
21 jest.resetModules();
22 React = require('react');
23 ReactNoop = require('react-noop-renderer');
24 + Scheduler = require('scheduler');
25 });
26
27 it('should render a simple fragment at the top of a component', function() {
@@ -27,7 +29,7 @@ describe('ReactTopLevelFragment', function() {
29 return [<div key="a">Hello</div>, <div key="b">World</div>];
30 }
31 ReactNoop.render(<Fragment />);
30 - expect(ReactNoop).toFlushWithoutYielding();
32 + expect(Scheduler).toFlushWithoutYielding();
33 });
34
35 it('should preserve state when switching from a single child', function() {
@@ -48,14 +50,14 @@ describe('ReactTopLevelFragment', function() {
50 );
51 }
52 ReactNoop.render(<Fragment />);
51 - expect(ReactNoop).toFlushWithoutYielding();
53 + expect(Scheduler).toFlushWithoutYielding();
54
55 const instanceA = instance;
56
57 expect(instanceA).not.toBe(null);
58
59 ReactNoop.render(<Fragment condition={true} />);
58 - expect(ReactNoop).toFlushWithoutYielding();
60 + expect(Scheduler).toFlushWithoutYielding();
61
62 const instanceB = instance;
63
@@ -80,14 +82,14 @@ describe('ReactTopLevelFragment', function() {
82 );
83 }
84 ReactNoop.render(<Fragment />);
83 - expect(ReactNoop).toFlushWithoutYielding();
85 + expect(Scheduler).toFlushWithoutYielding();
86
87 const instanceA = instance;
88
89 expect(instanceA).not.toBe(null);
90
91 ReactNoop.render(<Fragment condition={true} />);
90 - expect(ReactNoop).toFlushWithoutYielding();
92 + expect(Scheduler).toFlushWithoutYielding();
93
94 const instanceB = instance;
95
@@ -110,21 +112,21 @@ describe('ReactTopLevelFragment', function() {
112 : [<div key="b">Hello</div>, <Stateful key="a" />];
113 }
114 ReactNoop.render(<Fragment />);
113 - expect(ReactNoop).toFlushWithoutYielding();
115 + expect(Scheduler).toFlushWithoutYielding();
116
117 const instanceA = instance;
118
119 expect(instanceA).not.toBe(null);
120
121 ReactNoop.render(<Fragment condition={true} />);
120 - expect(ReactNoop).toFlushWithoutYielding();
122 + expect(Scheduler).toFlushWithoutYielding();
123
124 const instanceB = instance;
125
126 expect(instanceB).toBe(instanceA);
127
128 ReactNoop.render(<Fragment condition={false} />);
127 - expect(ReactNoop).toFlushWithoutYielding();
129 + expect(Scheduler).toFlushWithoutYielding();
130
131 const instanceC = instance;
132
@@ -147,14 +149,14 @@ describe('ReactTopLevelFragment', function() {
149 : [[<Stateful key="a" />, <div key="b">World</div>], <div key="c" />];
150 }
151 ReactNoop.render(<Fragment />);
150 - expect(ReactNoop).toFlushWithoutYielding();
152 + expect(Scheduler).toFlushWithoutYielding();
153
154 const instanceA = instance;
155
156 expect(instanceA).not.toBe(null);
157
158 ReactNoop.render(<Fragment condition={true} />);
157 - expect(ReactNoop).toFlushWithoutYielding();
159 + expect(Scheduler).toFlushWithoutYielding();
160
161 const instanceB = instance;
162
packages/react-reconciler/src/__tests__/ReactTopLevelText-test.js
+4 -2
@@ -12,6 +12,7 @@
12
13 let React;
14 let ReactNoop;
15 +let Scheduler;
16
17 // This is a new feature in Fiber so I put it in its own test file. It could
18 // probably move to one of the other test files once it is official.
@@ -20,19 +21,20 @@ describe('ReactTopLevelText', () => {
21 jest.resetModules();
22 React = require('react');
23 ReactNoop = require('react-noop-renderer');
24 + Scheduler = require('scheduler');
25 });
26
27 it('should render a component returning strings directly from render', () => {
28 const Text = ({value}) => value;
29 ReactNoop.render(<Text value="foo" />);
28 - expect(ReactNoop).toFlushWithoutYielding();
30 + expect(Scheduler).toFlushWithoutYielding();
31 expect(ReactNoop).toMatchRenderedOutput('foo');
32 });
33
34 it('should render a component returning numbers directly from render', () => {
35 const Text = ({value}) => value;
36 ReactNoop.render(<Text value={10} />);
35 - expect(ReactNoop).toFlushWithoutYielding();
37 + expect(Scheduler).toFlushWithoutYielding();
38 expect(ReactNoop).toMatchRenderedOutput('10');
39 });
40 });
packages/react-test-renderer/src/__tests__/ReactTestRenderer-test.internal.js
+2 -1
@@ -19,6 +19,7 @@ const prettyFormat = require('pretty-format');
19 // Isolate noop renderer
20 jest.resetModules();
21 const ReactNoop = require('react-noop-renderer');
22 +const Scheduler = require('scheduler');
23
24 // Kind of hacky, but we nullify all the instances to test the tree structure
25 // with jasmine's deep equality function, and test the instances separate. We
@@ -1018,7 +1019,7 @@ describe('ReactTestRenderer', () => {
1019 </Context.Provider>
1020 );
1021 ReactNoop.render(<App />);
1021 - expect(ReactNoop).toFlushWithoutYielding();
1022 + expect(Scheduler).toFlushWithoutYielding();
1023 ReactTestRenderer.create(<App />);
1024 });
1025
packages/react-test-renderer/src/__tests__/ReactTestRendererAsync-test.js
+19 -37
@@ -34,7 +34,7 @@ describe('ReactTestRendererAsync', () => {
34 expect(renderer.toJSON()).toEqual(null);
35
36 // Flush initial mount.
37 - expect(renderer).toFlushWithoutYielding();
37 + expect(Scheduler).toFlushWithoutYielding();
38 expect(renderer.toJSON()).toEqual('Hi');
39
40 // Update
@@ -42,7 +42,7 @@ describe('ReactTestRendererAsync', () => {
42 // Not yet updated.
43 expect(renderer.toJSON()).toEqual('Hi');
44 // Flush update.
45 - expect(renderer).toFlushWithoutYielding();
45 + expect(Scheduler).toFlushWithoutYielding();
46 expect(renderer.toJSON()).toEqual('Bye');
47 });
48
@@ -64,11 +64,11 @@ describe('ReactTestRendererAsync', () => {
64 unstable_isConcurrent: true,
65 });
66
67 - expect(renderer).toFlushAndYield(['A:1', 'B:1', 'C:1']);
67 + expect(Scheduler).toFlushAndYield(['A:1', 'B:1', 'C:1']);
68 expect(renderer.toJSON()).toEqual(['A:1', 'B:1', 'C:1']);
69
70 renderer.update(<Parent step={2} />);
71 - expect(renderer).toFlushAndYield(['A:2', 'B:2', 'C:2']);
71 + expect(Scheduler).toFlushAndYield(['A:2', 'B:2', 'C:2']);
72 expect(renderer.toJSON()).toEqual(['A:2', 'B:2', 'C:2']);
73 });
74
@@ -91,12 +91,12 @@ describe('ReactTestRendererAsync', () => {
91 });
92
93 // Flush the first two siblings
94 - expect(renderer).toFlushAndYieldThrough(['A:1', 'B:1']);
94 + expect(Scheduler).toFlushAndYieldThrough(['A:1', 'B:1']);
95 // Did not commit yet.
96 expect(renderer.toJSON()).toEqual(null);
97
98 // Flush the remaining work
99 - expect(renderer).toFlushAndYield(['C:1']);
99 + expect(Scheduler).toFlushAndYield(['C:1']);
100 expect(renderer.toJSON()).toEqual(['A:1', 'B:1', 'C:1']);
101 });
102
@@ -128,7 +128,7 @@ describe('ReactTestRendererAsync', () => {
128 });
129
130 // Flush the some of the changes, but don't commit
131 - expect(renderer).toFlushAndYieldThrough(['A:1']);
131 + expect(Scheduler).toFlushAndYieldThrough(['A:1']);
132 expect(renderer.toJSON()).toEqual(null);
133
134 // Interrupt with higher priority properties
@@ -147,7 +147,7 @@ describe('ReactTestRendererAsync', () => {
147 return id;
148 };
149
150 - const renderer = ReactTestRenderer.create(
150 + ReactTestRenderer.create(
151 <div>
152 <Yield id="foo" />
153 <Yield id="bar" />
@@ -159,7 +159,7 @@ describe('ReactTestRendererAsync', () => {
159 );
160
161 expect(() =>
162 - expect(renderer).toFlushAndYieldThrough(['foo', 'baz']),
162 + expect(Scheduler).toFlushAndYieldThrough(['foo', 'baz']),
163 ).toThrow('Expected value to equal:');
164 });
165
@@ -180,7 +180,7 @@ describe('ReactTestRendererAsync', () => {
180 },
181 );
182
183 - expect(() => expect(renderer).toFlushWithoutYielding()).toThrowError(
183 + expect(() => expect(Scheduler).toFlushWithoutYielding()).toThrowError(
184 'Expected value to equal:',
185 );
186
@@ -192,7 +192,7 @@ describe('ReactTestRendererAsync', () => {
192 </div>,
193 );
194
195 - expect(() => expect(renderer).toFlushAndYield(['foo', 'baz'])).toThrow(
195 + expect(() => expect(Scheduler).toFlushAndYield(['foo', 'baz'])).toThrow(
196 'Expected value to equal:',
197 );
198 });
@@ -223,34 +223,16 @@ describe('ReactTestRendererAsync', () => {
223 unstable_isConcurrent: true,
224 });
225
226 - expect(renderer).toFlushAndThrow('Oh no!');
227 - expect(ReactTestRenderer).toHaveYielded([
228 - 'A',
229 - 'B',
230 - 'C',
231 - 'D',
232 - 'A',
233 - 'B',
234 - 'C',
235 - 'D',
236 - ]);
226 + expect(Scheduler).toFlushAndThrow('Oh no!');
227 + expect(Scheduler).toHaveYielded(['A', 'B', 'C', 'D', 'A', 'B', 'C', 'D']);
228
229 renderer.update(<App />);
230
240 - expect(renderer).toFlushAndThrow('Oh no!');
241 - expect(ReactTestRenderer).toHaveYielded([
242 - 'A',
243 - 'B',
244 - 'C',
245 - 'D',
246 - 'A',
247 - 'B',
248 - 'C',
249 - 'D',
250 - ]);
231 + expect(Scheduler).toFlushAndThrow('Oh no!');
232 + expect(Scheduler).toHaveYielded(['A', 'B', 'C', 'D', 'A', 'B', 'C', 'D']);
233
234 renderer.update(<App />);
253 - expect(renderer).toFlushAndThrow('Oh no!');
235 + expect(Scheduler).toFlushAndThrow('Oh no!');
236 });
237 });
238
@@ -271,17 +253,17 @@ describe('ReactTestRendererAsync', () => {
253 }
254
255 ReactTestRenderer.create(<App />);
274 - expect(() => expect(ReactTestRenderer).toHaveYielded(['A', 'B'])).toThrow(
256 + expect(() => expect(Scheduler).toHaveYielded(['A', 'B'])).toThrow(
257 'Expected value to equal:',
258 );
259 });
260
261 it('flush methods throw if log is not empty', () => {
280 - const renderer = ReactTestRenderer.create(<div />, {
262 + ReactTestRenderer.create(<div />, {
263 unstable_isConcurrent: true,
264 });
265 Scheduler.yieldValue('Something');
284 - expect(() => expect(renderer).toFlushWithoutYielding()).toThrow(
266 + expect(() => expect(Scheduler).toFlushWithoutYielding()).toThrow(
267 'Log of yielded values is not empty.',
268 );
269 });
packages/react/src/__tests__/ReactProfiler-test.internal.js
+45 -49
@@ -241,7 +241,7 @@ describe('Profiler', () => {
241 return null;
242 };
243
244 - const renderer = ReactTestRenderer.create(
244 + ReactTestRenderer.create(
245 <React.unstable_Profiler id="test" onRender={callback}>
246 <Yield value="first" />
247 <Yield value="last" />
@@ -252,9 +252,9 @@ describe('Profiler', () => {
252 );
253
254 // Times are logged until a render is committed.
255 - expect(renderer).toFlushAndYieldThrough(['first']);
255 + expect(Scheduler).toFlushAndYieldThrough(['first']);
256 expect(callback).toHaveBeenCalledTimes(0);
257 - expect(renderer).toFlushAndYield(['last']);
257 + expect(Scheduler).toFlushAndYield(['last']);
258 expect(callback).toHaveBeenCalledTimes(1);
259 });
260
@@ -625,18 +625,18 @@ describe('Profiler', () => {
625 Scheduler.advanceTime(5); // 0 -> 5
626
627 // Render partially, but run out of time before completing.
628 - const renderer = ReactTestRenderer.create(
628 + ReactTestRenderer.create(
629 <React.unstable_Profiler id="test" onRender={callback}>
630 <Yield renderTime={2} />
631 <Yield renderTime={3} />
632 </React.unstable_Profiler>,
633 {unstable_isConcurrent: true},
634 );
635 - expect(renderer).toFlushAndYieldThrough(['Yield:2']);
635 + expect(Scheduler).toFlushAndYieldThrough(['Yield:2']);
636 expect(callback).toHaveBeenCalledTimes(0);
637
638 // Resume render for remaining children.
639 - expect(renderer).toFlushAndYield(['Yield:3']);
639 + expect(Scheduler).toFlushAndYield(['Yield:3']);
640
641 // Verify that logged times include both durations above.
642 expect(callback).toHaveBeenCalledTimes(1);
@@ -660,7 +660,7 @@ describe('Profiler', () => {
660
661 // Render partially, but don't finish.
662 // This partial render should take 5ms of simulated time.
663 - const renderer = ReactTestRenderer.create(
663 + ReactTestRenderer.create(
664 <React.unstable_Profiler id="outer" onRender={callback}>
665 <Yield renderTime={5} />
666 <Yield renderTime={10} />
@@ -670,7 +670,7 @@ describe('Profiler', () => {
670 </React.unstable_Profiler>,
671 {unstable_isConcurrent: true},
672 );
673 - expect(renderer).toFlushAndYieldThrough(['Yield:5']);
673 + expect(Scheduler).toFlushAndYieldThrough(['Yield:5']);
674 expect(callback).toHaveBeenCalledTimes(0);
675
676 // Simulate time moving forward while frame is paused.
@@ -678,7 +678,7 @@ describe('Profiler', () => {
678
679 // Flush the remaining work,
680 // Which should take an additional 10ms of simulated time.
681 - expect(renderer).toFlushAndYield(['Yield:10', 'Yield:17']);
681 + expect(Scheduler).toFlushAndYield(['Yield:10', 'Yield:17']);
682 expect(callback).toHaveBeenCalledTimes(2);
683
684 const [innerCall, outerCall] = callback.mock.calls;
@@ -717,7 +717,7 @@ describe('Profiler', () => {
717 </React.unstable_Profiler>,
718 {unstable_isConcurrent: true},
719 );
720 - expect(renderer).toFlushAndYieldThrough(['Yield:10']);
720 + expect(Scheduler).toFlushAndYieldThrough(['Yield:10']);
721 expect(callback).toHaveBeenCalledTimes(0);
722
723 // Simulate time moving forward while frame is paused.
@@ -732,7 +732,7 @@ describe('Profiler', () => {
732 </React.unstable_Profiler>,
733 );
734 });
735 - expect(ReactTestRenderer).toHaveYielded(['Yield:5']);
735 + expect(Scheduler).toHaveYielded(['Yield:5']);
736
737 // The initial work was thrown away in this case,
738 // So the actual and base times should only include the final rendered tree times.
@@ -746,7 +746,7 @@ describe('Profiler', () => {
746 callback.mockReset();
747
748 // Verify no more unexpected callbacks from low priority work
749 - expect(renderer).toFlushWithoutYielding();
749 + expect(Scheduler).toFlushWithoutYielding();
750 expect(callback).toHaveBeenCalledTimes(0);
751 });
752
@@ -771,7 +771,7 @@ describe('Profiler', () => {
771
772 // Render everything initially.
773 // This should take 21 seconds of actual and base time.
774 - expect(renderer).toFlushAndYield(['Yield:6', 'Yield:15']);
774 + expect(Scheduler).toFlushAndYield(['Yield:6', 'Yield:15']);
775 expect(callback).toHaveBeenCalledTimes(1);
776 let call = callback.mock.calls[0];
777 expect(call[2]).toBe(21); // actual time
@@ -792,14 +792,14 @@ describe('Profiler', () => {
792 <Yield renderTime={9} />
793 </React.unstable_Profiler>,
794 );
795 - expect(renderer).toFlushAndYieldThrough(['Yield:3']);
795 + expect(Scheduler).toFlushAndYieldThrough(['Yield:3']);
796 expect(callback).toHaveBeenCalledTimes(0);
797
798 // Simulate time moving forward while frame is paused.
799 Scheduler.advanceTime(100); // 59 -> 159
800
801 // Render another 5ms of simulated time.
802 - expect(renderer).toFlushAndYieldThrough(['Yield:5']);
802 + expect(Scheduler).toFlushAndYieldThrough(['Yield:5']);
803 expect(callback).toHaveBeenCalledTimes(0);
804
805 // Simulate time moving forward while frame is paused.
@@ -814,7 +814,7 @@ describe('Profiler', () => {
814 </React.unstable_Profiler>,
815 );
816 });
817 - expect(ReactTestRenderer).toHaveYielded(['Yield:11']);
817 + expect(Scheduler).toHaveYielded(['Yield:11']);
818
819 // The actual time should include only the most recent render,
820 // Because this lets us avoid a lot of commit phase reset complexity.
@@ -827,7 +827,7 @@ describe('Profiler', () => {
827 expect(call[5]).toBe(275); // commit time
828
829 // Verify no more unexpected callbacks from low priority work
830 - expect(renderer).toFlushAndYield([]);
830 + expect(Scheduler).toFlushAndYield([]);
831 expect(callback).toHaveBeenCalledTimes(1);
832 });
833
@@ -874,7 +874,7 @@ describe('Profiler', () => {
874 // Render everything initially.
875 // This simulates a total of 14ms of actual render time.
876 // The base render time is also 14ms for the initial render.
877 - expect(renderer).toFlushAndYield([
877 + expect(Scheduler).toFlushAndYield([
878 'FirstComponent:1',
879 'Yield:4',
880 'SecondComponent:2',
@@ -894,7 +894,7 @@ describe('Profiler', () => {
894 // Render a partially update, but don't finish.
895 // This partial render will take 10ms of actual render time.
896 first.setState({renderTime: 10});
897 - expect(renderer).toFlushAndYieldThrough(['FirstComponent:10']);
897 + expect(Scheduler).toFlushAndYieldThrough(['FirstComponent:10']);
898 expect(callback).toHaveBeenCalledTimes(0);
899
900 // Simulate time moving forward while frame is paused.
@@ -903,10 +903,7 @@ describe('Profiler', () => {
903 // Interrupt with higher priority work.
904 // This simulates a total of 37ms of actual render time.
905 renderer.unstable_flushSync(() => second.setState({renderTime: 30}));
906 - expect(ReactTestRenderer).toHaveYielded([
907 - 'SecondComponent:30',
908 - 'Yield:7',
909 - ]);
906 + expect(Scheduler).toHaveYielded(['SecondComponent:30', 'Yield:7']);
907
908 // The actual time should include only the most recent render (37ms),
909 // Because this greatly simplifies the commit phase logic.
@@ -930,7 +927,7 @@ describe('Profiler', () => {
927 // The tree contains 42ms of base render time at this point,
928 // Reflecting the most recent (longer) render durations.
929 // TODO: This actual time should decrease by 10ms once the scheduler supports resuming.
933 - expect(renderer).toFlushAndYield(['FirstComponent:10', 'Yield:4']);
930 + expect(Scheduler).toFlushAndYield(['FirstComponent:10', 'Yield:4']);
931 expect(callback).toHaveBeenCalledTimes(1);
932 call = callback.mock.calls[0];
933 expect(call[2]).toBe(14); // actual time
@@ -1106,7 +1103,7 @@ describe('Profiler', () => {
1103 <errorInCompletePhase>hi</errorInCompletePhase>
1104 </React.unstable_Profiler>,
1105 );
1109 - expect(ReactNoop).toFlushAndThrow('Error in host config.');
1106 + expect(Scheduler).toFlushAndThrow('Error in host config.');
1107
1108 // A similar case we've seen caused by an invariant in ReactDOM.
1109 // It didn't reproduce without a host component inside.
@@ -1117,7 +1114,7 @@ describe('Profiler', () => {
1114 </errorInCompletePhase>
1115 </React.unstable_Profiler>,
1116 );
1120 - expect(ReactNoop).toFlushAndThrow('Error in host config.');
1117 + expect(Scheduler).toFlushAndThrow('Error in host config.');
1118
1119 // So long as the profiler timer's fiber stack is reset correctly,
1120 // Subsequent renders should not error.
@@ -1126,7 +1123,7 @@ describe('Profiler', () => {
1123 <span>hi</span>
1124 </React.unstable_Profiler>,
1125 );
1129 - expect(ReactNoop).toFlushWithoutYielding();
1126 + expect(Scheduler).toFlushWithoutYielding();
1127 });
1128 });
1129 },
@@ -1247,7 +1244,7 @@ describe('Profiler', () => {
1244
1245 // Process some async work, but yield before committing it.
1246 ReactNoop.renderToRootWithID(<Parent duration={7} id="two" />, 'two');
1250 - expect(ReactNoop).toFlushAndYieldThrough(['Child:render:two']);
1247 + expect(Scheduler).toFlushAndYieldThrough(['Child:render:two']);
1248
1249 Scheduler.advanceTime(150);
1250
@@ -1259,7 +1256,7 @@ describe('Profiler', () => {
1256
1257 Scheduler.advanceTime(200);
1258
1262 - expect(ReactNoop).toFlushAndYield([
1259 + expect(Scheduler).toFlushAndYield([
1260 'Child:render:two',
1261 'Parent:componentDidMount:two',
1262 ]);
@@ -1360,7 +1357,7 @@ describe('Profiler', () => {
1357 renderer = ReactTestRenderer.create(<Component>succeed</Component>, {
1358 unstable_isConcurrent: true,
1359 });
1363 - expect(renderer).toFlushAndYield(['Component:succeed']);
1360 + expect(Scheduler).toFlushAndYield(['Component:succeed']);
1361 const tree = renderer.toTree();
1362 expect(tree.type).toBe(Component);
1363 expect(tree.props.children).toBe('succeed');
@@ -1386,13 +1383,13 @@ describe('Profiler', () => {
1383
1384 // Errors that happen inside of a subscriber should throw,
1385 throwInOnWorkStarted = true;
1389 - expect(renderer).toFlushAndThrow('Expected error onWorkStarted');
1390 - expect(ReactTestRenderer).toHaveYielded(['Component:text']);
1386 + expect(Scheduler).toFlushAndThrow('Expected error onWorkStarted');
1387 + expect(Scheduler).toHaveYielded(['Component:text']);
1388 throwInOnWorkStarted = false;
1389 expect(onWorkStarted).toHaveBeenCalled();
1390
1391 // But the React work should have still been processed.
1395 - expect(renderer).toFlushAndYield([]);
1392 + expect(Scheduler).toFlushAndYield([]);
1393 const tree = renderer.toTree();
1394 expect(tree.type).toBe(Component);
1395 expect(tree.props.children).toBe('text');
@@ -1637,7 +1634,7 @@ describe('Profiler', () => {
1634 ]);
1635 expect(onWorkScheduled.mock.calls[0][1] > 0).toBe(true);
1636
1640 - expect(renderer).toFlushAndYieldThrough(['first']);
1637 + expect(Scheduler).toFlushAndYieldThrough(['first']);
1638 expect(onRender).not.toHaveBeenCalled();
1639
1640 expect(onInteractionTraced).toHaveBeenCalledTimes(2);
@@ -1830,7 +1827,7 @@ describe('Profiler', () => {
1827 interactionLowPri,
1828 ]);
1829
1833 - expect(renderer).toFlushAndYieldThrough(['FirstComponent']);
1830 + expect(Scheduler).toFlushAndYieldThrough(['FirstComponent']);
1831 expect(onRender).not.toHaveBeenCalled();
1832
1833 expect(onInteractionTraced).toHaveBeenCalledTimes(1);
@@ -1874,7 +1871,7 @@ describe('Profiler', () => {
1871 },
1872 );
1873 });
1877 - expect(ReactTestRenderer).toHaveYielded(['SecondComponent']);
1874 + expect(Scheduler).toHaveYielded(['SecondComponent']);
1875
1876 expect(onInteractionTraced).toHaveBeenCalledTimes(2);
1877 expect(onInteractionScheduledWorkCompleted).toHaveBeenCalledTimes(1);
@@ -2294,7 +2291,7 @@ describe('Profiler', () => {
2291 expect(getWorkForReactThreads(onWorkStarted)).toHaveLength(0);
2292 expect(getWorkForReactThreads(onWorkStopped)).toHaveLength(0);
2293
2297 - expect(ReactNoop).toFlushAndYield([
2294 + expect(Scheduler).toFlushAndYield([
2295 'Suspend [Async]',
2296 'Text [Loading...]',
2297 'Text [Sync]',
@@ -2326,13 +2323,13 @@ describe('Profiler', () => {
2323
2324 // An unrelated update in the middle shouldn't affect things...
2325 monkey.current.forceUpdate();
2329 - expect(ReactNoop).toFlushAndYield(['Monkey']);
2326 + expect(Scheduler).toFlushAndYield(['Monkey']);
2327 expect(onRender).toHaveBeenCalledTimes(2);
2328
2329 // Once the promise resolves, we render the suspended view
2330 await awaitableAdvanceTimers(10000);
2334 - expect(ReactNoop).toHaveYielded(['Promise resolved [Async]']);
2335 - expect(ReactNoop).toFlushAndYield(['AsyncText [Async]']);
2331 + expect(Scheduler).toHaveYielded(['Promise resolved [Async]']);
2332 + expect(Scheduler).toFlushAndYield(['AsyncText [Async]']);
2333 expect(ReactNoop.getChildrenAsJSX()).toEqual('AsyncSync');
2334 expect(onRender).toHaveBeenCalledTimes(3);
2335
@@ -2450,12 +2447,11 @@ describe('Profiler', () => {
2447 };
2448
2449 const onRender = jest.fn();
2453 - let renderer;
2450 SchedulerTracing.unstable_trace(
2451 interaction.name,
2452 interaction.timestamp,
2453 () => {
2458 - renderer = ReactTestRenderer.create(
2454 + ReactTestRenderer.create(
2455 <React.unstable_Profiler id="app" onRender={onRender}>
2456 <React.Suspense
2457 maxDuration={1000}
@@ -2473,7 +2469,7 @@ describe('Profiler', () => {
2469 Scheduler.advanceTime(1500);
2470 await awaitableAdvanceTimers(1500);
2471
2476 - expect(renderer).toFlushAndYield([
2472 + expect(Scheduler).toFlushAndYield([
2473 'Suspend [loaded]',
2474 'Text [loading]',
2475 ]);
@@ -2482,8 +2478,8 @@ describe('Profiler', () => {
2478 Scheduler.advanceTime(2500);
2479 await awaitableAdvanceTimers(2500);
2480
2485 - expect(ReactTestRenderer).toHaveYielded(['Promise resolved [loaded]']);
2486 - expect(renderer).toFlushAndYield(['AsyncText [loaded]']);
2481 + expect(Scheduler).toHaveYielded(['Promise resolved [loaded]']);
2482 + expect(Scheduler).toFlushAndYield(['AsyncText [loaded]']);
2483 expect(onInteractionScheduledWorkCompleted).toHaveBeenCalledTimes(1);
2484 expect(
2485 onInteractionScheduledWorkCompleted,
@@ -2644,7 +2640,7 @@ describe('Profiler', () => {
2640 );
2641 },
2642 );
2647 - expect(renderer).toFlushAndYield([
2643 + expect(Scheduler).toFlushAndYield([
2644 'Suspend [loaded]',
2645 'Text [loading]',
2646 'Text [initial]',
@@ -2682,7 +2678,7 @@ describe('Profiler', () => {
2678 },
2679 );
2680 });
2685 - expect(ReactTestRenderer).toHaveYielded([
2681 + expect(Scheduler).toHaveYielded([
2682 'Suspend [loaded]',
2683 'Text [loading]',
2684 'Text [updated]',
@@ -2700,8 +2696,8 @@ describe('Profiler', () => {
2696 Scheduler.advanceTime(500);
2697 jest.advanceTimersByTime(500);
2698 await originalPromise;
2703 - expect(ReactTestRenderer).toHaveYielded(['Promise resolved [loaded]']);
2704 - expect(renderer).toFlushAndYield(['AsyncText [loaded]']);
2699 + expect(Scheduler).toHaveYielded(['Promise resolved [loaded]']);
2700 + expect(Scheduler).toFlushAndYield(['AsyncText [loaded]']);
2701 expect(renderer.toJSON()).toEqual(['loaded', 'updated']);
2702
2703 expect(onRender).toHaveBeenCalledTimes(1);
packages/react/src/__tests__/forwardRef-test.internal.js
+10 -8
@@ -13,6 +13,7 @@ describe('forwardRef', () => {
13 let React;
14 let ReactFeatureFlags;
15 let ReactNoop;
16 + let Scheduler;
17
18 beforeEach(() => {
19 jest.resetModules();
@@ -21,6 +22,7 @@ describe('forwardRef', () => {
22 ReactFeatureFlags.replayFailedUnitOfWorkWithInvokeGuardedCallback = false;
23 React = require('react');
24 ReactNoop = require('react-noop-renderer');
25 + Scheduler = require('scheduler');
26 });
27
28 it('should work without a ref to be forwarded', () => {
@@ -40,7 +42,7 @@ describe('forwardRef', () => {
42 ));
43
44 ReactNoop.render(<RefForwardingComponent value={123} />);
43 - expect(ReactNoop).toFlushAndYield([123]);
45 + expect(Scheduler).toFlushAndYield([123]);
46 });
47
48 it('should forward a ref for a single child', () => {
@@ -62,7 +64,7 @@ describe('forwardRef', () => {
64 const ref = React.createRef();
65
66 ReactNoop.render(<RefForwardingComponent ref={ref} value={123} />);
65 - expect(ReactNoop).toFlushAndYield([123]);
67 + expect(Scheduler).toFlushAndYield([123]);
68 expect(ref.current instanceof Child).toBe(true);
69 });
70
@@ -91,7 +93,7 @@ describe('forwardRef', () => {
93 <div />
94 </div>,
95 );
94 - expect(ReactNoop).toFlushAndYield([123]);
96 + expect(Scheduler).toFlushAndYield([123]);
97 expect(ref.current instanceof Child).toBe(true);
98 });
99
@@ -123,11 +125,11 @@ describe('forwardRef', () => {
125 };
126
127 ReactNoop.render(<RefForwardingComponent ref={setRef} value={123} />);
126 - expect(ReactNoop).toFlushAndYield([123]);
128 + expect(Scheduler).toFlushAndYield([123]);
129 expect(ref instanceof Child).toBe(true);
130 expect(setRefCount).toBe(1);
131 ReactNoop.render(<RefForwardingComponent ref={setRef} value={456} />);
130 - expect(ReactNoop).toFlushAndYield([456]);
132 + expect(Scheduler).toFlushAndYield([456]);
133 expect(ref instanceof Child).toBe(true);
134 expect(setRefCount).toBe(1);
135 });
@@ -172,7 +174,7 @@ describe('forwardRef', () => {
174 <RefForwardingComponent ref={ref} />
175 </ErrorBoundary>,
176 );
175 - expect(ReactNoop).toFlushAndYield([
177 + expect(Scheduler).toFlushAndYield([
178 'ErrorBoundary.render: try',
179 'Wrapper',
180 'BadRender throw',
@@ -216,9 +218,9 @@ describe('forwardRef', () => {
218 }
219
220 ReactNoop.render(<App />);
219 - expect(ReactNoop).toFlushAndYield(['App', 'Forward', 'Middle', 'Inner']);
221 + expect(Scheduler).toFlushAndYield(['App', 'Forward', 'Middle', 'Inner']);
222
223 inst.setState({});
222 - expect(ReactNoop).toFlushAndYield(['Inner']);
224 + expect(Scheduler).toFlushAndYield(['Inner']);
225 });
226 });
packages/react/src/__tests__/forwardRef-test.js
+22 -20
@@ -13,12 +13,14 @@ describe('forwardRef', () => {
13 let PropTypes;
14 let React;
15 let ReactNoop;
16 + let Scheduler;
17
18 beforeEach(() => {
19 jest.resetModules();
20 PropTypes = require('prop-types');
21 React = require('react');
22 ReactNoop = require('react-noop-renderer');
23 + Scheduler = require('scheduler');
24 });
25
26 it('should update refs when switching between children', () => {
@@ -38,11 +40,11 @@ describe('forwardRef', () => {
40 const ref = React.createRef();
41
42 ReactNoop.render(<RefForwardingComponent ref={ref} setRefOnDiv={true} />);
41 - expect(ReactNoop).toFlushWithoutYielding();
43 + expect(Scheduler).toFlushWithoutYielding();
44 expect(ref.current.type).toBe('div');
45
46 ReactNoop.render(<RefForwardingComponent ref={ref} setRefOnDiv={false} />);
45 - expect(ReactNoop).toFlushWithoutYielding();
47 + expect(Scheduler).toFlushWithoutYielding();
48 expect(ref.current.type).toBe('span');
49 });
50
@@ -52,7 +54,7 @@ describe('forwardRef', () => {
54 const ref = React.createRef();
55
56 ReactNoop.render(<RefForwardingComponent ref={ref} />);
55 - expect(ReactNoop).toFlushWithoutYielding();
57 + expect(Scheduler).toFlushWithoutYielding();
58 expect(ref.current).toBe(null);
59 });
60
@@ -68,7 +70,7 @@ describe('forwardRef', () => {
70 <div />
71 </div>,
72 );
71 - expect(ReactNoop).toFlushWithoutYielding();
73 + expect(Scheduler).toFlushWithoutYielding();
74 expect(ref.current).toBe(null);
75 });
76
@@ -101,14 +103,14 @@ describe('forwardRef', () => {
103 ReactNoop.render(
104 <RefForwardingComponent ref={ref} optional="foo" required="bar" />,
105 );
104 - expect(ReactNoop).toFlushWithoutYielding();
106 + expect(Scheduler).toFlushWithoutYielding();
107 expect(ref.current.children).toEqual([
108 {text: 'foo', hidden: false},
109 {text: 'bar', hidden: false},
110 ]);
111
112 ReactNoop.render(<RefForwardingComponent ref={ref} required="foo" />);
111 - expect(ReactNoop).toFlushWithoutYielding();
113 + expect(Scheduler).toFlushWithoutYielding();
114 expect(ref.current.children).toEqual([
115 {text: 'default', hidden: false},
116 {text: 'foo', hidden: false},
@@ -240,11 +242,11 @@ describe('forwardRef', () => {
242 const ref = React.createRef();
243
244 ReactNoop.render(<RefForwardingComponent ref={ref} optional="foo" />);
243 - expect(ReactNoop).toFlushWithoutYielding();
245 + expect(Scheduler).toFlushWithoutYielding();
246 expect(renderCount).toBe(1);
247
248 ReactNoop.render(<RefForwardingComponent ref={ref} optional="foo" />);
247 - expect(ReactNoop).toFlushWithoutYielding();
249 + expect(Scheduler).toFlushWithoutYielding();
250 expect(renderCount).toBe(2);
251 });
252
@@ -263,13 +265,13 @@ describe('forwardRef', () => {
265 const ref = React.createRef();
266
267 ReactNoop.render(<RefForwardingComponent ref={ref} optional="foo" />);
266 - expect(ReactNoop).toFlushWithoutYielding();
268 + expect(Scheduler).toFlushWithoutYielding();
269 expect(renderCount).toBe(1);
270
271 expect(ref.current.type).toBe('div');
272
273 ReactNoop.render(<RefForwardingComponent ref={ref} optional="foo" />);
272 - expect(ReactNoop).toFlushWithoutYielding();
274 + expect(Scheduler).toFlushWithoutYielding();
275 expect(renderCount).toBe(1);
276
277 const differentRef = React.createRef();
@@ -277,14 +279,14 @@ describe('forwardRef', () => {
279 ReactNoop.render(
280 <RefForwardingComponent ref={differentRef} optional="foo" />,
281 );
280 - expect(ReactNoop).toFlushWithoutYielding();
282 + expect(Scheduler).toFlushWithoutYielding();
283 expect(renderCount).toBe(2);
284
285 expect(ref.current).toBe(null);
286 expect(differentRef.current.type).toBe('div');
287
288 ReactNoop.render(<RefForwardingComponent ref={ref} optional="bar" />);
287 - expect(ReactNoop).toFlushWithoutYielding();
289 + expect(Scheduler).toFlushWithoutYielding();
290 expect(renderCount).toBe(3);
291 });
292
@@ -304,19 +306,19 @@ describe('forwardRef', () => {
306 const ref = React.createRef();
307
308 ReactNoop.render(<RefForwardingComponent ref={ref} a="0" b="0" c="1" />);
307 - expect(ReactNoop).toFlushWithoutYielding();
309 + expect(Scheduler).toFlushWithoutYielding();
310 expect(renderCount).toBe(1);
311
312 expect(ref.current.type).toBe('div');
313
314 // Changing either a or b rerenders
315 ReactNoop.render(<RefForwardingComponent ref={ref} a="0" b="1" c="1" />);
314 - expect(ReactNoop).toFlushWithoutYielding();
316 + expect(Scheduler).toFlushWithoutYielding();
317 expect(renderCount).toBe(2);
318
319 // Changing c doesn't rerender
320 ReactNoop.render(<RefForwardingComponent ref={ref} a="0" b="1" c="2" />);
319 - expect(ReactNoop).toFlushWithoutYielding();
321 + expect(Scheduler).toFlushWithoutYielding();
322 expect(renderCount).toBe(2);
323
324 const ComposedMemo = React.memo(
@@ -325,29 +327,29 @@ describe('forwardRef', () => {
327 );
328
329 ReactNoop.render(<ComposedMemo ref={ref} a="0" b="0" c="0" />);
328 - expect(ReactNoop).toFlushWithoutYielding();
330 + expect(Scheduler).toFlushWithoutYielding();
331 expect(renderCount).toBe(3);
332
333 // Changing just b no longer updates
334 ReactNoop.render(<ComposedMemo ref={ref} a="0" b="1" c="0" />);
333 - expect(ReactNoop).toFlushWithoutYielding();
335 + expect(Scheduler).toFlushWithoutYielding();
336 expect(renderCount).toBe(3);
337
338 // Changing just a and c updates
339 ReactNoop.render(<ComposedMemo ref={ref} a="2" b="2" c="2" />);
338 - expect(ReactNoop).toFlushWithoutYielding();
340 + expect(Scheduler).toFlushWithoutYielding();
341 expect(renderCount).toBe(4);
342
343 // Changing just c does not update
344 ReactNoop.render(<ComposedMemo ref={ref} a="2" b="2" c="3" />);
343 - expect(ReactNoop).toFlushWithoutYielding();
345 + expect(Scheduler).toFlushWithoutYielding();
346 expect(renderCount).toBe(4);
347
348 // Changing ref still rerenders
349 const differentRef = React.createRef();
350
351 ReactNoop.render(<ComposedMemo ref={differentRef} a="2" b="2" c="3" />);
350 - expect(ReactNoop).toFlushWithoutYielding();
352 + expect(Scheduler).toFlushWithoutYielding();
353 expect(renderCount).toBe(5);
354
355 expect(ref.current).toBe(null);
scripts/error-codes/codes.json
+2 -2
@@ -290,8 +290,8 @@
290 "288": "It is not supported to run the profiling version of a renderer (for example, `react-dom/profiling`) without also replacing the `schedule/tracing` module with `schedule/tracing-profiling`. Your bundler might have a setting for aliasing both modules. Learn more at http://fb.me/react-profiling",
291 "289": "Function components cannot have refs.",
292 "290": "Element ref was specified as a string (%s) but no owner was set. This could happen for one of the following reasons:\n1. You may be adding a ref to a function component\n2. You may be adding a ref to a component that was not created inside a component's render method\n3. You have multiple copies of React loaded\nSee https://fb.me/react-refs-must-have-owner for more information.",
293 - "291": "Log of yielded values is not empty. Call expect(ReactTestRenderer).toHaveYielded(...) first.",
294 - "292": "The matcher `toHaveYielded` expects an instance of React Test Renderer.\n\nTry: expect(ReactTestRenderer).toHaveYielded(expectedYields)",
293 + "291": "Log of yielded values is not empty. Call expect(Scheduler).toHaveYielded(...) first.",
294 + "292": "The matcher `toHaveYielded` expects an instance of React Test Renderer.\n\nTry: expect(Scheduler).toHaveYielded(expectedYields)",
295 "293": "Context can only be read while React is rendering, e.g. inside the render method or getDerivedStateFromProps.",
296 "294": "ReactDOMServer does not yet support Suspense.",
297 "295": "ReactDOMServer does not yet support lazy-loaded components.",
scripts/jest/matchers/reactTestMatchers.js
+1 -37
@@ -19,13 +19,6 @@ function captureAssertion(fn) {
19 return {pass: true};
20 }
21
22 -function resolveScheduler(obj) {
23 - if (obj._Scheduler !== undefined) {
24 - return obj._Scheduler;
25 - }
26 - return obj;
27 -}
28 -
22 function assertYieldsWereCleared(Scheduler) {
23 const actualYields = Scheduler.unstable_clearYields();
24 if (actualYields.length !== 0) {
@@ -36,31 +29,6 @@ function assertYieldsWereCleared(Scheduler) {
29 }
30 }
31
39 -function toFlushAndYield(ReactNoop, expectedYields) {
40 - const Scheduler = resolveScheduler(ReactNoop);
41 - return SchedulerMatchers.toFlushAndYield(Scheduler, expectedYields);
42 -}
43 -
44 -function toFlushAndYieldThrough(ReactNoop, expectedYields) {
45 - const Scheduler = resolveScheduler(ReactNoop);
46 - return SchedulerMatchers.toFlushAndYieldThrough(Scheduler, expectedYields);
47 -}
48 -
49 -function toFlushWithoutYielding(ReactNoop) {
50 - const Scheduler = resolveScheduler(ReactNoop);
51 - return SchedulerMatchers.toFlushWithoutYielding(Scheduler);
52 -}
53 -
54 -function toHaveYielded(ReactNoop, expectedYields) {
55 - const Scheduler = resolveScheduler(ReactNoop);
56 - return SchedulerMatchers.toHaveYielded(Scheduler, expectedYields);
57 -}
58 -
59 -function toFlushAndThrow(ReactNoop, ...rest) {
60 - const Scheduler = resolveScheduler(ReactNoop);
61 - return SchedulerMatchers.toFlushAndThrow(Scheduler, ...rest);
62 -}
63 -
32 function toMatchRenderedOutput(ReactNoop, expectedJSX) {
33 if (typeof ReactNoop.getChildrenAsJSX === 'function') {
34 const Scheduler = ReactNoop._Scheduler;
@@ -73,10 +41,6 @@ function toMatchRenderedOutput(ReactNoop, expectedJSX) {
41 }
42
43 module.exports = {
76 - toFlushAndYield,
77 - toFlushAndYieldThrough,
78 - toFlushWithoutYielding,
79 - toHaveYielded,
80 - toFlushAndThrow,
44 + ...SchedulerMatchers,
45 toMatchRenderedOutput,
46 };
scripts/rollup/bundles.js
+5 -44
@@ -281,7 +281,7 @@ const bundles = [
281 moduleType: RENDERER,
282 entry: 'react-test-renderer',
283 global: 'ReactTestRenderer',
284 - externals: ['react'],
284 + externals: ['react', 'scheduler', 'scheduler/unstable_mock'],
285 },
286
287 {
@@ -289,7 +289,7 @@ const bundles = [
289 moduleType: NON_FIBER_RENDERER,
290 entry: 'react-test-renderer/shallow',
291 global: 'ReactShallowRenderer',
292 - externals: ['react'],
292 + externals: ['react', 'scheduler', 'scheduler/unstable_mock'],
293 },
294
295 /******* React Noop Renderer (used for tests) *******/
@@ -298,20 +298,7 @@ const bundles = [
298 moduleType: RENDERER,
299 entry: 'react-noop-renderer',
300 global: 'ReactNoopRenderer',
301 - externals: ['react', 'expect'],
302 - // React Noop uses generators. However GCC currently
303 - // breaks when we attempt to use them in the output.
304 - // So we precompile them with regenerator, and include
305 - // it as a runtime dependency of React Noop. In practice
306 - // this isn't an issue because React Noop is only used
307 - // in our tests. We wouldn't want to do this for any
308 - // public package though.
309 - babel: opts =>
310 - Object.assign({}, opts, {
311 - plugins: opts.plugins.concat([
312 - require.resolve('babel-plugin-transform-regenerator'),
313 - ]),
314 - }),
301 + externals: ['react', 'scheduler', 'scheduler/unstable_mock', 'expect'],
302 },
303
304 /******* React Noop Persistent Renderer (used for tests) *******/
@@ -320,20 +307,7 @@ const bundles = [
307 moduleType: RENDERER,
308 entry: 'react-noop-renderer/persistent',
309 global: 'ReactNoopRendererPersistent',
323 - externals: ['react', 'expect'],
324 - // React Noop uses generators. However GCC currently
325 - // breaks when we attempt to use them in the output.
326 - // So we precompile them with regenerator, and include
327 - // it as a runtime dependency of React Noop. In practice
328 - // this isn't an issue because React Noop is only used
329 - // in our tests. We wouldn't want to do this for any
330 - // public package though.
331 - babel: opts =>
332 - Object.assign({}, opts, {
333 - plugins: opts.plugins.concat([
334 - require.resolve('babel-plugin-transform-regenerator'),
335 - ]),
336 - }),
310 + externals: ['react', 'scheduler', 'expect'],
311 },
312
313 /******* React Noop Server Renderer (used for tests) *******/
@@ -342,20 +316,7 @@ const bundles = [
316 moduleType: RENDERER,
317 entry: 'react-noop-renderer/server',
318 global: 'ReactNoopRendererServer',
345 - externals: ['react', 'expect'],
346 - // React Noop uses generators. However GCC currently
347 - // breaks when we attempt to use them in the output.
348 - // So we precompile them with regenerator, and include
349 - // it as a runtime dependency of React Noop. In practice
350 - // this isn't an issue because React Noop is only used
351 - // in our tests. We wouldn't want to do this for any
352 - // public package though.
353 - babel: opts =>
354 - Object.assign({}, opts, {
355 - plugins: opts.plugins.concat([
356 - require.resolve('babel-plugin-transform-regenerator'),
357 - ]),
358 - }),
319 + externals: ['react', 'scheduler', 'expect'],
320 },
321
322 /******* React Reconciler *******/
scripts/rollup/modules.js
+1
@@ -25,6 +25,7 @@ const knownGlobals = Object.freeze({
25 'react-dom': 'ReactDOM',
26 scheduler: 'Scheduler',
27 'scheduler/tracing': 'SchedulerTracing',
28 + 'scheduler/unstable_mock': 'SchedulerMock',
29 });
30
31 // Given ['react'] in bundle externals, returns { 'react': 'React' }.