Skip to content

Commit

Permalink
Enable RTR create warning
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack Pope committed Mar 6, 2024
1 parent 0066e0b commit b0853ad
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
4 changes: 1 addition & 3 deletions packages/shared/ReactFeatureFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/forks/ReactFeatureFlags.test-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
6 changes: 6 additions & 0 deletions scripts/jest/setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions scripts/jest/shouldIgnoreConsoleWarn.js
Original file line number Diff line number Diff line change
@@ -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;
};

0 comments on commit b0853ad

Please sign in to comment.