Skip to content

Commit c7fdaef

Browse files
committed
Ignore infinite timers in tests
1 parent 3b6aa41 commit c7fdaef

24 files changed

+77
-72
lines changed

packages/internal-test-utils/internalAct.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ export async function serverAct<T>(scope: () => Thenable<T>): Thenable<T> {
249249

250250
// $FlowFixMe[cannot-resolve-name]: Flow doesn't know about global Jest object
251251
const j = jest;
252-
if (j.getTimerCount() > 0) {
252+
// We have always one pending timer running that resets the Owner Stack limit.
253+
if (j.getTimerCount() > 1) {
253254
// There's a pending timer. Flush it now. We only do this in order to
254255
// force Suspense fallbacks to display; the fact that it's a timer
255256
// is an implementation detail. If there are other timers scheduled,

packages/react-devtools-shared/src/__tests__/bridge-test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ describe('Bridge', () => {
2626

2727
// Check that we're wired up correctly.
2828
bridge.send('reloadAppForProfiling');
29-
jest.runAllTimers();
29+
jest.runOnlyPendingTimers();
3030
expect(wall.send).toHaveBeenCalledWith('reloadAppForProfiling');
3131

3232
// Should flush pending messages and then shut down.
3333
wall.send.mockClear();
3434
bridge.send('update', '1');
3535
bridge.send('update', '2');
3636
bridge.shutdown();
37-
jest.runAllTimers();
37+
jest.runOnlyPendingTimers();
3838
expect(wall.send).toHaveBeenCalledWith('update', '1');
3939
expect(wall.send).toHaveBeenCalledWith('update', '2');
4040
expect(wall.send).toHaveBeenCalledWith('shutdown');
@@ -44,7 +44,7 @@ describe('Bridge', () => {
4444
jest.spyOn(console, 'warn').mockImplementation(() => {});
4545
wall.send.mockClear();
4646
bridge.send('should not send');
47-
jest.runAllTimers();
47+
jest.runOnlyPendingTimers();
4848
expect(wall.send).not.toHaveBeenCalled();
4949
expect(console.warn).toHaveBeenCalledWith(
5050
'Cannot send message "should not send" through a Bridge that has been shutdown.',

packages/react-devtools-shared/src/__tests__/legacy/editing-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('editing interface', () => {
2020
const act = (callback: Function) => {
2121
callback();
2222

23-
jest.runAllTimers(); // Flush Bridge operations
23+
jest.runOnlyPendingTimers(); // Flush Bridge operations
2424
};
2525

2626
const flushPendingUpdates = () => {

packages/react-devtools-shared/src/__tests__/legacy/inspectElement-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('InspectedElementContext', () => {
2121
const act = (callback: Function) => {
2222
callback();
2323

24-
jest.runAllTimers(); // Flush Bridge operations
24+
jest.runOnlyPendingTimers(); // Flush Bridge operations
2525
};
2626

2727
async function read(

packages/react-devtools-shared/src/__tests__/legacy/storeLegacy-v15-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('Store (legacy)', () => {
1313
let store;
1414
const act = (callback: Function) => {
1515
callback();
16-
jest.runAllTimers(); // Flush Bridge operations
16+
jest.runOnlyPendingTimers(); // Flush Bridge operations
1717
};
1818
beforeEach(() => {
1919
store = global.store;

packages/react-devtools-shared/src/__tests__/store-test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1978,7 +1978,7 @@ describe('Store', () => {
19781978
clearErrorsAndWarnings({bridge, store});
19791979

19801980
// flush events to the renderer
1981-
jest.runAllTimers();
1981+
jest.runOnlyPendingTimers();
19821982

19831983
expect(store).toMatchInlineSnapshot(`
19841984
[root]
@@ -2022,7 +2022,7 @@ describe('Store', () => {
20222022
clearWarningsForElement({bridge, id, rendererID});
20232023

20242024
// Flush events to the renderer.
2025-
jest.runAllTimers();
2025+
jest.runOnlyPendingTimers();
20262026

20272027
expect(store).toMatchInlineSnapshot(`
20282028
✕ 2, ⚠ 1
@@ -2067,7 +2067,7 @@ describe('Store', () => {
20672067
clearErrorsForElement({bridge, id, rendererID});
20682068

20692069
// Flush events to the renderer.
2070-
jest.runAllTimers();
2070+
jest.runOnlyPendingTimers();
20712071

20722072
expect(store).toMatchInlineSnapshot(`
20732073
✕ 1, ⚠ 2

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -1421,21 +1421,21 @@ describe('TreeListContext', () => {
14211421
function clearAllErrors() {
14221422
utils.act(() => clearErrorsAndWarningsAPI({bridge, store}));
14231423
// flush events to the renderer
1424-
jest.runAllTimers();
1424+
jest.runOnlyPendingTimers();
14251425
}
14261426

14271427
function clearErrorsForElement(id) {
14281428
const rendererID = store.getRendererIDForElement(id);
14291429
utils.act(() => clearErrorsForElementAPI({bridge, id, rendererID}));
14301430
// flush events to the renderer
1431-
jest.runAllTimers();
1431+
jest.runOnlyPendingTimers();
14321432
}
14331433

14341434
function clearWarningsForElement(id) {
14351435
const rendererID = store.getRendererIDForElement(id);
14361436
utils.act(() => clearWarningsForElementAPI({bridge, id, rendererID}));
14371437
// flush events to the renderer
1438-
jest.runAllTimers();
1438+
jest.runOnlyPendingTimers();
14391439
}
14401440

14411441
function selectNextErrorOrWarning() {
@@ -2358,7 +2358,7 @@ describe('TreeListContext', () => {
23582358
);
23592359
utils.act(() => TestRenderer.create(<Contexts />));
23602360

2361-
jest.runAllTimers();
2361+
jest.runOnlyPendingTimers();
23622362

23632363
expect(state).toMatchInlineSnapshot(`
23642364
[root]

packages/react-devtools-shared/src/__tests__/utils.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,11 @@ export function act(
8181

8282
if (recursivelyFlush) {
8383
// Flush Bridge operations
84-
while (jest.getTimerCount() > 0) {
84+
// We have always one pending timer running that resets the Owner Stack limit.
85+
while (jest.getTimerCount() > 1) {
8586
actDOM(() => {
8687
actTestRenderer(() => {
87-
jest.runAllTimers();
88+
jest.runOnlyPendingTimers();
8889
});
8990
});
9091
}
@@ -107,10 +108,11 @@ export async function actAsync(
107108
});
108109

109110
if (recursivelyFlush) {
110-
while (jest.getTimerCount() > 0) {
111+
// We have always one pending timer running that resets the Owner Stack limit.
112+
while (jest.getTimerCount() > 1) {
111113
await actDOM(async () => {
112114
await actTestRenderer(async () => {
113-
jest.runAllTimers();
115+
jest.runOnlyPendingTimers();
114116
});
115117
});
116118
}

packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -2881,7 +2881,7 @@ describe('ReactDOMFizzServer', () => {
28812881
root.render(<App color="blue" />);
28822882
});
28832883
await waitForAll([]);
2884-
jest.runAllTimers();
2884+
jest.runOnlyPendingTimers();
28852885
const clientFallback2 = container.getElementsByTagName('p')[0];
28862886
expect(clientFallback2).toBe(serverFallback);
28872887

@@ -2987,7 +2987,7 @@ describe('ReactDOMFizzServer', () => {
29872987
// actually force it to re-render on the client and throw away the server one.
29882988
root.render(<App fallbackText="More loading..." />);
29892989
await waitForAll([]);
2990-
jest.runAllTimers();
2990+
jest.runOnlyPendingTimers();
29912991
assertLog([
29922992
'onRecoverableError: The server could not finish this Suspense boundary, ' +
29932993
'likely due to an error during server rendering. ' +
@@ -6414,7 +6414,7 @@ describe('ReactDOMFizzServer', () => {
64146414
ref.current.dispatchEvent(
64156415
new window.MouseEvent('click', {bubbles: true}),
64166416
);
6417-
await jest.runAllTimers();
6417+
await jest.runOnlyPendingTimers();
64186418
expect(getVisibleChildren(container)).toEqual(<button>1</button>);
64196419
});
64206420

packages/react-dom/src/__tests__/ReactDOMFizzServerNode-test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,14 @@ describe('ReactDOMFizzServerNode', () => {
144144
},
145145
},
146146
);
147-
await jest.runAllTimers();
147+
await jest.runOnlyPendingTimers();
148148
expect(output.result).toBe('');
149149
expect(isCompleteCalls).toBe(0);
150150
// Resolve the loading.
151151
hasLoaded = true;
152152
await resolve();
153153

154-
await jest.runAllTimers();
154+
await jest.runOnlyPendingTimers();
155155

156156
expect(output.result).toBe('');
157157
expect(isCompleteCalls).toBe(1);
@@ -354,7 +354,7 @@ describe('ReactDOMFizzServerNode', () => {
354354
const theReason = new Error('uh oh');
355355
abort(theReason);
356356

357-
jest.runAllTimers();
357+
jest.runOnlyPendingTimers();
358358

359359
await completed;
360360

@@ -632,7 +632,7 @@ describe('ReactDOMFizzServerNode', () => {
632632

633633
writable.end();
634634

635-
await jest.runAllTimers();
635+
await jest.runOnlyPendingTimers();
636636

637637
hasLoaded = true;
638638
resolve();

packages/react-dom/src/__tests__/ReactDOMFizzStaticBrowser-test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ describe('ReactDOMFizzStaticBrowser', () => {
225225
),
226226
);
227227

228-
await jest.runAllTimers();
228+
await jest.runOnlyPendingTimers();
229229

230230
// Resolve the loading.
231231
hasLoaded = true;
@@ -354,7 +354,7 @@ describe('ReactDOMFizzStaticBrowser', () => {
354354
),
355355
);
356356

357-
await jest.runAllTimers();
357+
await jest.runOnlyPendingTimers();
358358

359359
const theReason = new Error('aborted for reasons');
360360
controller.abort(theReason);
@@ -387,7 +387,7 @@ describe('ReactDOMFizzStaticBrowser', () => {
387387
),
388388
);
389389

390-
await jest.runAllTimers();
390+
await jest.runOnlyPendingTimers();
391391

392392
const theReason = new Error('aborted for reasons');
393393
controller.abort(theReason);
@@ -1377,7 +1377,7 @@ describe('ReactDOMFizzStaticBrowser', () => {
13771377
),
13781378
);
13791379

1380-
await jest.runAllTimers();
1380+
await jest.runOnlyPendingTimers();
13811381

13821382
expect(getVisibleChildren(container)).toEqual(<div>Loading...</div>);
13831383

packages/react-dom/src/__tests__/ReactDOMFizzStaticNode-test.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ describe('ReactDOMFizzStaticNode', () => {
103103
</div>,
104104
);
105105

106-
await jest.runAllTimers();
106+
await jest.runOnlyPendingTimers();
107107

108108
// Resolve the loading.
109109
hasLoaded = true;
@@ -199,7 +199,7 @@ describe('ReactDOMFizzStaticNode', () => {
199199
},
200200
);
201201

202-
await jest.runAllTimers();
202+
await jest.runOnlyPendingTimers();
203203

204204
controller.abort();
205205

@@ -228,7 +228,7 @@ describe('ReactDOMFizzStaticNode', () => {
228228
},
229229
);
230230

231-
await jest.runAllTimers();
231+
await jest.runOnlyPendingTimers();
232232

233233
const theReason = new Error('aborted for reasons');
234234
controller.abort(theReason);
@@ -259,7 +259,7 @@ describe('ReactDOMFizzStaticNode', () => {
259259
},
260260
);
261261

262-
await jest.runAllTimers();
262+
await jest.runOnlyPendingTimers();
263263

264264
const theReason = new Error('aborted for reasons');
265265
controller.abort(theReason);
@@ -422,7 +422,7 @@ describe('ReactDOMFizzStaticNode', () => {
422422
},
423423
});
424424

425-
await jest.runAllTimers();
425+
await jest.runOnlyPendingTimers();
426426

427427
controller.abort('foobar');
428428

@@ -464,7 +464,7 @@ describe('ReactDOMFizzStaticNode', () => {
464464
},
465465
});
466466

467-
await jest.runAllTimers();
467+
await jest.runOnlyPendingTimers();
468468

469469
controller.abort(new Error('uh oh'));
470470

0 commit comments

Comments
 (0)