Skip to content

Commit b36ae8d

Browse files
authored
Add stable concurrent option to react-test-renderer (#27804)
## Summary Concurrent rendering has been the default since React 18 release. ReactTestRenderer requires passing `{unstable_isConcurrent: true}` to match this behavior, which means by default tests written with RTR use a different rendering method than the code they test. Eventually, RTR should only use ConcurrentRoot. As a first step, let's add a version of the concurrent option that isn't marked unstable. Next we will follow up with removing the unstable option when it is safe to merge. ## How did you test this change? `yarn test packages/react-test-renderer/src/__tests__/ReactTestRendererAsync-test.js`
1 parent be8aa76 commit b36ae8d

15 files changed

+107
-103
lines changed

packages/react-cache/src/__tests__/ReactCacheOld-test.internal.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ describe('ReactCache', () => {
121121
}
122122

123123
ReactTestRenderer.create(<App />, {
124-
unstable_isConcurrent: true,
124+
isConcurrent: true,
125125
});
126126

127127
await waitForAll(['Suspend! [Hi]', 'Loading...']);
@@ -141,7 +141,7 @@ describe('ReactCache', () => {
141141
}
142142

143143
const root = ReactTestRenderer.create(<App />, {
144-
unstable_isConcurrent: true,
144+
isConcurrent: true,
145145
});
146146

147147
await waitForAll(['Suspend! [Hi]', 'Loading...']);
@@ -181,7 +181,7 @@ describe('ReactCache', () => {
181181
<App />
182182
</Suspense>,
183183
{
184-
unstable_isConcurrent: true,
184+
isConcurrent: true,
185185
},
186186
);
187187

@@ -210,7 +210,7 @@ describe('ReactCache', () => {
210210
<AsyncText ms={100} text={3} />
211211
</Suspense>,
212212
{
213-
unstable_isConcurrent: true,
213+
isConcurrent: true,
214214
},
215215
);
216216
await waitForAll(['Suspend! [1]', 'Loading...']);
@@ -298,7 +298,7 @@ describe('ReactCache', () => {
298298
<App />
299299
</Suspense>,
300300
{
301-
unstable_isConcurrent: true,
301+
isConcurrent: true,
302302
},
303303
);
304304

@@ -356,7 +356,7 @@ describe('ReactCache', () => {
356356
<BadAsyncText text="Hi" />
357357
</Suspense>,
358358
{
359-
unstable_isConcurrent: true,
359+
isConcurrent: true,
360360
},
361361
);
362362

@@ -372,7 +372,7 @@ describe('ReactCache', () => {
372372
<BadAsyncText text="Hi" />
373373
</Suspense>,
374374
{
375-
unstable_isConcurrent: true,
375+
isConcurrent: true,
376376
},
377377
);
378378

packages/react-debug-tools/src/__tests__/ReactDevToolsHooksIntegration-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ describe('React hooks DevTools integration', () => {
254254
<MyComponent />
255255
</React.Suspense>
256256
</div>,
257-
{unstable_isConcurrent: true},
257+
{isConcurrent: true},
258258
),
259259
);
260260

packages/react-devtools-shared/src/__tests__/inspectedElement-test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ describe('InspectedElement', () => {
7575
// Used by inspectElementAtIndex() helper function
7676
utils.act(() => {
7777
testRendererInstance = TestRenderer.create(null, {
78-
unstable_isConcurrent: true,
78+
isConcurrent: true,
7979
});
8080
});
8181

@@ -307,7 +307,7 @@ describe('InspectedElement', () => {
307307
['An update to %s inside a test was not wrapped in act'],
308308
() => {
309309
testRendererInstance = TestRenderer.create(null, {
310-
unstable_isConcurrent: true,
310+
isConcurrent: true,
311311
});
312312
},
313313
);
@@ -469,7 +469,7 @@ describe('InspectedElement', () => {
469469
['An update to %s inside a test was not wrapped in act'],
470470
() => {
471471
testRendererInstance = TestRenderer.create(null, {
472-
unstable_isConcurrent: true,
472+
isConcurrent: true,
473473
});
474474
},
475475
);
@@ -2034,7 +2034,7 @@ describe('InspectedElement', () => {
20342034
['An update to %s inside a test was not wrapped in act'],
20352035
() => {
20362036
testRendererInstance = TestRenderer.create(null, {
2037-
unstable_isConcurrent: true,
2037+
isConcurrent: true,
20382038
});
20392039
},
20402040
);
@@ -2317,7 +2317,7 @@ describe('InspectedElement', () => {
23172317
<Suspender target={id} />
23182318
</React.Suspense>
23192319
</Contexts>,
2320-
{unstable_isConcurrent: true},
2320+
{isConcurrent: true},
23212321
);
23222322
}, false);
23232323
await utils.actAsync(() => {
@@ -2817,7 +2817,7 @@ describe('InspectedElement', () => {
28172817
['An update to %s inside a test was not wrapped in act'],
28182818
() => {
28192819
testRendererInstance = TestRenderer.create(null, {
2820-
unstable_isConcurrent: true,
2820+
isConcurrent: true,
28212821
});
28222822
},
28232823
);

packages/react-reconciler/src/__tests__/DebugTracing-test.internal.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ describe('DebugTracing', () => {
6767
<React.unstable_DebugTracingMode>
6868
<div />
6969
</React.unstable_DebugTracingMode>,
70-
{unstable_isConcurrent: true},
70+
{isConcurrent: true},
7171
),
7272
);
7373
expect(logs).toEqual([]);
@@ -179,7 +179,7 @@ describe('DebugTracing', () => {
179179
<Example />
180180
</React.Suspense>
181181
</React.unstable_DebugTracingMode>,
182-
{unstable_isConcurrent: true},
182+
{isConcurrent: true},
183183
),
184184
);
185185

@@ -216,7 +216,7 @@ describe('DebugTracing', () => {
216216
</React.Suspense>
217217
</Wrapper>
218218
</React.unstable_DebugTracingMode>,
219-
{unstable_isConcurrent: true},
219+
{isConcurrent: true},
220220
),
221221
);
222222

@@ -247,7 +247,7 @@ describe('DebugTracing', () => {
247247
<React.unstable_DebugTracingMode>
248248
<Example />
249249
</React.unstable_DebugTracingMode>,
250-
{unstable_isConcurrent: true},
250+
{isConcurrent: true},
251251
),
252252
);
253253

@@ -278,7 +278,7 @@ describe('DebugTracing', () => {
278278
<React.unstable_DebugTracingMode>
279279
<Example />
280280
</React.unstable_DebugTracingMode>,
281-
{unstable_isConcurrent: true},
281+
{isConcurrent: true},
282282
),
283283
);
284284
}).toErrorDev('Cannot update during an existing state transition');
@@ -305,7 +305,7 @@ describe('DebugTracing', () => {
305305
<React.unstable_DebugTracingMode>
306306
<Example />
307307
</React.unstable_DebugTracingMode>,
308-
{unstable_isConcurrent: true},
308+
{isConcurrent: true},
309309
),
310310
);
311311

@@ -333,7 +333,7 @@ describe('DebugTracing', () => {
333333
<React.unstable_DebugTracingMode>
334334
<Example />
335335
</React.unstable_DebugTracingMode>,
336-
{unstable_isConcurrent: true},
336+
{isConcurrent: true},
337337
);
338338
});
339339
expect(logs).toEqual([
@@ -358,7 +358,7 @@ describe('DebugTracing', () => {
358358
<React.unstable_DebugTracingMode>
359359
<Example />
360360
</React.unstable_DebugTracingMode>,
361-
{unstable_isConcurrent: true},
361+
{isConcurrent: true},
362362
);
363363
});
364364

@@ -381,7 +381,7 @@ describe('DebugTracing', () => {
381381
<React.unstable_DebugTracingMode>
382382
<Example />
383383
</React.unstable_DebugTracingMode>,
384-
{unstable_isConcurrent: true},
384+
{isConcurrent: true},
385385
),
386386
);
387387

packages/react-reconciler/src/__tests__/ErrorBoundaryReconciliation-test.internal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ describe('ErrorBoundaryReconciliation', () => {
5959
<ErrorBoundary fallbackTagName={fallbackTagName}>
6060
<BrokenRender fail={false} />
6161
</ErrorBoundary>,
62-
{unstable_isConcurrent: isConcurrent},
62+
{isConcurrent: isConcurrent},
6363
);
6464
});
6565
expect(renderer).toMatchRenderedOutput(<span prop="BrokenRender" />);

packages/react-reconciler/src/__tests__/ReactHooks-test.internal.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ describe('ReactHooks', () => {
8686
return <Child text={text} />;
8787
}
8888

89-
const root = ReactTestRenderer.create(null, {unstable_isConcurrent: true});
89+
const root = ReactTestRenderer.create(null, {isConcurrent: true});
9090
root.update(<Parent />);
9191
await waitForAll(['Parent: 0, 0', 'Child: 0, 0', 'Effect: 0, 0']);
9292
expect(root).toMatchRenderedOutput('0, 0');
@@ -174,7 +174,7 @@ describe('ReactHooks', () => {
174174

175175
Parent = memo(Parent);
176176

177-
const root = ReactTestRenderer.create(null, {unstable_isConcurrent: true});
177+
const root = ReactTestRenderer.create(null, {isConcurrent: true});
178178
root.update(<Parent theme="light" />);
179179
await waitForAll(['Parent: 0, 0 (light)', 'Child: 0, 0 (light)']);
180180
expect(root).toMatchRenderedOutput('0, 0 (light)');
@@ -232,7 +232,7 @@ describe('ReactHooks', () => {
232232
return counter;
233233
}
234234

235-
const root = ReactTestRenderer.create(null, {unstable_isConcurrent: true});
235+
const root = ReactTestRenderer.create(null, {isConcurrent: true});
236236
root.update(<Counter />);
237237
await waitForAll(['Count: 0']);
238238
expect(root).toMatchRenderedOutput('0');
@@ -266,7 +266,7 @@ describe('ReactHooks', () => {
266266
return counter;
267267
}
268268

269-
const root = ReactTestRenderer.create(null, {unstable_isConcurrent: true});
269+
const root = ReactTestRenderer.create(null, {isConcurrent: true});
270270
root.update(<Counter />);
271271
await waitForAll(['Count: 0']);
272272
expect(root).toMatchRenderedOutput('0');
@@ -322,7 +322,7 @@ describe('ReactHooks', () => {
322322
});
323323
return <Child text={text} />;
324324
}
325-
const root = ReactTestRenderer.create(null, {unstable_isConcurrent: true});
325+
const root = ReactTestRenderer.create(null, {isConcurrent: true});
326326
await act(() => {
327327
root.update(
328328
<ThemeProvider>
@@ -390,7 +390,7 @@ describe('ReactHooks', () => {
390390
return <Child text={counter} />;
391391
}
392392

393-
const root = ReactTestRenderer.create(null, {unstable_isConcurrent: true});
393+
const root = ReactTestRenderer.create(null, {isConcurrent: true});
394394
root.update(<Parent />);
395395
await waitForAll(['Parent: 0', 'Child: 0', 'Effect: 0']);
396396
expect(root).toMatchRenderedOutput('0');
@@ -465,7 +465,7 @@ describe('ReactHooks', () => {
465465
return <Child text={counter} />;
466466
}
467467

468-
const root = ReactTestRenderer.create(null, {unstable_isConcurrent: true});
468+
const root = ReactTestRenderer.create(null, {isConcurrent: true});
469469
root.update(<Parent />);
470470
await waitForAll(['Parent: 0', 'Child: 0']);
471471
expect(root).toMatchRenderedOutput('0');
@@ -523,7 +523,7 @@ describe('ReactHooks', () => {
523523
return <Child text={counter} />;
524524
}
525525

526-
const root = ReactTestRenderer.create(null, {unstable_isConcurrent: true});
526+
const root = ReactTestRenderer.create(null, {isConcurrent: true});
527527
root.update(<Parent />);
528528
await waitForAll(['Parent: 1', 'Child: 1']);
529529
expect(root).toMatchRenderedOutput('1');

0 commit comments

Comments
 (0)