Skip to content

Commit c516cef

Browse files
authoredApr 24, 2024··
warn -> error for Test Renderer deprecation (#28904)
We use `console.error` for deprecations. `console.warn` is for less critical issues, like performance anti-patterns.
1 parent cb15184 commit c516cef

File tree

8 files changed

+32
-42
lines changed

8 files changed

+32
-42
lines changed
 

‎packages/internal-test-utils/shouldIgnoreConsoleError.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ module.exports = function shouldIgnoreConsoleError(format, args) {
2323
) !== -1 ||
2424
format.indexOf(
2525
'ReactDOM.hydrate has not been supported since React 18',
26-
) !== -1
26+
) !== -1 ||
27+
format.indexOf('react-test-renderer is deprecated.') !== -1
2728
) {
2829
// We haven't finished migrating our tests to use createRoot.
2930
return true;
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
'use strict';
22

33
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-
104
return false;
115
};

‎packages/react-devtools-shared/src/__tests__/treeContext-test.js

+6-6
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, ⚠ 1
2589+
2, ⚠ 0
25902590
[root]
25912591
<ErrorBoundary> ✕
25922592
`);
25932593

25942594
selectNextErrorOrWarning();
25952595
expect(state).toMatchInlineSnapshot(`
2596-
1, ⚠ 1
2596+
2, ⚠ 0
25972597
[root]
25982598
→ <ErrorBoundary> ✕
25992599
`);
@@ -2648,14 +2648,14 @@ describe('TreeListContext', () => {
26482648
utils.act(() => TestRenderer.create(<Contexts />));
26492649

26502650
expect(store).toMatchInlineSnapshot(`
2651-
1, ⚠ 1
2651+
2, ⚠ 0
26522652
[root]
26532653
<ErrorBoundary> ✕
26542654
`);
26552655

26562656
selectNextErrorOrWarning();
26572657
expect(state).toMatchInlineSnapshot(`
2658-
1, ⚠ 1
2658+
2, ⚠ 0
26592659
[root]
26602660
→ <ErrorBoundary> ✕
26612661
`);
@@ -2705,15 +2705,15 @@ describe('TreeListContext', () => {
27052705
utils.act(() => TestRenderer.create(<Contexts />));
27062706

27072707
expect(store).toMatchInlineSnapshot(`
2708-
2, ⚠ 1
2708+
3, ⚠ 0
27092709
[root]
27102710
▾ <ErrorBoundary> ✕
27112711
<Child> ✕
27122712
`);
27132713

27142714
selectNextErrorOrWarning();
27152715
expect(state).toMatchInlineSnapshot(`
2716-
2, ⚠ 1
2716+
3, ⚠ 0
27172717
[root]
27182718
→ ▾ <ErrorBoundary> ✕
27192719
<Child> ✕

‎packages/react-devtools-shell/src/app/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ ignoreErrors([
3131
'Warning: Unsafe lifecycle methods',
3232
'Warning: %s is deprecated in StrictMode.', // findDOMNode
3333
'Warning: ReactDOM.render was removed in React 19',
34+
'Warning: react-test-renderer is deprecated',
3435
]);
3536
ignoreWarnings(['Warning: componentWillReceiveProps has been renamed']);
3637
ignoreLogs([]);

‎packages/react-reconciler/src/__tests__/ReactHooks-test.internal.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ let Scheduler;
1919
let ReactDOMServer;
2020
let act;
2121
let assertLog;
22+
let assertConsoleErrorDev;
2223
let waitForAll;
2324
let waitForThrow;
2425

@@ -35,6 +36,7 @@ describe('ReactHooks', () => {
3536

3637
const InternalTestUtils = require('internal-test-utils');
3738
assertLog = InternalTestUtils.assertLog;
39+
assertConsoleErrorDev = InternalTestUtils.assertConsoleErrorDev;
3840
waitForAll = InternalTestUtils.waitForAll;
3941
waitForThrow = InternalTestUtils.waitForThrow;
4042
});
@@ -1810,7 +1812,6 @@ describe('ReactHooks', () => {
18101812
// Regression test for #14674
18111813
it('does not swallow original error when updating another component in render phase', async () => {
18121814
const {useState} = React;
1813-
spyOnDev(console, 'error').mockImplementation(() => {});
18141815

18151816
let _setState;
18161817
function A() {
@@ -1837,14 +1838,10 @@ describe('ReactHooks', () => {
18371838
);
18381839
});
18391840
}).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+
]);
18481845
});
18491846

18501847
// Regression test for https://github.com/facebook/react/issues/15057

‎packages/react-reconciler/src/__tests__/ReactLazy-test.internal.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ let waitFor;
77
let waitForAll;
88
let waitForThrow;
99
let assertLog;
10+
let assertConsoleErrorDev;
1011
let act;
1112

1213
let fakeModuleCache;
@@ -34,6 +35,7 @@ describe('ReactLazy', () => {
3435
waitForAll = InternalTestUtils.waitForAll;
3536
waitForThrow = InternalTestUtils.waitForThrow;
3637
assertLog = InternalTestUtils.assertLog;
38+
assertConsoleErrorDev = InternalTestUtils.assertConsoleErrorDev;
3739
act = InternalTestUtils.act;
3840

3941
fakeModuleCache = new Map();
@@ -205,8 +207,6 @@ describe('ReactLazy', () => {
205207
});
206208

207209
it('does not support arbitrary promises, only module objects', async () => {
208-
spyOnDev(console, 'error').mockImplementation(() => {});
209-
210210
const LazyText = lazy(async () => Text);
211211

212212
const root = ReactTestRenderer.create(null, {
@@ -228,13 +228,11 @@ describe('ReactLazy', () => {
228228

229229
expect(error.message).toMatch('Element type is invalid');
230230
assertLog(['Loading...']);
231+
assertConsoleErrorDev([
232+
'Expected the result of a dynamic import() call',
233+
'Expected the result of a dynamic import() call',
234+
]);
231235
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-
}
238236
});
239237

240238
it('throws if promise rejects', async () => {

‎packages/react-test-renderer/src/ReactTestRenderer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ function create(
475475
enableReactTestRendererWarning === true &&
476476
global.IS_REACT_NATIVE_TEST_ENVIRONMENT !== true
477477
) {
478-
console.warn(
478+
console.error(
479479
'react-test-renderer is deprecated. See https://react.dev/warnings/react-test-renderer',
480480
);
481481
}

‎packages/react-test-renderer/src/__tests__/ReactTestRenderer-test.internal.js

+10-11
Original file line numberDiff line numberDiff line change
@@ -60,26 +60,25 @@ describe('ReactTestRenderer', () => {
6060
ReactFeatureFlags.enableReactTestRendererWarning = false;
6161
});
6262

63+
// @gate __DEV__
6364
it('should warn if enableReactTestRendererWarning is enabled', () => {
65+
jest.spyOn(console, 'error').mockImplementation(() => {});
6466
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(
6870
'Warning: react-test-renderer is deprecated. See https://react.dev/warnings/react-test-renderer',
69-
{withoutStack: true},
7071
);
72+
console.error.mockRestore();
7173
});
7274

73-
// @gate __DEV__
7475
it('should not warn if enableReactTestRendererWarning is enabled but the RN global is set', () => {
76+
jest.spyOn(console, 'error').mockImplementation(() => {});
7577
global.IS_REACT_NATIVE_TEST_ENVIRONMENT = true;
7678
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();
8382
});
8483

8584
describe('root tags', () => {

0 commit comments

Comments
 (0)
Please sign in to comment.