Skip to content

Commit bf84bba

Browse files
author
Jack Pope
committed
Enable RTR create warning
1 parent e373190 commit bf84bba

File tree

8 files changed

+44
-12
lines changed

8 files changed

+44
-12
lines changed

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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 4 additions & 1 deletion
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
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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ describe('ReactTestRenderer', () => {
6565
);
6666
});
6767

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

packages/shared/ReactFeatureFlags.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,8 @@ export const enableInfiniteRenderLoopDetection = true;
188188
export const enableRefAsProp = __NEXT_MAJOR__;
189189
export const disableStringRefs = __NEXT_MAJOR__;
190190

191-
// Not ready to break experimental yet.
192-
// Needs more internal cleanup
193191
// Warn on any usage of ReactTestRenderer
194-
export const enableReactTestRendererWarning = false;
192+
export const enableReactTestRendererWarning = __NEXT_MAJOR__;
195193

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ export const enableInfiniteRenderLoopDetection = false;
9393
const __NEXT_MAJOR__ = __EXPERIMENTAL__;
9494
export const enableRefAsProp = __NEXT_MAJOR__;
9595
export const disableStringRefs = __NEXT_MAJOR__;
96-
export const enableReactTestRendererWarning = false;
9796
export const enableBigIntSupport = __NEXT_MAJOR__;
9897
export const disableLegacyMode = __NEXT_MAJOR__;
9998
export const disableLegacyContext = __NEXT_MAJOR__;
10099
export const enableNewBooleanProps = __NEXT_MAJOR__;
101100
export const disableModulePatternComponents = __NEXT_MAJOR__;
101+
export const enableReactTestRendererWarning = __NEXT_MAJOR__;
102102

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

scripts/jest/setupTests.js

Lines changed: 6 additions & 0 deletions
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.
Lines changed: 11 additions & 0 deletions
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)