Skip to content

Commit

Permalink
warn -> error for Test Renderer deprecation
Browse files Browse the repository at this point in the history
We use `console.error` for deprecations. `console.warn` is for less
critical issues, like performance anti-patterns.
  • Loading branch information
acdlite committed Apr 24, 2024
1 parent cb15184 commit ab7322b
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 117 deletions.
3 changes: 2 additions & 1 deletion packages/internal-test-utils/shouldIgnoreConsoleError.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ module.exports = function shouldIgnoreConsoleError(format, args) {
) !== -1 ||
format.indexOf(
'ReactDOM.hydrate has not been supported since React 18',
) !== -1
) !== -1 ||
format.indexOf('react-test-renderer is deprecated.') !== -1
) {
// We haven't finished migrating our tests to use createRoot.
return true;
Expand Down
6 changes: 0 additions & 6 deletions packages/internal-test-utils/shouldIgnoreConsoleWarn.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
'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;
};

Large diffs are not rendered by default.

70 changes: 35 additions & 35 deletions packages/react-devtools-shared/src/__tests__/preprocessData-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -841,83 +841,83 @@ describe('Timeline profiler', () => {
{
"batchUID": 0,
"depth": 0,
"duration": 0.014,
"duration": 0.012,
"lanes": "0b0000000000000000000000000000101",
"timestamp": 0.008,
"timestamp": 0.006,
"type": "render-idle",
},
{
"batchUID": 0,
"depth": 0,
"duration": 0.003,
"lanes": "0b0000000000000000000000000000101",
"timestamp": 0.008,
"timestamp": 0.006,
"type": "render",
},
{
"batchUID": 0,
"depth": 0,
"duration": 0.010,
"duration": 0.008,
"lanes": "0b0000000000000000000000000000101",
"timestamp": 0.012,
"timestamp": 0.01,
"type": "commit",
},
{
"batchUID": 0,
"depth": 1,
"duration": 0.001,
"lanes": "0b0000000000000000000000000000101",
"timestamp": 0.02,
"timestamp": 0.016,
"type": "layout-effects",
},
{
"batchUID": 0,
"depth": 0,
"duration": 0.004,
"lanes": "0b0000000000000000000000000000101",
"timestamp": 0.023,
"timestamp": 0.019,
"type": "passive-effects",
},
],
1 => [
{
"batchUID": 1,
"depth": 0,
"duration": 0.014,
"duration": 0.012,
"lanes": "0b0000000000000000000000000000101",
"timestamp": 0.028,
"timestamp": 0.024,
"type": "render-idle",
},
{
"batchUID": 1,
"depth": 0,
"duration": 0.003,
"lanes": "0b0000000000000000000000000000101",
"timestamp": 0.028,
"timestamp": 0.024,
"type": "render",
},
{
"batchUID": 1,
"depth": 0,
"duration": 0.010,
"duration": 0.008,
"lanes": "0b0000000000000000000000000000101",
"timestamp": 0.032,
"timestamp": 0.028,
"type": "commit",
},
{
"batchUID": 1,
"depth": 1,
"duration": 0.001,
"lanes": "0b0000000000000000000000000000101",
"timestamp": 0.04,
"timestamp": 0.034,
"type": "layout-effects",
},
{
"batchUID": 1,
"depth": 0,
"duration": 0.003,
"lanes": "0b0000000000000000000000000000101",
"timestamp": 0.043,
"timestamp": 0.037,
"type": "passive-effects",
},
],
Expand All @@ -926,33 +926,33 @@ describe('Timeline profiler', () => {
{
"componentName": "App",
"duration": 0.001,
"timestamp": 0.009,
"timestamp": 0.007,
"type": "render",
"warning": null,
},
{
"componentName": "App",
"duration": 0.002,
"timestamp": 0.024,
"timestamp": 0.02,
"type": "passive-effect-mount",
"warning": null,
},
{
"componentName": "App",
"duration": 0.001,
"timestamp": 0.029,
"timestamp": 0.025,
"type": "render",
"warning": null,
},
{
"componentName": "App",
"duration": 0.001,
"timestamp": 0.044,
"timestamp": 0.038,
"type": "passive-effect-mount",
"warning": null,
},
],
"duration": 0.046,
"duration": 0.04,
"flamechart": [],
"internalModuleSourceToRanges": Map {
undefined => [
Expand Down Expand Up @@ -1015,81 +1015,81 @@ describe('Timeline profiler', () => {
{
"batchUID": 0,
"depth": 0,
"duration": 0.014,
"duration": 0.012,
"lanes": "0b0000000000000000000000000000101",
"timestamp": 0.008,
"timestamp": 0.006,
"type": "render-idle",
},
{
"batchUID": 0,
"depth": 0,
"duration": 0.003,
"lanes": "0b0000000000000000000000000000101",
"timestamp": 0.008,
"timestamp": 0.006,
"type": "render",
},
{
"batchUID": 0,
"depth": 0,
"duration": 0.010,
"duration": 0.008,
"lanes": "0b0000000000000000000000000000101",
"timestamp": 0.012,
"timestamp": 0.01,
"type": "commit",
},
{
"batchUID": 0,
"depth": 1,
"duration": 0.001,
"lanes": "0b0000000000000000000000000000101",
"timestamp": 0.02,
"timestamp": 0.016,
"type": "layout-effects",
},
{
"batchUID": 0,
"depth": 0,
"duration": 0.004,
"lanes": "0b0000000000000000000000000000101",
"timestamp": 0.023,
"timestamp": 0.019,
"type": "passive-effects",
},
{
"batchUID": 1,
"depth": 0,
"duration": 0.014,
"duration": 0.012,
"lanes": "0b0000000000000000000000000000101",
"timestamp": 0.028,
"timestamp": 0.024,
"type": "render-idle",
},
{
"batchUID": 1,
"depth": 0,
"duration": 0.003,
"lanes": "0b0000000000000000000000000000101",
"timestamp": 0.028,
"timestamp": 0.024,
"type": "render",
},
{
"batchUID": 1,
"depth": 0,
"duration": 0.010,
"duration": 0.008,
"lanes": "0b0000000000000000000000000000101",
"timestamp": 0.032,
"timestamp": 0.028,
"type": "commit",
},
{
"batchUID": 1,
"depth": 1,
"duration": 0.001,
"lanes": "0b0000000000000000000000000000101",
"timestamp": 0.04,
"timestamp": 0.034,
"type": "layout-effects",
},
{
"batchUID": 1,
"depth": 0,
"duration": 0.003,
"lanes": "0b0000000000000000000000000000101",
"timestamp": 0.043,
"timestamp": 0.037,
"type": "passive-effects",
},
],
Expand Down Expand Up @@ -1126,14 +1126,14 @@ describe('Timeline profiler', () => {
"schedulingEvents": [
{
"lanes": "0b0000000000000000000000000000101",
"timestamp": 0.007,
"timestamp": 0.005,
"type": "schedule-render",
"warning": null,
},
{
"componentName": "App",
"lanes": "0b0000000000000000000000000000101",
"timestamp": 0.025,
"timestamp": 0.021,
"type": "schedule-state-update",
"warning": null,
},
Expand Down
12 changes: 6 additions & 6 deletions packages/react-devtools-shared/src/__tests__/treeContext-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2586,14 +2586,14 @@ describe('TreeListContext', () => {
utils.act(() => TestRenderer.create(<Contexts />));

expect(store).toMatchInlineSnapshot(`
1, ⚠ 1
2, ⚠ 0
[root]
<ErrorBoundary> ✕
`);

selectNextErrorOrWarning();
expect(state).toMatchInlineSnapshot(`
1, ⚠ 1
2, ⚠ 0
[root]
→ <ErrorBoundary> ✕
`);
Expand Down Expand Up @@ -2648,14 +2648,14 @@ describe('TreeListContext', () => {
utils.act(() => TestRenderer.create(<Contexts />));

expect(store).toMatchInlineSnapshot(`
1, ⚠ 1
2, ⚠ 0
[root]
<ErrorBoundary> ✕
`);

selectNextErrorOrWarning();
expect(state).toMatchInlineSnapshot(`
1, ⚠ 1
2, ⚠ 0
[root]
→ <ErrorBoundary> ✕
`);
Expand Down Expand Up @@ -2705,15 +2705,15 @@ describe('TreeListContext', () => {
utils.act(() => TestRenderer.create(<Contexts />));

expect(store).toMatchInlineSnapshot(`
2, ⚠ 1
3, ⚠ 0
[root]
▾ <ErrorBoundary> ✕
<Child> ✕
`);

selectNextErrorOrWarning();
expect(state).toMatchInlineSnapshot(`
2, ⚠ 1
3, ⚠ 0
[root]
→ ▾ <ErrorBoundary> ✕
<Child> ✕
Expand Down
1 change: 1 addition & 0 deletions packages/react-devtools-shell/src/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ ignoreErrors([
'Warning: Unsafe lifecycle methods',
'Warning: %s is deprecated in StrictMode.', // findDOMNode
'Warning: ReactDOM.render was removed in React 19',
'Warning: react-test-renderer is deprecated',
]);
ignoreWarnings(['Warning: componentWillReceiveProps has been renamed']);
ignoreLogs([]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ let Scheduler;
let ReactDOMServer;
let act;
let assertLog;
let assertConsoleErrorDev;
let waitForAll;
let waitForThrow;

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

const InternalTestUtils = require('internal-test-utils');
assertLog = InternalTestUtils.assertLog;
assertConsoleErrorDev = InternalTestUtils.assertConsoleErrorDev;
waitForAll = InternalTestUtils.waitForAll;
waitForThrow = InternalTestUtils.waitForThrow;
});
Expand Down Expand Up @@ -1810,7 +1812,6 @@ describe('ReactHooks', () => {
// Regression test for #14674
it('does not swallow original error when updating another component in render phase', async () => {
const {useState} = React;
spyOnDev(console, 'error').mockImplementation(() => {});

let _setState;
function A() {
Expand All @@ -1837,14 +1838,10 @@ describe('ReactHooks', () => {
);
});
}).rejects.toThrow('Hello');

if (__DEV__) {
expect(console.error).toHaveBeenCalledTimes(1);
expect(console.error.mock.calls[0][0]).toContain(
'Warning: Cannot update a component (`%s`) while rendering ' +
'a different component (`%s`).',
);
}
assertConsoleErrorDev([
'Warning: Cannot update a component (`A`) while rendering ' +
'a different component (`B`).',
]);
});

// Regression test for https://github.com/facebook/react/issues/15057
Expand Down
Loading

0 comments on commit ab7322b

Please sign in to comment.