Skip to content

Commit f73d11f

Browse files
authored
[RTR] Enable warning flag (#28419)
## Summary Based on - #27903 This PR - Silence warning in React tests - Turn on flag We want to finish cleaning up internal RTR usage, but let's prioritize the deprecation process. We do this by silencing the internal warning for now. ## How did you test this change? `yarn build` `yarn test ReactHooksInspectionIntegration -b`
1 parent 670d61b commit f73d11f

File tree

8 files changed

+45
-12
lines changed

8 files changed

+45
-12
lines changed

packages/react-devtools-shared/src/__tests__/setupTests.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ beforeEach(() => {
129129
jest.useFakeTimers();
130130

131131
// Use utils.js#withErrorsOrWarningsIgnored instead of directly mutating this array.
132-
global._ignoredErrorOrWarningMessages = [];
132+
global._ignoredErrorOrWarningMessages = [
133+
'react-test-renderer is deprecated.',
134+
];
133135
function shouldIgnoreConsoleErrorOrWarn(args) {
134136
let firstArg = args[0];
135137
if (

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -2586,14 +2586,14 @@ describe('TreeListContext', () => {
25862586
utils.act(() => TestRenderer.create(<Contexts />));
25872587

25882588
expect(store).toMatchInlineSnapshot(`
2589-
✕ 1, ⚠ 0
2589+
✕ 1, ⚠ 1
25902590
[root]
25912591
<ErrorBoundary> ✕
25922592
`);
25932593

25942594
selectNextErrorOrWarning();
25952595
expect(state).toMatchInlineSnapshot(`
2596-
✕ 1, ⚠ 0
2596+
✕ 1, ⚠ 1
25972597
[root]
25982598
→ <ErrorBoundary> ✕
25992599
`);
@@ -2648,14 +2648,14 @@ describe('TreeListContext', () => {
26482648
utils.act(() => TestRenderer.create(<Contexts />));
26492649

26502650
expect(store).toMatchInlineSnapshot(`
2651-
✕ 1, ⚠ 0
2651+
✕ 1, ⚠ 1
26522652
[root]
26532653
<ErrorBoundary> ✕
26542654
`);
26552655

26562656
selectNextErrorOrWarning();
26572657
expect(state).toMatchInlineSnapshot(`
2658-
✕ 1, ⚠ 0
2658+
✕ 1, ⚠ 1
26592659
[root]
26602660
→ <ErrorBoundary> ✕
26612661
`);
@@ -2705,15 +2705,15 @@ describe('TreeListContext', () => {
27052705
utils.act(() => TestRenderer.create(<Contexts />));
27062706

27072707
expect(store).toMatchInlineSnapshot(`
2708-
✕ 2, ⚠ 0
2708+
✕ 2, ⚠ 1
27092709
[root]
27102710
▾ <ErrorBoundary> ✕
27112711
<Child> ✕
27122712
`);
27132713

27142714
selectNextErrorOrWarning();
27152715
expect(state).toMatchInlineSnapshot(`
2716-
✕ 2, ⚠ 0
2716+
✕ 2, ⚠ 1
27172717
[root]
27182718
→ ▾ <ErrorBoundary> ✕
27192719
<Child> ✕

packages/react-test-renderer/src/ReactTestRenderer.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,10 @@ function create(
474474
unstable_flushSync: typeof flushSync,
475475
} {
476476
if (__DEV__) {
477-
if (enableReactTestRendererWarning === true) {
477+
if (
478+
enableReactTestRendererWarning === true &&
479+
global.IS_REACT_NATIVE_TEST_ENVIRONMENT !== true
480+
) {
478481
console.warn(
479482
'react-test-renderer is deprecated. See https://react.dev/warnings/react-test-renderer',
480483
);

packages/react-test-renderer/src/__tests__/ReactTestRenderer-test.internal.js

+13
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@ describe('ReactTestRenderer', () => {
6565
);
6666
});
6767

68+
// @gate __DEV__
69+
it('should not warn if enableReactTestRendererWarning is enabled but the RN global is set', () => {
70+
global.IS_REACT_NATIVE_TEST_ENVIRONMENT = true;
71+
ReactFeatureFlags.enableReactTestRendererWarning = true;
72+
expect(() => {
73+
ReactTestRenderer.create(<div />);
74+
}).not.toWarnDev(
75+
'Warning: react-test-renderer is deprecated. See https://react.dev/warnings/react-test-renderer',
76+
{withoutStack: true},
77+
);
78+
global.IS_REACT_NATIVE_TEST_ENVIRONMENT = false;
79+
});
80+
6881
it('renders a simple component', () => {
6982
function Link() {
7083
return <a role="link" />;

packages/shared/ReactFeatureFlags.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,8 @@ export const enableInfiniteRenderLoopDetection = true;
183183
export const enableRefAsProp = __NEXT_MAJOR__;
184184
export const disableStringRefs = __NEXT_MAJOR__;
185185

186-
// Not ready to break experimental yet.
187-
// Needs more internal cleanup
188186
// Warn on any usage of ReactTestRenderer
189-
export const enableReactTestRendererWarning = false;
187+
export const enableReactTestRendererWarning = __NEXT_MAJOR__;
190188

191189
// Disables legacy mode
192190
// This allows us to land breaking changes to remove legacy mode APIs in experimental builds

packages/shared/forks/ReactFeatureFlags.test-renderer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ export const enableInfiniteRenderLoopDetection = false;
9090
const __NEXT_MAJOR__ = __EXPERIMENTAL__;
9191
export const enableRefAsProp = __NEXT_MAJOR__;
9292
export const disableStringRefs = __NEXT_MAJOR__;
93-
export const enableReactTestRendererWarning = false;
9493
export const enableBigIntSupport = __NEXT_MAJOR__;
9594
export const disableLegacyMode = __NEXT_MAJOR__;
9695
export const disableLegacyContext = __NEXT_MAJOR__;
9796
export const enableNewBooleanProps = __NEXT_MAJOR__;
9897
export const disableModulePatternComponents = __NEXT_MAJOR__;
9998
export const enableRenderableContext = __NEXT_MAJOR__;
99+
export const enableReactTestRendererWarning = __NEXT_MAJOR__;
100100

101101
// Flow magic to verify the exports of this file match the original version.
102102
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

scripts/jest/setupTests.js

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const chalk = require('chalk');
44
const util = require('util');
55
const shouldIgnoreConsoleError = require('./shouldIgnoreConsoleError');
6+
const shouldIgnoreConsoleWarn = require('./shouldIgnoreConsoleWarn');
67
const {getTestFlags} = require('./TestFlags');
78

89
if (process.env.REACT_CLASS_EQUIVALENCE_TEST) {
@@ -71,6 +72,11 @@ if (process.env.REACT_CLASS_EQUIVALENCE_TEST) {
7172
return;
7273
}
7374

75+
// Ignore certain React warnings causing test failures
76+
if (methodName === 'warn' && shouldIgnoreConsoleWarn(format)) {
77+
return;
78+
}
79+
7480
// Capture the call stack now so we can warn about it later.
7581
// The call stack has helpful information for the test author.
7682
// Don't throw yet though b'c it might be accidentally caught and suppressed.
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
module.exports = function shouldIgnoreConsoleWarn(format) {
4+
if (typeof format === 'string') {
5+
if (format.indexOf('Warning: react-test-renderer is deprecated.') === 0) {
6+
return true;
7+
}
8+
}
9+
10+
return false;
11+
};

0 commit comments

Comments
 (0)