Skip to content

Commit

Permalink
Add stable concurrent option to react-test-renderer (#27804)
Browse files Browse the repository at this point in the history
## 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`
  • Loading branch information
jackpope authored Dec 7, 2023
1 parent be8aa76 commit b36ae8d
Show file tree
Hide file tree
Showing 15 changed files with 107 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe('ReactCache', () => {
}

ReactTestRenderer.create(<App />, {
unstable_isConcurrent: true,
isConcurrent: true,
});

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

const root = ReactTestRenderer.create(<App />, {
unstable_isConcurrent: true,
isConcurrent: true,
});

await waitForAll(['Suspend! [Hi]', 'Loading...']);
Expand Down Expand Up @@ -181,7 +181,7 @@ describe('ReactCache', () => {
<App />
</Suspense>,
{
unstable_isConcurrent: true,
isConcurrent: true,
},
);

Expand Down Expand Up @@ -210,7 +210,7 @@ describe('ReactCache', () => {
<AsyncText ms={100} text={3} />
</Suspense>,
{
unstable_isConcurrent: true,
isConcurrent: true,
},
);
await waitForAll(['Suspend! [1]', 'Loading...']);
Expand Down Expand Up @@ -298,7 +298,7 @@ describe('ReactCache', () => {
<App />
</Suspense>,
{
unstable_isConcurrent: true,
isConcurrent: true,
},
);

Expand Down Expand Up @@ -356,7 +356,7 @@ describe('ReactCache', () => {
<BadAsyncText text="Hi" />
</Suspense>,
{
unstable_isConcurrent: true,
isConcurrent: true,
},
);

Expand All @@ -372,7 +372,7 @@ describe('ReactCache', () => {
<BadAsyncText text="Hi" />
</Suspense>,
{
unstable_isConcurrent: true,
isConcurrent: true,
},
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ describe('React hooks DevTools integration', () => {
<MyComponent />
</React.Suspense>
</div>,
{unstable_isConcurrent: true},
{isConcurrent: true},
),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('InspectedElement', () => {
// Used by inspectElementAtIndex() helper function
utils.act(() => {
testRendererInstance = TestRenderer.create(null, {
unstable_isConcurrent: true,
isConcurrent: true,
});
});

Expand Down Expand Up @@ -307,7 +307,7 @@ describe('InspectedElement', () => {
['An update to %s inside a test was not wrapped in act'],
() => {
testRendererInstance = TestRenderer.create(null, {
unstable_isConcurrent: true,
isConcurrent: true,
});
},
);
Expand Down Expand Up @@ -469,7 +469,7 @@ describe('InspectedElement', () => {
['An update to %s inside a test was not wrapped in act'],
() => {
testRendererInstance = TestRenderer.create(null, {
unstable_isConcurrent: true,
isConcurrent: true,
});
},
);
Expand Down Expand Up @@ -2034,7 +2034,7 @@ describe('InspectedElement', () => {
['An update to %s inside a test was not wrapped in act'],
() => {
testRendererInstance = TestRenderer.create(null, {
unstable_isConcurrent: true,
isConcurrent: true,
});
},
);
Expand Down Expand Up @@ -2317,7 +2317,7 @@ describe('InspectedElement', () => {
<Suspender target={id} />
</React.Suspense>
</Contexts>,
{unstable_isConcurrent: true},
{isConcurrent: true},
);
}, false);
await utils.actAsync(() => {
Expand Down Expand Up @@ -2817,7 +2817,7 @@ describe('InspectedElement', () => {
['An update to %s inside a test was not wrapped in act'],
() => {
testRendererInstance = TestRenderer.create(null, {
unstable_isConcurrent: true,
isConcurrent: true,
});
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('DebugTracing', () => {
<React.unstable_DebugTracingMode>
<div />
</React.unstable_DebugTracingMode>,
{unstable_isConcurrent: true},
{isConcurrent: true},
),
);
expect(logs).toEqual([]);
Expand Down Expand Up @@ -179,7 +179,7 @@ describe('DebugTracing', () => {
<Example />
</React.Suspense>
</React.unstable_DebugTracingMode>,
{unstable_isConcurrent: true},
{isConcurrent: true},
),
);

Expand Down Expand Up @@ -216,7 +216,7 @@ describe('DebugTracing', () => {
</React.Suspense>
</Wrapper>
</React.unstable_DebugTracingMode>,
{unstable_isConcurrent: true},
{isConcurrent: true},
),
);

Expand Down Expand Up @@ -247,7 +247,7 @@ describe('DebugTracing', () => {
<React.unstable_DebugTracingMode>
<Example />
</React.unstable_DebugTracingMode>,
{unstable_isConcurrent: true},
{isConcurrent: true},
),
);

Expand Down Expand Up @@ -278,7 +278,7 @@ describe('DebugTracing', () => {
<React.unstable_DebugTracingMode>
<Example />
</React.unstable_DebugTracingMode>,
{unstable_isConcurrent: true},
{isConcurrent: true},
),
);
}).toErrorDev('Cannot update during an existing state transition');
Expand All @@ -305,7 +305,7 @@ describe('DebugTracing', () => {
<React.unstable_DebugTracingMode>
<Example />
</React.unstable_DebugTracingMode>,
{unstable_isConcurrent: true},
{isConcurrent: true},
),
);

Expand Down Expand Up @@ -333,7 +333,7 @@ describe('DebugTracing', () => {
<React.unstable_DebugTracingMode>
<Example />
</React.unstable_DebugTracingMode>,
{unstable_isConcurrent: true},
{isConcurrent: true},
);
});
expect(logs).toEqual([
Expand All @@ -358,7 +358,7 @@ describe('DebugTracing', () => {
<React.unstable_DebugTracingMode>
<Example />
</React.unstable_DebugTracingMode>,
{unstable_isConcurrent: true},
{isConcurrent: true},
);
});

Expand All @@ -381,7 +381,7 @@ describe('DebugTracing', () => {
<React.unstable_DebugTracingMode>
<Example />
</React.unstable_DebugTracingMode>,
{unstable_isConcurrent: true},
{isConcurrent: true},
),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('ErrorBoundaryReconciliation', () => {
<ErrorBoundary fallbackTagName={fallbackTagName}>
<BrokenRender fail={false} />
</ErrorBoundary>,
{unstable_isConcurrent: isConcurrent},
{isConcurrent: isConcurrent},
);
});
expect(renderer).toMatchRenderedOutput(<span prop="BrokenRender" />);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('ReactHooks', () => {
return <Child text={text} />;
}

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

Parent = memo(Parent);

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

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

const root = ReactTestRenderer.create(null, {unstable_isConcurrent: true});
const root = ReactTestRenderer.create(null, {isConcurrent: true});
root.update(<Counter />);
await waitForAll(['Count: 0']);
expect(root).toMatchRenderedOutput('0');
Expand Down Expand Up @@ -322,7 +322,7 @@ describe('ReactHooks', () => {
});
return <Child text={text} />;
}
const root = ReactTestRenderer.create(null, {unstable_isConcurrent: true});
const root = ReactTestRenderer.create(null, {isConcurrent: true});
await act(() => {
root.update(
<ThemeProvider>
Expand Down Expand Up @@ -390,7 +390,7 @@ describe('ReactHooks', () => {
return <Child text={counter} />;
}

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

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

const root = ReactTestRenderer.create(null, {unstable_isConcurrent: true});
const root = ReactTestRenderer.create(null, {isConcurrent: true});
root.update(<Parent />);
await waitForAll(['Parent: 1', 'Child: 1']);
expect(root).toMatchRenderedOutput('1');
Expand Down
Loading

0 comments on commit b36ae8d

Please sign in to comment.