Skip to content

Commit 2d6186a

Browse files
committed
Use modern timers everywhere (we already do on main, using legacy was a mistake)
1 parent 0bcfaec commit 2d6186a

File tree

18 files changed

+52
-156
lines changed

18 files changed

+52
-156
lines changed

packages/account-tree-controller/src/backup-and-sync/service/atomic-sync-queue.test.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ describe('BackupAndSync - Service - AtomicSyncQueue', () => {
6262
});
6363

6464
it('triggers async processing after enqueueing', async () => {
65-
jest.useFakeTimers({
66-
legacyFakeTimers: true,
67-
});
65+
jest.useFakeTimers();
6866
const mockSyncFunction = jest.fn().mockResolvedValue(undefined);
6967

7068
void atomicSyncQueue.enqueue(mockSyncFunction);
@@ -203,9 +201,7 @@ describe('BackupAndSync - Service - AtomicSyncQueue', () => {
203201

204202
describe('error handling in async processing', () => {
205203
it('handles errors in async process call', async () => {
206-
jest.useFakeTimers({
207-
legacyFakeTimers: true,
208-
});
204+
jest.useFakeTimers();
209205

210206
const error = new Error('Process error');
211207
jest.spyOn(atomicSyncQueue, 'process').mockRejectedValueOnce(error);

packages/assets-controllers/src/DeFiPositionsController/DeFiPositionsController.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,7 @@ function setupController({
173173

174174
describe('DeFiPositionsController', () => {
175175
beforeEach(() => {
176-
jest.useFakeTimers({
177-
legacyFakeTimers: true,
178-
});
176+
jest.useFakeTimers();
179177
});
180178

181179
afterEach(() => {

packages/assets-controllers/src/TokenBalancesController.test.ts

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2441,9 +2441,7 @@ describe('TokenBalancesController', () => {
24412441
const { controller } = setupController({ tokens });
24422442

24432443
// Use fake timers for precise control
2444-
jest.useFakeTimers({
2445-
legacyFakeTimers: true,
2446-
});
2444+
jest.useFakeTimers();
24472445

24482446
// Mock safelyExecuteWithTimeout to simulate timeout by returning undefined
24492447
mockedSafelyExecuteWithTimeout.mockImplementation(
@@ -4094,9 +4092,7 @@ describe('TokenBalancesController', () => {
40944092
});
40954093

40964094
// Use fake timers to control polling intervals
4097-
jest.useFakeTimers({
4098-
legacyFakeTimers: true,
4099-
});
4095+
jest.useFakeTimers();
41004096

41014097
// Mock _executePoll to track calls
41024098
const executePollSpy = jest.spyOn(controller, '_executePoll');
@@ -4522,9 +4518,7 @@ describe('TokenBalancesController', () => {
45224518
});
45234519

45244520
it('should handle status change to "up" and increase polling interval', async () => {
4525-
jest.useFakeTimers({
4526-
legacyFakeTimers: true,
4527-
});
4521+
jest.useFakeTimers();
45284522

45294523
const { controller, messenger } = setupController();
45304524

@@ -4560,9 +4554,7 @@ describe('TokenBalancesController', () => {
45604554
});
45614555

45624556
it('should handle status change to "down" and restore default polling interval', async () => {
4563-
jest.useFakeTimers({
4564-
legacyFakeTimers: true,
4565-
});
4557+
jest.useFakeTimers();
45664558

45674559
const { controller, messenger } = setupController();
45684560

@@ -4597,9 +4589,7 @@ describe('TokenBalancesController', () => {
45974589
});
45984590

45994591
it('should debounce rapid status changes', async () => {
4600-
jest.useFakeTimers({
4601-
legacyFakeTimers: true,
4602-
});
4592+
jest.useFakeTimers();
46034593

46044594
const { controller, messenger } = setupController();
46054595

@@ -4765,9 +4755,7 @@ describe('TokenBalancesController', () => {
47654755
});
47664756

47674757
it('should handle status changes with hex chain ID format', async () => {
4768-
jest.useFakeTimers({
4769-
legacyFakeTimers: true,
4770-
});
4758+
jest.useFakeTimers();
47714759

47724760
const { controller, messenger } = setupController();
47734761
const updateConfigSpy = jest.spyOn(
@@ -5207,9 +5195,7 @@ describe('TokenBalancesController', () => {
52075195
});
52085196

52095197
it('should cleanup debouncing timer on destroy', () => {
5210-
jest.useFakeTimers({
5211-
legacyFakeTimers: true,
5212-
});
5198+
jest.useFakeTimers();
52135199

52145200
const { controller, messenger } = setupController();
52155201
const clearTimeoutSpy = jest.spyOn(global, 'clearTimeout');

packages/assets-controllers/src/utils/timeout-with-retry.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ describe('timeoutWithRetry', () => {
55
const timeout = 1000;
66

77
beforeEach(() => {
8-
jest.useFakeTimers({
9-
legacyFakeTimers: true,
10-
});
8+
jest.useFakeTimers();
119
});
1210

1311
afterEach(() => {

packages/bridge-controller/src/bridge-controller.sse.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,7 @@ describe('BridgeController SSE', function () {
126126
clientVersion: '13.8.0',
127127
});
128128

129-
jest.useFakeTimers({
130-
legacyFakeTimers: true,
131-
});
129+
jest.useFakeTimers();
132130
stopAllPollingSpy = jest.spyOn(bridgeController, 'stopAllPolling');
133131
startPollingSpy = jest.spyOn(bridgeController, 'startPolling');
134132
hasSufficientBalanceSpy = jest

packages/bridge-controller/src/bridge-controller.test.ts

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,7 @@ describe('BridgeController', function () {
308308
});
309309

310310
it('updateBridgeQuoteRequestParams should not call fetchBridgeQuotes if SSE is not enabled', async function () {
311-
jest.useFakeTimers({
312-
legacyFakeTimers: true,
313-
});
311+
jest.useFakeTimers();
314312
const stopAllPollingSpy = jest.spyOn(bridgeController, 'stopAllPolling');
315313
const startPollingSpy = jest.spyOn(bridgeController, 'startPolling');
316314
const hasSufficientBalanceSpy = jest
@@ -389,9 +387,7 @@ describe('BridgeController', function () {
389387
});
390388

391389
it('updateBridgeQuoteRequestParams should trigger quote polling if request is valid', async function () {
392-
jest.useFakeTimers({
393-
legacyFakeTimers: true,
394-
});
390+
jest.useFakeTimers();
395391
const stopAllPollingSpy = jest.spyOn(bridgeController, 'stopAllPolling');
396392
const startPollingSpy = jest.spyOn(bridgeController, 'startPolling');
397393
const hasSufficientBalanceSpy = jest
@@ -633,9 +629,7 @@ describe('BridgeController', function () {
633629
});
634630

635631
it('updateBridgeQuoteRequestParams should reset minimumBalanceForRentExemptionInLamports if getMinimumBalanceForRentExemption call fails', async function () {
636-
jest.useFakeTimers({
637-
legacyFakeTimers: true,
638-
});
632+
jest.useFakeTimers();
639633
jest.clearAllMocks();
640634
jest.spyOn(balanceUtils, 'hasSufficientBalance').mockResolvedValue(false);
641635
const consoleErrorSpy = jest
@@ -924,9 +918,7 @@ describe('BridgeController', function () {
924918
});
925919

926920
it('updateBridgeQuoteRequestParams should only poll once if insufficientBal=true', async function () {
927-
jest.useFakeTimers({
928-
legacyFakeTimers: true,
929-
});
921+
jest.useFakeTimers();
930922
const stopAllPollingSpy = jest.spyOn(bridgeController, 'stopAllPolling');
931923
const startPollingSpy = jest.spyOn(bridgeController, 'startPolling');
932924
const hasSufficientBalanceSpy = jest
@@ -1093,9 +1085,7 @@ describe('BridgeController', function () {
10931085
});
10941086

10951087
it('updateBridgeQuoteRequestParams should set insufficientBal=true if RPC provider is tenderly', async function () {
1096-
jest.useFakeTimers({
1097-
legacyFakeTimers: true,
1098-
});
1088+
jest.useFakeTimers();
10991089
const stopAllPollingSpy = jest.spyOn(bridgeController, 'stopAllPolling');
11001090
const startPollingSpy = jest.spyOn(bridgeController, 'startPolling');
11011091
const hasSufficientBalanceSpy = jest
@@ -1440,9 +1430,7 @@ describe('BridgeController', function () {
14401430
const errorSpy = jest
14411431
.spyOn(console, 'error')
14421432
.mockImplementation(jest.fn());
1443-
jest.useFakeTimers({
1444-
legacyFakeTimers: true,
1445-
});
1433+
jest.useFakeTimers();
14461434
const stopAllPollingSpy = jest.spyOn(bridgeController, 'stopAllPolling');
14471435
const startPollingSpy = jest.spyOn(bridgeController, 'startPolling');
14481436
const hasSufficientBalanceSpy = jest
@@ -1586,9 +1574,7 @@ describe('BridgeController', function () {
15861574
);
15871575

15881576
it('should handle errors from fetchBridgeQuotes', async () => {
1589-
jest.useFakeTimers({
1590-
legacyFakeTimers: true,
1591-
});
1577+
jest.useFakeTimers();
15921578
const fetchBridgeQuotesSpy = jest.spyOn(fetchUtils, 'fetchBridgeQuotes');
15931579
messengerMock.call.mockReturnValue({
15941580
address: '0x123',
@@ -1699,9 +1685,7 @@ describe('BridgeController', function () {
16991685
});
17001686

17011687
it('returns early on AbortError without updating post-fetch state', async () => {
1702-
jest.useFakeTimers({
1703-
legacyFakeTimers: true,
1704-
});
1688+
jest.useFakeTimers();
17051689

17061690
const abortError = new Error('Aborted');
17071691
// Make it look like an AbortError to hit the early return
@@ -1816,9 +1800,7 @@ describe('BridgeController', function () {
18161800
expectedMinBalance: string | undefined,
18171801
isEvmAccount = false,
18181802
) => {
1819-
jest.useFakeTimers({
1820-
legacyFakeTimers: true,
1821-
});
1803+
jest.useFakeTimers();
18221804
const stopAllPollingSpy = jest.spyOn(bridgeController, 'stopAllPolling');
18231805
const startPollingSpy = jest.spyOn(bridgeController, 'startPolling');
18241806
const hasSufficientBalanceSpy = jest
@@ -2006,9 +1988,7 @@ describe('BridgeController', function () {
20061988
);
20071989

20081990
it('should handle BTC chain fees correctly', async () => {
2009-
jest.useFakeTimers({
2010-
legacyFakeTimers: true,
2011-
});
1991+
jest.useFakeTimers();
20121992
// Use the actual Solana mock which already has string trade type
20131993
const btcQuoteResponse = mockBridgeQuotesSolErc20.map((quote) => ({
20141994
...quote,

0 commit comments

Comments
 (0)