From 2757affe97af28f4220acc01086f751b69ea9017 Mon Sep 17 00:00:00 2001 From: Sergey Petushkov Date: Wed, 26 Nov 2025 12:51:34 +0100 Subject: [PATCH] fix(eslint): fix await-thenable issues --- configs/eslint-config-compass/index.js | 1 - .../pipeline-preview-manager.spec.ts | 17 +++++++++-------- .../src/stores/connections-store-redux.ts | 12 +++++++----- .../helpers/test-runner-global-fixtures.ts | 4 +++- .../src/store/atlas-optin-reducer.spec.ts | 8 ++++---- .../src/modules/regular-indexes.ts | 4 ++-- .../src/stores/aggregations-queries-items.ts | 8 ++++++-- 7 files changed, 31 insertions(+), 23 deletions(-) diff --git a/configs/eslint-config-compass/index.js b/configs/eslint-config-compass/index.js index 46c92fcf22e..cb5ff1ad5c5 100644 --- a/configs/eslint-config-compass/index.js +++ b/configs/eslint-config-compass/index.js @@ -15,7 +15,6 @@ const tempNewEslintRulesDisabled = { 'react-hooks/static-components': 'off', 'react-hooks/purity': 'off', '@typescript-eslint/no-redundant-type-constituents': 'off', - '@typescript-eslint/await-thenable': 'off', '@typescript-eslint/no-unsafe-enum-comparison': 'off', }; diff --git a/packages/compass-aggregations/src/modules/pipeline-builder/pipeline-preview-manager.spec.ts b/packages/compass-aggregations/src/modules/pipeline-builder/pipeline-preview-manager.spec.ts index 450f1262b83..c15f07dff68 100644 --- a/packages/compass-aggregations/src/modules/pipeline-builder/pipeline-preview-manager.spec.ts +++ b/packages/compass-aggregations/src/modules/pipeline-builder/pipeline-preview-manager.spec.ts @@ -29,13 +29,14 @@ describe('PipelinePreviewManager', function () { const dataService = mockDataService({ data: [] }); const previewManager = new PipelinePreviewManager(dataService, preferences); - const result = await Promise.allSettled([ - previewManager.getPreviewForStage(0, 'test.test', []), - previewManager.cancelPreviewForStage(0), - ]); - - expect(result[0]).to.have.property('status', 'rejected'); - expect(result[0]).to.have.nested.property('reason.name', 'AbortError'); + try { + const result = previewManager.getPreviewForStage(0, 'test.test', []); + previewManager.cancelPreviewForStage(0); + await result; + expect.fail('Expected promise to reject'); + } catch (err) { + expect(err).to.have.property('name', 'AbortError'); + } }); it('should debounce aggregation calls for the same stage', async function () { @@ -108,7 +109,7 @@ describe('PipelinePreviewManager', function () { previewManager.getPreviewForStage(2, 'test.test', []), previewManager.getPreviewForStage(3, 'test.test', []), previewManager.getPreviewForStage(4, 'test.test', []), - previewManager.clearQueue(1), + Promise.resolve(previewManager.clearQueue(1)), ]); // Only pipeline for stage 0 was executed diff --git a/packages/compass-connections/src/stores/connections-store-redux.ts b/packages/compass-connections/src/stores/connections-store-redux.ts index c589594fd69..7b942ab01f8 100644 --- a/packages/compass-connections/src/stores/connections-store-redux.ts +++ b/packages/compass-connections/src/stores/connections-store-redux.ts @@ -2100,10 +2100,9 @@ const cleanupConnection = ( const connectionAttempt = ConnectionAttemptForConnection.get(connectionId); const dataService = DataServiceForConnection.get(connectionId); - void Promise.all([ - connectionAttempt?.cancelConnectionAttempt(), - dataService?.disconnect(), - ]).then( + connectionAttempt?.cancelConnectionAttempt(); + + void dataService?.disconnect().then( () => { debug('connection closed', connectionId); }, @@ -2219,7 +2218,10 @@ export const removeAllRecentConnections = (): ConnectionsThunkAction< toRemove.map((connection) => { dispatch(cleanupConnection(connection.info.id)); track('Connection Removed', {}, connection.info); - return connectionStorage.delete?.({ id: connection.info.id }); + return ( + connectionStorage.delete?.({ id: connection.info.id }) ?? + Promise.resolve() + ); }) ); diff --git a/packages/compass-e2e-tests/helpers/test-runner-global-fixtures.ts b/packages/compass-e2e-tests/helpers/test-runner-global-fixtures.ts index 8a6def6ee32..a852dc7674e 100644 --- a/packages/compass-e2e-tests/helpers/test-runner-global-fixtures.ts +++ b/packages/compass-e2e-tests/helpers/test-runner-global-fixtures.ts @@ -174,7 +174,9 @@ export async function mochaGlobalTeardown() { debug('Cleaning up after the tests ...'); await Promise.allSettled( cleanupFns.map((fn) => { - return fn(); + // We get a mix of sync and non-sync functions here. Awaiting even the + // sync ones just makes the logic simpler + return Promise.resolve(fn()); }) ); } diff --git a/packages/compass-generative-ai/src/store/atlas-optin-reducer.spec.ts b/packages/compass-generative-ai/src/store/atlas-optin-reducer.spec.ts index 7cebbb2fe9d..567ce5a7d36 100644 --- a/packages/compass-generative-ai/src/store/atlas-optin-reducer.spec.ts +++ b/packages/compass-generative-ai/src/store/atlas-optin-reducer.spec.ts @@ -174,10 +174,10 @@ describe('atlasOptInReducer', function () { .dispatch(optIntoGenAIWithModalPrompt({ isCloudOptIn: true })) .catch(() => {}); - await Promise.all([ - store.dispatch(optIn()), - store.dispatch(cancelOptIn()), - ]); + const promise = store.dispatch(optIn()); + store.dispatch(cancelOptIn()); + await promise; + expect(store.getState().optIn).to.have.nested.property( 'state', 'canceled' diff --git a/packages/compass-indexes/src/modules/regular-indexes.ts b/packages/compass-indexes/src/modules/regular-indexes.ts index 661ea04d5c4..f4c4372d61b 100644 --- a/packages/compass-indexes/src/modules/regular-indexes.ts +++ b/packages/compass-indexes/src/modules/regular-indexes.ts @@ -425,8 +425,8 @@ const fetchIndexes = ( dataService.indexes(namespace), shouldFetchRollingIndexes ? rollingIndexesService.listRollingIndexes(namespace) - : undefined, - ] as [Promise, Promise | undefined]; + : Promise.resolve(undefined), + ] as const; const [indexes, rollingIndexes] = await Promise.all(promises); const indexesBefore = pickCollectionStatFields(getState()); dispatch(fetchIndexesSucceeded(indexes, rollingIndexes)); diff --git a/packages/compass-saved-aggregations-queries/src/stores/aggregations-queries-items.ts b/packages/compass-saved-aggregations-queries/src/stores/aggregations-queries-items.ts index de4532f51fb..ec55078b044 100644 --- a/packages/compass-saved-aggregations-queries/src/stores/aggregations-queries-items.ts +++ b/packages/compass-saved-aggregations-queries/src/stores/aggregations-queries-items.ts @@ -75,8 +75,12 @@ export const fetchItems = (): SavedQueryAggregationThunkAction< { pipelineStorage, queryStorage } ): Promise => { const payload = await Promise.allSettled([ - (await pipelineStorage?.loadAll())?.map(mapAggregationToItem) ?? [], - (await queryStorage?.loadAll())?.map(mapQueryToItem) ?? [], + pipelineStorage?.loadAll().then((items) => { + return items.map(mapAggregationToItem); + }) ?? Promise.resolve([]), + queryStorage?.loadAll().then((items) => { + return items.map(mapQueryToItem); + }) ?? Promise.resolve([]), ]); dispatch({ type: ActionTypes.ITEMS_FETCHED,