Skip to content

Commit 6fbd265

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

17 files changed

+58
-55
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-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

packages/react-dom/src/__tests__/ReactDOMServerPartialHydration-test.internal.js

+17-17
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ describe('ReactDOMServerPartialHydration', () => {
314314
},
315315
});
316316
await waitForAll(['Suspend']);
317-
jest.runAllTimers();
317+
jest.runOnlyPendingTimers();
318318

319319
// Unchanged
320320
expect(container.innerHTML).toBe(
@@ -407,7 +407,7 @@ describe('ReactDOMServerPartialHydration', () => {
407407
},
408408
});
409409
await waitForAll(['Suspend']);
410-
jest.runAllTimers();
410+
jest.runOnlyPendingTimers();
411411

412412
// !! Unchanged, continue showing server content while suspended.
413413
expect(container.innerHTML).toBe(
@@ -425,7 +425,7 @@ describe('ReactDOMServerPartialHydration', () => {
425425
'Component',
426426
"onRecoverableError: Hydration failed because the server rendered HTML didn't match the client.",
427427
]);
428-
jest.runAllTimers();
428+
jest.runOnlyPendingTimers();
429429

430430
// Client rendered - suspense comment nodes removed.
431431
expect(container.innerHTML).toBe('Hello<article>Mismatch</article>');
@@ -491,7 +491,7 @@ describe('ReactDOMServerPartialHydration', () => {
491491
},
492492
});
493493
await waitForAll(['Suspend']);
494-
jest.runAllTimers();
494+
jest.runOnlyPendingTimers();
495495

496496
// !! Unchanged, continue showing server content while suspended.
497497
expect(container.innerHTML).toBe(
@@ -509,7 +509,7 @@ describe('ReactDOMServerPartialHydration', () => {
509509
'Component',
510510
"onRecoverableError: Hydration failed because the server rendered HTML didn't match the client.",
511511
]);
512-
jest.runAllTimers();
512+
jest.runOnlyPendingTimers();
513513

514514
// Client rendered - suspense comment nodes removed
515515
expect(container.innerHTML).toBe('<div><article>Mismatch</article></div>');
@@ -585,7 +585,7 @@ describe('ReactDOMServerPartialHydration', () => {
585585
},
586586
});
587587
await waitForAll(['Component', 'Suspend']);
588-
jest.runAllTimers();
588+
jest.runOnlyPendingTimers();
589589

