Skip to content

Commit

Permalink
Revert "Ignore infinite timers in tests"
Browse files Browse the repository at this point in the history
This reverts commit 97ffdbb.
No longer needed now that we stop resetting outside render.
  • Loading branch information
eps1lon committed Mar 9, 2025
1 parent 2ee6f47 commit 1a87f42
Show file tree
Hide file tree
Showing 22 changed files with 70 additions and 75 deletions.
6 changes: 3 additions & 3 deletions packages/react-devtools-shared/src/__tests__/bridge-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ describe('Bridge', () => {

// Check that we're wired up correctly.
bridge.send('reloadAppForProfiling');
jest.runOnlyPendingTimers();
jest.runAllTimers();
expect(wall.send).toHaveBeenCalledWith('reloadAppForProfiling');

// Should flush pending messages and then shut down.
wall.send.mockClear();
bridge.send('update', '1');
bridge.send('update', '2');
bridge.shutdown();
jest.runOnlyPendingTimers();
jest.runAllTimers();
expect(wall.send).toHaveBeenCalledWith('update', '1');
expect(wall.send).toHaveBeenCalledWith('update', '2');
expect(wall.send).toHaveBeenCalledWith('shutdown');
Expand All @@ -44,7 +44,7 @@ describe('Bridge', () => {
jest.spyOn(console, 'warn').mockImplementation(() => {});
wall.send.mockClear();
bridge.send('should not send');
jest.runOnlyPendingTimers();
jest.runAllTimers();
expect(wall.send).not.toHaveBeenCalled();
expect(console.warn).toHaveBeenCalledWith(
'Cannot send message "should not send" through a Bridge that has been shutdown.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('editing interface', () => {
const act = (callback: Function) => {
callback();

jest.runOnlyPendingTimers(); // Flush Bridge operations
jest.runAllTimers(); // Flush Bridge operations
};

const flushPendingUpdates = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('InspectedElementContext', () => {
const act = (callback: Function) => {
callback();

jest.runOnlyPendingTimers(); // Flush Bridge operations
jest.runAllTimers(); // Flush Bridge operations
};

async function read(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Store (legacy)', () => {
let store;
const act = (callback: Function) => {
callback();
jest.runOnlyPendingTimers(); // Flush Bridge operations
jest.runAllTimers(); // Flush Bridge operations
};
beforeEach(() => {
store = global.store;
Expand Down
6 changes: 3 additions & 3 deletions packages/react-devtools-shared/src/__tests__/store-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1978,7 +1978,7 @@ describe('Store', () => {
clearErrorsAndWarnings({bridge, store});

// flush events to the renderer
jest.runOnlyPendingTimers();
jest.runAllTimers();

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

// Flush events to the renderer.
jest.runOnlyPendingTimers();
jest.runAllTimers();

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

// Flush events to the renderer.
jest.runOnlyPendingTimers();
jest.runAllTimers();

expect(store).toMatchInlineSnapshot(`
✕ 1, ⚠ 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1421,21 +1421,21 @@ describe('TreeListContext', () => {
function clearAllErrors() {
utils.act(() => clearErrorsAndWarningsAPI({bridge, store}));
// flush events to the renderer
jest.runOnlyPendingTimers();
jest.runAllTimers();
}

function clearErrorsForElement(id) {
const rendererID = store.getRendererIDForElement(id);
utils.act(() => clearErrorsForElementAPI({bridge, id, rendererID}));
// flush events to the renderer
jest.runOnlyPendingTimers();
jest.runAllTimers();
}

function clearWarningsForElement(id) {
const rendererID = store.getRendererIDForElement(id);
utils.act(() => clearWarningsForElementAPI({bridge, id, rendererID}));
// flush events to the renderer
jest.runOnlyPendingTimers();
jest.runAllTimers();
}

function selectNextErrorOrWarning() {
Expand Down Expand Up @@ -2358,7 +2358,7 @@ describe('TreeListContext', () => {
);
utils.act(() => TestRenderer.create(<Contexts />));

jest.runOnlyPendingTimers();
jest.runAllTimers();

expect(state).toMatchInlineSnapshot(`
[root]
Expand Down
10 changes: 4 additions & 6 deletions packages/react-devtools-shared/src/__tests__/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,10 @@ export function act(

if (recursivelyFlush) {
// Flush Bridge operations
// We have always one pending timer running that resets the Owner Stack limit.
while (jest.getTimerCount() > 1) {
while (jest.getTimerCount() > 0) {
actDOM(() => {
actTestRenderer(() => {
jest.runOnlyPendingTimers();
jest.runAllTimers();
});
});
}
Expand All @@ -108,11 +107,10 @@ export async function actAsync(
});

if (recursivelyFlush) {
// We have always one pending timer running that resets the Owner Stack limit.
while (jest.getTimerCount() > 1) {
while (jest.getTimerCount() > 0) {
await actDOM(async () => {
await actTestRenderer(async () => {
jest.runOnlyPendingTimers();
jest.runAllTimers();
});
});
}
Expand Down
6 changes: 3 additions & 3 deletions packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2881,7 +2881,7 @@ describe('ReactDOMFizzServer', () => {
root.render(<App color="blue" />);
});
await waitForAll([]);
jest.runOnlyPendingTimers();
jest.runAllTimers();
const clientFallback2 = container.getElementsByTagName('p')[0];
expect(clientFallback2).toBe(serverFallback);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@ describe('ReactDOMFizzServerNode', () => {
},
},
);
await jest.runOnlyPendingTimers();
await jest.runAllTimers();
expect(output.result).toBe('');
expect(isCompleteCalls).toBe(0);
// Resolve the loading.
hasLoaded = true;
await resolve();

await jest.runOnlyPendingTimers();
await jest.runAllTimers();

expect(output.result).toBe('');
expect(isCompleteCalls).toBe(1);
Expand Down Expand Up @@ -354,7 +354,7 @@ describe('ReactDOMFizzServerNode', () => {
const theReason = new Error('uh oh');
abort(theReason);

jest.runOnlyPendingTimers();
jest.runAllTimers();

await completed;

Expand Down Expand Up @@ -632,7 +632,7 @@ describe('ReactDOMFizzServerNode', () => {

writable.end();

await jest.runOnlyPendingTimers();
await jest.runAllTimers();

hasLoaded = true;
resolve();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ describe('ReactDOMFizzStaticBrowser', () => {
),
);

await jest.runOnlyPendingTimers();
await jest.runAllTimers();

// Resolve the loading.
hasLoaded = true;
Expand Down Expand Up @@ -354,7 +354,7 @@ describe('ReactDOMFizzStaticBrowser', () => {
),
);

await jest.runOnlyPendingTimers();
await jest.runAllTimers();

const theReason = new Error('aborted for reasons');
controller.abort(theReason);
Expand Down Expand Up @@ -387,7 +387,7 @@ describe('ReactDOMFizzStaticBrowser', () => {
),
);

await jest.runOnlyPendingTimers();
await jest.runAllTimers();

const theReason = new Error('aborted for reasons');
controller.abort(theReason);
Expand Down Expand Up @@ -1377,7 +1377,7 @@ describe('ReactDOMFizzStaticBrowser', () => {
),
);

await jest.runOnlyPendingTimers();
await jest.runAllTimers();

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

Expand Down
12 changes: 6 additions & 6 deletions packages/react-dom/src/__tests__/ReactDOMFizzStaticNode-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe('ReactDOMFizzStaticNode', () => {
</div>,
);

await jest.runOnlyPendingTimers();
await jest.runAllTimers();

// Resolve the loading.
hasLoaded = true;
Expand Down Expand Up @@ -199,7 +199,7 @@ describe('ReactDOMFizzStaticNode', () => {
},
);

await jest.runOnlyPendingTimers();
await jest.runAllTimers();

controller.abort();

Expand Down Expand Up @@ -228,7 +228,7 @@ describe('ReactDOMFizzStaticNode', () => {
},
);

await jest.runOnlyPendingTimers();
await jest.runAllTimers();

const theReason = new Error('aborted for reasons');
controller.abort(theReason);
Expand Down Expand Up @@ -259,7 +259,7 @@ describe('ReactDOMFizzStaticNode', () => {
},
);

await jest.runOnlyPendingTimers();
await jest.runAllTimers();

const theReason = new Error('aborted for reasons');
controller.abort(theReason);
Expand Down Expand Up @@ -422,7 +422,7 @@ describe('ReactDOMFizzStaticNode', () => {
},
});

await jest.runOnlyPendingTimers();
await jest.runAllTimers();

controller.abort('foobar');

Expand Down Expand Up @@ -464,7 +464,7 @@ describe('ReactDOMFizzStaticNode', () => {
},
});

await jest.runOnlyPendingTimers();
await jest.runAllTimers();

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

Expand Down
Loading

0 comments on commit 1a87f42

Please sign in to comment.