From b0853ad4d322b323cf453cf44511660fbc7014ed Mon Sep 17 00:00:00 2001 From: Jack Pope Date: Thu, 22 Feb 2024 12:27:42 -0500 Subject: [PATCH] Enable RTR create warning --- packages/shared/ReactFeatureFlags.js | 4 +--- .../shared/forks/ReactFeatureFlags.test-renderer.js | 2 +- scripts/jest/setupTests.js | 6 ++++++ scripts/jest/shouldIgnoreConsoleWarn.js | 11 +++++++++++ 4 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 scripts/jest/shouldIgnoreConsoleWarn.js diff --git a/packages/shared/ReactFeatureFlags.js b/packages/shared/ReactFeatureFlags.js index 506f6746b98de..79a4433d184da 100644 --- a/packages/shared/ReactFeatureFlags.js +++ b/packages/shared/ReactFeatureFlags.js @@ -190,10 +190,8 @@ export const enableInfiniteRenderLoopDetection = true; export const enableRefAsProp = __NEXT_MAJOR__; export const disableStringRefs = __NEXT_MAJOR__; -// Not ready to break experimental yet. -// Needs more internal cleanup // Warn on any usage of ReactTestRenderer -export const enableReactTestRendererWarning = false; +export const enableReactTestRendererWarning = __NEXT_MAJOR__; // Disables legacy mode // This allows us to land breaking changes to remove legacy mode APIs in experimental builds diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.js index 60e53b3fb3315..352802586e014 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.js @@ -99,9 +99,9 @@ export const enableInfiniteRenderLoopDetection = false; const __NEXT_MAJOR__ = __EXPERIMENTAL__; export const enableRefAsProp = __NEXT_MAJOR__; export const disableStringRefs = __NEXT_MAJOR__; -export const enableReactTestRendererWarning = false; export const enableBigIntSupport = __NEXT_MAJOR__; export const disableLegacyMode = __NEXT_MAJOR__; +export const enableReactTestRendererWarning = __NEXT_MAJOR__; // Flow magic to verify the exports of this file match the original version. ((((null: any): ExportsType): FeatureFlagsType): ExportsType); diff --git a/scripts/jest/setupTests.js b/scripts/jest/setupTests.js index 0d23861568fe4..4baf12f2caf92 100644 --- a/scripts/jest/setupTests.js +++ b/scripts/jest/setupTests.js @@ -3,6 +3,7 @@ const chalk = require('chalk'); const util = require('util'); const shouldIgnoreConsoleError = require('./shouldIgnoreConsoleError'); +const shouldIgnoreConsoleWarn = require('./shouldIgnoreConsoleWarn'); const {getTestFlags} = require('./TestFlags'); if (process.env.REACT_CLASS_EQUIVALENCE_TEST) { @@ -71,6 +72,11 @@ if (process.env.REACT_CLASS_EQUIVALENCE_TEST) { return; } + // Ignore certain React warnings causing test failures + if (methodName === 'warn' && shouldIgnoreConsoleWarn(format)) { + return; + } + // Capture the call stack now so we can warn about it later. // The call stack has helpful information for the test author. // Don't throw yet though b'c it might be accidentally caught and suppressed. diff --git a/scripts/jest/shouldIgnoreConsoleWarn.js b/scripts/jest/shouldIgnoreConsoleWarn.js new file mode 100644 index 0000000000000..9fa8414263bbc --- /dev/null +++ b/scripts/jest/shouldIgnoreConsoleWarn.js @@ -0,0 +1,11 @@ +'use strict'; + +module.exports = function shouldIgnoreConsoleWarn(format) { + if (typeof format === 'string') { + if (format.indexOf('Warning: react-test-renderer is deprecated.') === 0) { + return true; + } + } + + return false; +};