Skip to content

Commit 736f235

Browse files
authored
fix(eslint): fix await-thenable issues (#7606)
1 parent bab5540 commit 736f235

File tree

7 files changed

+31
-23
lines changed

7 files changed

+31
-23
lines changed

configs/eslint-config-compass/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const tempNewEslintRulesDisabled = {
1515
'react-hooks/static-components': 'off',
1616
'react-hooks/purity': 'off',
1717
'@typescript-eslint/no-redundant-type-constituents': 'off',
18-
'@typescript-eslint/await-thenable': 'off',
1918
'@typescript-eslint/no-unsafe-enum-comparison': 'off',
2019
};
2120

packages/compass-aggregations/src/modules/pipeline-builder/pipeline-preview-manager.spec.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@ describe('PipelinePreviewManager', function () {
2929
const dataService = mockDataService({ data: [] });
3030
const previewManager = new PipelinePreviewManager(dataService, preferences);
3131

32-
const result = await Promise.allSettled([
33-
previewManager.getPreviewForStage(0, 'test.test', []),
34-
previewManager.cancelPreviewForStage(0),
35-
]);
36-
37-
expect(result[0]).to.have.property('status', 'rejected');
38-
expect(result[0]).to.have.nested.property('reason.name', 'AbortError');
32+
try {
33+
const result = previewManager.getPreviewForStage(0, 'test.test', []);
34+
previewManager.cancelPreviewForStage(0);
35+
await result;
36+
expect.fail('Expected promise to reject');
37+
} catch (err) {
38+
expect(err).to.have.property('name', 'AbortError');
39+
}
3940
});
4041

4142
it('should debounce aggregation calls for the same stage', async function () {
@@ -108,7 +109,7 @@ describe('PipelinePreviewManager', function () {
108109
previewManager.getPreviewForStage(2, 'test.test', []),
109110
previewManager.getPreviewForStage(3, 'test.test', []),
110111
previewManager.getPreviewForStage(4, 'test.test', []),
111-
previewManager.clearQueue(1),
112+
Promise.resolve(previewManager.clearQueue(1)),
112113
]);
113114

114115
// Only pipeline for stage 0 was executed

packages/compass-connections/src/stores/connections-store-redux.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2100,10 +2100,9 @@ const cleanupConnection = (
21002100
const connectionAttempt = ConnectionAttemptForConnection.get(connectionId);
21012101
const dataService = DataServiceForConnection.get(connectionId);
21022102

2103-
void Promise.all([
2104-
connectionAttempt?.cancelConnectionAttempt(),
2105-
dataService?.disconnect(),
2106-
]).then(
2103+
connectionAttempt?.cancelConnectionAttempt();
2104+
2105+
void dataService?.disconnect().then(
21072106
() => {
21082107
debug('connection closed', connectionId);
21092108
},
@@ -2219,7 +2218,10 @@ export const removeAllRecentConnections = (): ConnectionsThunkAction<
22192218
toRemove.map((connection) => {
22202219
dispatch(cleanupConnection(connection.info.id));
22212220
track('Connection Removed', {}, connection.info);
2222-
return connectionStorage.delete?.({ id: connection.info.id });
2221+
return (
2222+
connectionStorage.delete?.({ id: connection.info.id }) ??
2223+
Promise.resolve()
2224+
);
22232225
})
22242226
);
22252227

packages/compass-e2e-tests/helpers/test-runner-global-fixtures.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ export async function mochaGlobalTeardown() {
174174
debug('Cleaning up after the tests ...');
175175
await Promise.allSettled(
176176
cleanupFns.map((fn) => {
177-
return fn();
177+
// We get a mix of sync and non-sync functions here. Awaiting even the
178+
// sync ones just makes the logic simpler
179+
return Promise.resolve(fn());
178180
})
179181
);
180182
}

packages/compass-generative-ai/src/store/atlas-optin-reducer.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,10 @@ describe('atlasOptInReducer', function () {
174174
.dispatch(optIntoGenAIWithModalPrompt({ isCloudOptIn: true }))
175175
.catch(() => {});
176176

177-
await Promise.all([
178-
store.dispatch(optIn()),
179-
store.dispatch(cancelOptIn()),
180-
]);
177+
const promise = store.dispatch(optIn());
178+
store.dispatch(cancelOptIn());
179+
await promise;
180+
181181
expect(store.getState().optIn).to.have.nested.property(
182182
'state',
183183
'canceled'

packages/compass-indexes/src/modules/regular-indexes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,8 @@ const fetchIndexes = (
425425
dataService.indexes(namespace),
426426
shouldFetchRollingIndexes
427427
? rollingIndexesService.listRollingIndexes(namespace)
428-
: undefined,
429-
] as [Promise<IndexDefinition[]>, Promise<AtlasIndexStats[]> | undefined];
428+
: Promise.resolve(undefined),
429+
] as const;
430430
const [indexes, rollingIndexes] = await Promise.all(promises);
431431
const indexesBefore = pickCollectionStatFields(getState());
432432
dispatch(fetchIndexesSucceeded(indexes, rollingIndexes));

packages/compass-saved-aggregations-queries/src/stores/aggregations-queries-items.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,12 @@ export const fetchItems = (): SavedQueryAggregationThunkAction<
7575
{ pipelineStorage, queryStorage }
7676
): Promise<void> => {
7777
const payload = await Promise.allSettled([
78-
(await pipelineStorage?.loadAll())?.map(mapAggregationToItem) ?? [],
79-
(await queryStorage?.loadAll())?.map(mapQueryToItem) ?? [],
78+
pipelineStorage?.loadAll().then((items) => {
79+
return items.map(mapAggregationToItem);
80+
}) ?? Promise.resolve([]),
81+
queryStorage?.loadAll().then((items) => {
82+
return items.map(mapQueryToItem);
83+
}) ?? Promise.resolve([]),
8084
]);
8185
dispatch({
8286
type: ActionTypes.ITEMS_FETCHED,

0 commit comments

Comments
 (0)