Skip to content

Commit ee4699f

Browse files
authored
[noop] Fail tests on unasserted recoverable errors (facebook#35948)
1 parent 23b2d85 commit ee4699f

4 files changed

Lines changed: 34 additions & 7 deletions

File tree

packages/react-noop-renderer/src/createReactNoop.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,9 +1151,9 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
11511151
}
11521152
}
11531153

1154-
function onRecoverableError(error) {
1155-
// TODO: Turn this on once tests are fixed
1156-
// console.error(error);
1154+
function onRecoverableError(error: mixed): void {
1155+
// eslint-disable-next-line react-internal/warning-args, react-internal/no-production-logging -- renderer is only used for testing.
1156+
console.error(error);
11571157
}
11581158
function onDefaultTransitionIndicator(): void | (() => void) {}
11591159

packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.internal.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,10 @@ describe('ReactIncrementalErrorHandling', () => {
287287
'commit',
288288
'commit',
289289
]);
290+
assertConsoleErrorDev([
291+
'Error: There was an error during concurrent rendering but React was able to recover by instead synchronously rendering the entire root.' +
292+
'\n in <stack>',
293+
]);
290294
expect(ReactNoop).toMatchRenderedOutput(
291295
<span prop="Everything is fine." />,
292296
);
@@ -339,6 +343,10 @@ describe('ReactIncrementalErrorHandling', () => {
339343
'commit',
340344
'commit',
341345
]);
346+
assertConsoleErrorDev([
347+
'Error: There was an error during concurrent rendering but React was able to recover by instead synchronously rendering the entire root.' +
348+
'\n in <stack>',
349+
]);
342350
// This should not include the offscreen content
343351
expect(ReactNoop).toMatchRenderedOutput(
344352
<>
@@ -1786,6 +1794,10 @@ describe('ReactIncrementalErrorHandling', () => {
17861794
});
17871795

17881796
// Should finish without throwing.
1797+
assertConsoleErrorDev([
1798+
'Error: There was an error during concurrent rendering but React was able to recover by instead synchronously rendering the entire root.' +
1799+
'\n in <stack>',
1800+
]);
17891801
expect(root).toMatchRenderedOutput('Everything is fine.');
17901802
});
17911803

@@ -1832,6 +1844,10 @@ describe('ReactIncrementalErrorHandling', () => {
18321844
});
18331845
// Should render the final state without throwing the error.
18341846
assertLog(['Everything is fine.']);
1847+
assertConsoleErrorDev([
1848+
'Error: There was an error during concurrent rendering but React was able to recover by instead synchronously rendering the entire root.' +
1849+
'\n in <stack>',
1850+
]);
18351851
expect(root).toMatchRenderedOutput('Everything is fine.');
18361852
});
18371853

packages/react-reconciler/src/__tests__/ReactIncrementalErrorReplay-test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
let React;
1414
let ReactNoop;
15+
let assertConsoleErrorDev;
1516
let waitForAll;
1617
let waitForThrow;
1718

@@ -22,6 +23,7 @@ describe('ReactIncrementalErrorReplay', () => {
2223
ReactNoop = require('react-noop-renderer');
2324

2425
const InternalTestUtils = require('internal-test-utils');
26+
assertConsoleErrorDev = InternalTestUtils.assertConsoleErrorDev;
2527
waitForAll = InternalTestUtils.waitForAll;
2628
waitForThrow = InternalTestUtils.waitForThrow;
2729
});
@@ -50,5 +52,9 @@ describe('ReactIncrementalErrorReplay', () => {
5052
}
5153
ReactNoop.render(<App />);
5254
await waitForAll([]);
55+
assertConsoleErrorDev([
56+
'Error: There was an error during concurrent rendering but React was able to recover by instead synchronously rendering the entire root.' +
57+
'\n in <stack>',
58+
]);
5359
});
5460
});

packages/react-reconciler/src/__tests__/useMemoCache-test.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ let React;
1212
let ReactNoop;
1313
let Scheduler;
1414
let act;
15+
let assertConsoleErrorDev;
1516
let assertLog;
1617
let useMemo;
1718
let useState;
@@ -26,8 +27,10 @@ describe('useMemoCache()', () => {
2627
React = require('react');
2728
ReactNoop = require('react-noop-renderer');
2829
Scheduler = require('scheduler');
29-
act = require('internal-test-utils').act;
30-
assertLog = require('internal-test-utils').assertLog;
30+
const InternalTestUtils = require('internal-test-utils');
31+
act = InternalTestUtils.act;
32+
assertConsoleErrorDev = InternalTestUtils.assertConsoleErrorDev;
33+
assertLog = InternalTestUtils.assertLog;
3134
useMemo = React.useMemo;
3235
useMemoCache = require('react/compiler-runtime').c;
3336
useState = React.useState;
@@ -256,8 +259,6 @@ describe('useMemoCache()', () => {
256259
return `${data.text} (n=${props.n})`;
257260
});
258261

259-
spyOnDev(console, 'error');
260-
261262
const root = ReactNoop.createRoot();
262263
await act(() => {
263264
root.render(
@@ -274,6 +275,10 @@ describe('useMemoCache()', () => {
274275
// this triggers a throw.
275276
setN(1);
276277
});
278+
assertConsoleErrorDev([
279+
'Error: There was an error during concurrent rendering but React was able to recover by instead synchronously rendering the entire root.' +
280+
'\n in <stack>',
281+
]);
277282
expect(root).toMatchRenderedOutput('Count 0 (n=1)');
278283
expect(Text).toBeCalledTimes(2);
279284
expect(data).toBe(data0);

0 commit comments

Comments
 (0)