warn -> error for Test Renderer deprecation (#28904)
We use `console.error` for deprecations. `console.warn` is for less critical issues, like performance anti-patterns.
Andrew Clark committed
Apr 24, 2024 at 14:54 UTC
c516cefc7dbb717f50bcb53de83591b1ef9d93ac
8 files changed
+32
-42
packages/internal-test-utils/shouldIgnoreConsoleError.js
+2
-1
@@ -23,7 +23,8 @@ module.exports = function shouldIgnoreConsoleError(format, args) {
23
) !== -1 ||
24
format.indexOf(
25
'ReactDOM.hydrate has not been supported since React 18',
26
- ) !== -1
26
+ ) !== -1 ||
27
+ format.indexOf('react-test-renderer is deprecated.') !== -1
28
) {
29
// We haven't finished migrating our tests to use createRoot.
30
return true;
packages/internal-test-utils/shouldIgnoreConsoleWarn.js
-6
@@ -1,11 +1,5 @@
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
-
4
return false;
5
};
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, ⚠ 1
2589
+ ✕ 2, ⚠ 0
2590
[root]
2591
<ErrorBoundary> ✕
2592
`);
2593
2594
selectNextErrorOrWarning();
2595
expect(state).toMatchInlineSnapshot(`
2596
- ✕ 1, ⚠ 1
2596
+ ✕ 2, ⚠ 0
2597
[root]
2598
→ <ErrorBoundary> ✕
2599
`);
@@ -2648,14 +2648,14 @@ describe('TreeListContext', () => {
2648
utils.act(() => TestRenderer.create(<Contexts />));
2649
2650
expect(store).toMatchInlineSnapshot(`
2651
- ✕ 1, ⚠ 1
2651
+ ✕ 2, ⚠ 0
2652
[root]
2653
<ErrorBoundary> ✕
2654
`);
2655
2656
selectNextErrorOrWarning();
2657
expect(state).toMatchInlineSnapshot(`
2658
- ✕ 1, ⚠ 1
2658
+ ✕ 2, ⚠ 0
2659
[root]
2660
→ <ErrorBoundary> ✕
2661
`);
@@ -2705,7 +2705,7 @@ describe('TreeListContext', () => {
2705
utils.act(() => TestRenderer.create(<Contexts />));
2706
2707
expect(store).toMatchInlineSnapshot(`
2708
- ✕ 2, ⚠ 1
2708
+ ✕ 3, ⚠ 0
2709
[root]
2710
▾ <ErrorBoundary> ✕
2711
<Child> ✕
@@ -2713,7 +2713,7 @@ describe('TreeListContext', () => {
2713
2714
selectNextErrorOrWarning();
2715
expect(state).toMatchInlineSnapshot(`
2716
- ✕ 2, ⚠ 1
2716
+ ✕ 3, ⚠ 0
2717
[root]
2718
→ ▾ <ErrorBoundary> ✕
2719
<Child> ✕
packages/react-devtools-shell/src/app/index.js
+1
@@ -31,6 +31,7 @@ ignoreErrors([
31
'Warning: Unsafe lifecycle methods',
32
'Warning: %s is deprecated in StrictMode.', // findDOMNode
33
'Warning: ReactDOM.render was removed in React 19',
34
+ 'Warning: react-test-renderer is deprecated',
35
]);
36
ignoreWarnings(['Warning: componentWillReceiveProps has been renamed']);
37
ignoreLogs([]);
packages/react-reconciler/src/__tests__/ReactHooks-test.internal.js
+6
-9
@@ -19,6 +19,7 @@ let Scheduler;
19
let ReactDOMServer;
20
let act;
21
let assertLog;
22
+let assertConsoleErrorDev;
23
let waitForAll;
24
let waitForThrow;
25
@@ -35,6 +36,7 @@ describe('ReactHooks', () => {
36
37
const InternalTestUtils = require('internal-test-utils');
38
assertLog = InternalTestUtils.assertLog;
39
+ assertConsoleErrorDev = InternalTestUtils.assertConsoleErrorDev;
40
waitForAll = InternalTestUtils.waitForAll;
41
waitForThrow = InternalTestUtils.waitForThrow;
42
});
@@ -1810,7 +1812,6 @@ describe('ReactHooks', () => {
1812
// Regression test for #14674
1813
it('does not swallow original error when updating another component in render phase', async () => {
1814
const {useState} = React;
1813
- spyOnDev(console, 'error').mockImplementation(() => {});
1815
1816
let _setState;
1817
function A() {
@@ -1837,14 +1838,10 @@ describe('ReactHooks', () => {
1838
);
1839
});
1840
}).rejects.toThrow('Hello');
1840
-
1841
- if (__DEV__) {
1842
- expect(console.error).toHaveBeenCalledTimes(1);
1843
- expect(console.error.mock.calls[0][0]).toContain(
1844
- 'Warning: Cannot update a component (`%s`) while rendering ' +
1845
- 'a different component (`%s`).',
1846
- );
1847
- }
1841
+ assertConsoleErrorDev([
1842
+ 'Warning: Cannot update a component (`A`) while rendering ' +
1843
+ 'a different component (`B`).',
1844
+ ]);
1845
});
1846
1847
// Regression test for https://github.com/facebook/react/issues/15057
packages/react-reconciler/src/__tests__/ReactLazy-test.internal.js
+6
-8
@@ -7,6 +7,7 @@ let waitFor;
7
let waitForAll;
8
let waitForThrow;
9
let assertLog;
10
+let assertConsoleErrorDev;
11
let act;
12
13
let fakeModuleCache;
@@ -34,6 +35,7 @@ describe('ReactLazy', () => {
35
waitForAll = InternalTestUtils.waitForAll;
36
waitForThrow = InternalTestUtils.waitForThrow;
37
assertLog = InternalTestUtils.assertLog;
38
+ assertConsoleErrorDev = InternalTestUtils.assertConsoleErrorDev;
39
act = InternalTestUtils.act;
40
41
fakeModuleCache = new Map();
@@ -205,8 +207,6 @@ describe('ReactLazy', () => {
207
});
208
209
it('does not support arbitrary promises, only module objects', async () => {
208
- spyOnDev(console, 'error').mockImplementation(() => {});
209
-
210
const LazyText = lazy(async () => Text);
211
212
const root = ReactTestRenderer.create(null, {
@@ -228,13 +228,11 @@ describe('ReactLazy', () => {
228
229
expect(error.message).toMatch('Element type is invalid');
230
assertLog(['Loading...']);
231
+ assertConsoleErrorDev([
232
+ 'Expected the result of a dynamic import() call',
233
+ 'Expected the result of a dynamic import() call',
234
+ ]);
235
expect(root).not.toMatchRenderedOutput('Hi');
232
- if (__DEV__) {
233
- expect(console.error).toHaveBeenCalledTimes(2);
234
- expect(console.error.mock.calls[0][0]).toContain(
235
- 'Expected the result of a dynamic import() call',
236
- );
237
- }
236
});
237
238
it('throws if promise rejects', async () => {
packages/react-test-renderer/src/ReactTestRenderer.js
+1
-1
@@ -475,7 +475,7 @@ function create(
475
enableReactTestRendererWarning === true &&
476
global.IS_REACT_NATIVE_TEST_ENVIRONMENT !== true
477
) {
478
- console.warn(
478
+ console.error(
479
'react-test-renderer is deprecated. See https://react.dev/warnings/react-test-renderer',
480
);
481
}
packages/react-test-renderer/src/__tests__/ReactTestRenderer-test.internal.js
+10
-11
@@ -60,26 +60,25 @@ describe('ReactTestRenderer', () => {
60
ReactFeatureFlags.enableReactTestRendererWarning = false;
61
});
62
63
+ // @gate __DEV__
64
it('should warn if enableReactTestRendererWarning is enabled', () => {
65
+ jest.spyOn(console, 'error').mockImplementation(() => {});
66
ReactFeatureFlags.enableReactTestRendererWarning = true;
65
- expect(() => {
66
- ReactTestRenderer.create(<div />);
67
- }).toWarnDev(
67
+ ReactTestRenderer.create(<div />);
68
+ expect(console.error).toHaveBeenCalledTimes(1);
69
+ expect(console.error.mock.calls[0][0]).toContain(
70
'Warning: react-test-renderer is deprecated. See https://react.dev/warnings/react-test-renderer',
69
- {withoutStack: true},
71
);
72
+ console.error.mockRestore();
73
});
74
73
- // @gate __DEV__
75
it('should not warn if enableReactTestRendererWarning is enabled but the RN global is set', () => {
76
+ jest.spyOn(console, 'error').mockImplementation(() => {});
77
global.IS_REACT_NATIVE_TEST_ENVIRONMENT = true;
78
ReactFeatureFlags.enableReactTestRendererWarning = true;
77
- expect(() => {
78
- ReactTestRenderer.create(<div />);
79
- }).not.toWarnDev(
80
- 'Warning: react-test-renderer is deprecated. See https://react.dev/warnings/react-test-renderer',
81
- {withoutStack: true},
82
- );
79
+ ReactTestRenderer.create(<div />);
80
+ expect(console.error).toHaveBeenCalledTimes(0);
81
+ console.error.mockRestore();
82
});
83
84
describe('root tags', () => {