@samitouri / QOS-React-1 / commits / f73d11f092

[RTR] Enable warning flag (#28419)

## Summary Based on - https://github.com/facebook/react/pull/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`

Jack Pope committed Mar 26, 2024 at 17:44 UTC f73d11f0923ace72b867bec6a9f48930c3a4b9b6
8 files changed +45 -12
packages/react-devtools-shared/src/__tests__/setupTests.js
+3 -1
@@ -129,7 +129,9 @@ beforeEach(() => {
129 jest.useFakeTimers();
130
131 // Use utils.js#withErrorsOrWarningsIgnored instead of directly mutating this array.
132 - global._ignoredErrorOrWarningMessages = [];
132 + global._ignoredErrorOrWarningMessages = [
133 + 'react-test-renderer is deprecated.',
134 + ];
135 function shouldIgnoreConsoleErrorOrWarn(args) {
136 let firstArg = args[0];
137 if (
packages/react-devtools-shared/src/__tests__/treeContext-test.js
+6 -6
@@ -2586,14 +2586,14 @@ describe('TreeListContext', () => {
2586 utils.act(() => TestRenderer.create(<Contexts />));
2587
2588 expect(store).toMatchInlineSnapshot(`
2589 - ✕ 1, ⚠ 0
2589 + ✕ 1, ⚠ 1
2590 [root]
2591 <ErrorBoundary> ✕
2592 `);
2593
2594 selectNextErrorOrWarning();
2595 expect(state).toMatchInlineSnapshot(`
2596 - ✕ 1, ⚠ 0
2596 + ✕ 1, ⚠ 1
2597 [root]
2598 → <ErrorBoundary> ✕
2599 `);
@@ -2648,14 +2648,14 @@ describe('TreeListContext', () => {
2648 utils.act(() => TestRenderer.create(<Contexts />));
2649
2650 expect(store).toMatchInlineSnapshot(`
2651 - ✕ 1, ⚠ 0
2651 + ✕ 1, ⚠ 1
2652 [root]
2653 <ErrorBoundary> ✕
2654 `);
2655
2656 selectNextErrorOrWarning();
2657 expect(state).toMatchInlineSnapshot(`
2658 - ✕ 1, ⚠ 0
2658 + ✕ 1, ⚠ 1
2659 [root]
2660 → <ErrorBoundary> ✕
2661 `);
@@ -2705,7 +2705,7 @@ describe('TreeListContext', () => {
2705 utils.act(() => TestRenderer.create(<Contexts />));
2706
2707 expect(store).toMatchInlineSnapshot(`
2708 - ✕ 2, ⚠ 0
2708 + ✕ 2, ⚠ 1
2709 [root]
2710 ▾ <ErrorBoundary> ✕
2711 <Child> ✕
@@ -2713,7 +2713,7 @@ describe('TreeListContext', () => {
2713
2714 selectNextErrorOrWarning();
2715 expect(state).toMatchInlineSnapshot(`
2716 - ✕ 2, ⚠ 0
2716 + ✕ 2, ⚠ 1
2717 [root]
2718 → ▾ <ErrorBoundary> ✕
2719 <Child> ✕
packages/react-test-renderer/src/ReactTestRenderer.js
+4 -1
@@ -474,7 +474,10 @@ function create(
474 unstable_flushSync: typeof flushSync,
475 } {
476 if (__DEV__) {
477 - if (enableReactTestRendererWarning === true) {
477 + if (
478 + enableReactTestRendererWarning === true &&
479 + global.IS_REACT_NATIVE_TEST_ENVIRONMENT !== true
480 + ) {
481 console.warn(
482 'react-test-renderer is deprecated. See https://react.dev/warnings/react-test-renderer',
483 );
packages/react-test-renderer/src/__tests__/ReactTestRenderer-test.internal.js
+13
@@ -65,6 +65,19 @@ describe('ReactTestRenderer', () => {
65 );
66 });
67
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 +
81 it('renders a simple component', () => {
82 function Link() {
83 return <a role="link" />;
packages/shared/ReactFeatureFlags.js
+1 -3
@@ -183,10 +183,8 @@ export const enableInfiniteRenderLoopDetection = true;
183 export const enableRefAsProp = __NEXT_MAJOR__;
184 export const disableStringRefs = __NEXT_MAJOR__;
185
186 -// Not ready to break experimental yet.
187 -// Needs more internal cleanup
186 // Warn on any usage of ReactTestRenderer
189 -export const enableReactTestRendererWarning = false;
187 +export const enableReactTestRendererWarning = __NEXT_MAJOR__;
188
189 // Disables legacy mode
190 // This allows us to land breaking changes to remove legacy mode APIs in experimental builds
packages/shared/forks/ReactFeatureFlags.test-renderer.js
+1 -1
@@ -90,13 +90,13 @@ export const enableInfiniteRenderLoopDetection = false;
90 const __NEXT_MAJOR__ = __EXPERIMENTAL__;
91 export const enableRefAsProp = __NEXT_MAJOR__;
92 export const disableStringRefs = __NEXT_MAJOR__;
93 -export const enableReactTestRendererWarning = false;
93 export const enableBigIntSupport = __NEXT_MAJOR__;
94 export const disableLegacyMode = __NEXT_MAJOR__;
95 export const disableLegacyContext = __NEXT_MAJOR__;
96 export const enableNewBooleanProps = __NEXT_MAJOR__;
97 export const disableModulePatternComponents = __NEXT_MAJOR__;
98 export const enableRenderableContext = __NEXT_MAJOR__;
99 +export const enableReactTestRendererWarning = __NEXT_MAJOR__;
100
101 // Flow magic to verify the exports of this file match the original version.
102 ((((null: any): ExportsType): FeatureFlagsType): ExportsType);
scripts/jest/setupTests.js
+6
@@ -3,6 +3,7 @@
3 const chalk = require('chalk');
4 const util = require('util');
5 const shouldIgnoreConsoleError = require('./shouldIgnoreConsoleError');
6 +const shouldIgnoreConsoleWarn = require('./shouldIgnoreConsoleWarn');
7 const {getTestFlags} = require('./TestFlags');
8
9 if (process.env.REACT_CLASS_EQUIVALENCE_TEST) {
@@ -71,6 +72,11 @@ if (process.env.REACT_CLASS_EQUIVALENCE_TEST) {
72 return;
73 }
74
75 + // Ignore certain React warnings causing test failures
76 + if (methodName === 'warn' && shouldIgnoreConsoleWarn(format)) {
77 + return;
78 + }
79 +
80 // Capture the call stack now so we can warn about it later.
81 // The call stack has helpful information for the test author.
82 // Don't throw yet though b'c it might be accidentally caught and suppressed.
scripts/jest/shouldIgnoreConsoleWarn.js new
+11
@@ -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 +};