590590
// !! Unchanged, continue showing server content while suspended.
591591
expect(container.innerHTML).toBe(
@@ -603,7 +603,7 @@ describe('ReactDOMServerPartialHydration', () => {
603603
'Hello',
604604
"onRecoverableError: Hydration failed because the server rendered HTML didn't match the client.",
605605
]);
606-
jest.runAllTimers();
606+
jest.runOnlyPendingTimers();
607607

608608
// Client rendered - suspense comment nodes removed
609609
expect(container.innerHTML).toBe(
@@ -687,7 +687,7 @@ describe('ReactDOMServerPartialHydration', () => {
687687
'Fallback',
688688
"onRecoverableError: Hydration failed because the server rendered HTML didn't match the client.",
689689
]);
690-
jest.runAllTimers();
690+
jest.runOnlyPendingTimers();
691691

692692
// !! Client switches to suspense fallback.
693693
expect(container.innerHTML).toBe('Loading...');
@@ -696,7 +696,7 @@ describe('ReactDOMServerPartialHydration', () => {
696696
resolve();
697697
await promise;
698698
await waitForAll(['Component', 'Hello']);
699-
jest.runAllTimers();
699+
jest.runOnlyPendingTimers();
700700

701701
// Client rendered - suspense comment nodes removed
702702
expect(container.innerHTML).toBe(
@@ -768,7 +768,7 @@ describe('ReactDOMServerPartialHydration', () => {
768768
'Fallback',
769769
"onRecoverableError: Hydration failed because the server rendered HTML didn't match the client.",
770770
]);
771-
jest.runAllTimers();
771+
jest.runOnlyPendingTimers();
772772

773773
// !! Client switches to suspense fallback.
774774
expect(container.innerHTML).toBe('Loading...');
@@ -777,7 +777,7 @@ describe('ReactDOMServerPartialHydration', () => {
777777
resolve();
778778
await promise;
779779
await waitForAll(['Component', 'Hello']);
780-
jest.runAllTimers();
780+
jest.runOnlyPendingTimers();
781781

782782
// Client rendered - suspense comment nodes removed
783783
expect(container.innerHTML).toBe('<article><div></div></article>');
@@ -848,7 +848,7 @@ describe('ReactDOMServerPartialHydration', () => {
848848
'Fallback',
849849
"onRecoverableError: Hydration failed because the server rendered HTML didn't match the client.",
850850
]);
851-
jest.runAllTimers();
851+
jest.runOnlyPendingTimers();
852852

853853
// !! Client switches to suspense fallback.
854854
expect(container.innerHTML).toBe('Loading...');
@@ -861,7 +861,7 @@ describe('ReactDOMServerPartialHydration', () => {
861861
'Component',
862862
'Hello',
863863
]);
864-
jest.runAllTimers();
864+
jest.runOnlyPendingTimers();
865865

866866
// Client rendered - suspense comment nodes removed
867867
expect(container.innerHTML).toBe('<article>Mismatch</article>Hello');
@@ -934,7 +934,7 @@ describe('ReactDOMServerPartialHydration', () => {
934934
'Fallback',
935935
"onRecoverableError: Hydration failed because the server rendered HTML didn't match the client.",
936936
]);
937-
jest.runAllTimers();
937+
jest.runOnlyPendingTimers();
938938

939939
// !! Client switches to suspense fallback.
940940
expect(container.innerHTML).toBe('Loading...');
@@ -947,7 +947,7 @@ describe('ReactDOMServerPartialHydration', () => {
947947
'Component',
948948
'Hello',
949949
]);
950-
jest.runAllTimers();
950+
jest.runOnlyPendingTimers();
951951

952952
// Client rendered - suspense comment nodes removed.
953953
expect(container.innerHTML).toBe(
@@ -2167,7 +2167,7 @@ describe('ReactDOMServerPartialHydration', () => {
21672167
'an error during server rendering.',
21682168
]);
21692169
}
2170-
jest.runAllTimers();
2170+
jest.runOnlyPendingTimers();
21712171

21722172
expect(container.textContent).toBe('Hello');
21732173

@@ -2709,7 +2709,7 @@ describe('ReactDOMServerPartialHydration', () => {
27092709
'an error during server rendering.',
27102710
]);
27112711
}
2712-
jest.runAllTimers();
2712+
jest.runOnlyPendingTimers();
27132713

27142714
expect(ref.current).toBe(span);
27152715
expect(span.parentNode).not.toBe(null);

packages/react-dom/src/__tests__/ReactDOMServerSelectiveHydration-test.internal.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ describe('ReactDOMServerSelectiveHydration', () => {
10081008
dispatchClickEvent(innerDiv);
10091009

10101010
await act(() => {
1011-
jest.runAllTimers();
1011+
jest.runOnlyPendingTimers();
10121012
Scheduler.unstable_flushAllWithoutAsserting();
10131013
OuterScheduler.unstable_flushAllWithoutAsserting();
10141014
InnerScheduler.unstable_flushAllWithoutAsserting();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ describe('ReactErrorLoggingRecovery', () => {
6868
root.render(<Bad />);
6969
});
7070

71-
expect(() => jest.runAllTimers()).toThrow('');
71+
expect(() => jest.runOnlyPendingTimers()).toThrow('');
7272

7373
await fakeAct(() => {
7474
root.render(<span>Hello</span>);

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ function runActTests(render, unmount, rerender) {
347347
render(<App />, container);
348348
});
349349
act(() => {
350-
jest.runAllTimers();
350+
jest.runOnlyPendingTimers();
351351
});
352352

353353
expect(container.innerHTML).toBe('1');
@@ -370,7 +370,7 @@ function runActTests(render, unmount, rerender) {
370370
render(<App />, container);
371371
});
372372
await act(async () => {
373-
jest.runAllTimers();
373+
jest.runOnlyPendingTimers();
374374
});
375375

376376
expect(container.innerHTML).toBe('1');
@@ -417,13 +417,13 @@ function runActTests(render, unmount, rerender) {
417417
act(() => {
418418
render(<App />, container);
419419
// Since effects haven't been flushed yet, this does not advance the timer
420-
jest.runAllTimers();
420+
jest.runOnlyPendingTimers();
421421
});
422422

423423
expect(container.innerHTML).toBe('1');
424424

425425
act(() => {
426-
jest.runAllTimers();
426+
jest.runOnlyPendingTimers();
427427
});
428428

429429
expect(container.innerHTML).toBe('2');

0 commit comments

Comments
 (0)