Skip to content

Commit edc8751

Browse files
authored
chore(compass-connections): typecheck test files (#7570)
1 parent 041f647 commit edc8751

File tree

9 files changed

+39
-24
lines changed

9 files changed

+39
-24
lines changed

package-lock.json

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compass-connections/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,14 @@
4747
"test-ci": "npm run test-cov",
4848
"test-ci-electron": "npm run test-electron",
4949
"reformat": "npm run eslint . -- --fix && npm run prettier -- --write .",
50-
"typecheck": "echo \"TODO(COMPASS-9897): typecheck is failing in test files\" && tsc -p tsconfig-build.json --noEmit"
50+
"typecheck": "tsc -p tsconfig.json --noEmit"
5151
},
5252
"dependencies": {
5353
"@mongodb-js/compass-app-registry": "^9.4.28",
5454
"@mongodb-js/compass-assistant": "^1.19.0",
5555
"@mongodb-js/compass-components": "^1.59.0",
5656
"@mongodb-js/compass-logging": "^1.7.24",
5757
"@mongodb-js/compass-telemetry": "^1.19.3",
58-
"@mongodb-js/compass-utils": "^0.9.22",
5958
"@mongodb-js/connection-form": "^1.74.0",
6059
"@mongodb-js/connection-info": "^0.23.0",
6160
"@mongodb-js/connection-storage": "^0.62.0",

packages/compass-connections/src/components/connection-status-notifications.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
import type { ConnectionInfo } from '@mongodb-js/connection-info';
1515
import { getConnectionTitle } from '@mongodb-js/connection-info';
1616
import ConnectionString from 'mongodb-connection-string-url';
17-
import { isCancelError } from '@mongodb-js/compass-utils';
1817

1918
export function isOIDCAuth(connectionString: string): boolean {
2019
const authMechanismString = (
@@ -25,10 +24,6 @@ export function isOIDCAuth(connectionString: string): boolean {
2524
return authMechanismString === 'MONGODB-OIDC';
2625
}
2726

28-
export function getConnectionErrorMessage(err?: any) {
29-
return isCancelError(err) ? null : err?.message ?? null;
30-
}
31-
3227
export function getConnectingStatusText(connectionInfo: ConnectionInfo) {
3328
const connectionTitle = getConnectionTitle(connectionInfo);
3429
const isOIDC = isOIDCAuth(connectionInfo.connectionOptions.connectionString);

packages/compass-connections/src/connection-scoped-app-registry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export type ConnectionScopedAppRegistry<
2020
Partial<Pick<ConnectionScopedAppRegistryImpl<T>, L>>;
2121

2222
interface EventForwarder<T extends string> {
23-
emit(event: T, ...payload: any[]): void;
23+
emit(event: T, ...payload: unknown[]): void;
2424
}
2525

2626
export class ConnectionScopedAppRegistryImpl<T extends string>
@@ -43,7 +43,7 @@ export class ConnectionScopedAppRegistryImpl<T extends string>
4343
* to understand how other plugins communicate with these plugins without
4444
* relying on AppRegistry events.
4545
*/
46-
emit(event: T, ...payload: any[]): void {
46+
emit(event: T, ...payload: unknown[]): void {
4747
const connectionId = this.connectionInfoRef.current.id;
4848
this.appRegistryEmitter(event, ...payload, { connectionId });
4949
}

packages/compass-connections/src/hooks/use-connection-supports.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const mockConnections: ConnectionInfo[] = [
3030
globalWrites: false,
3131
rollingIndexes: false,
3232
},
33+
userConnectionString: 'mongodb+srv://foo',
3334
},
3435
},
3536
{
@@ -52,6 +53,7 @@ const mockConnections: ConnectionInfo[] = [
5253
globalWrites: false,
5354
rollingIndexes: false,
5455
},
56+
userConnectionString: 'mongodb+srv://foo',
5557
},
5658
},
5759
{
@@ -74,6 +76,7 @@ const mockConnections: ConnectionInfo[] = [
7476
globalWrites: false,
7577
rollingIndexes: false,
7678
},
79+
userConnectionString: 'mongodb+srv://foo',
7780
},
7881
},
7982
{
@@ -96,6 +99,7 @@ const mockConnections: ConnectionInfo[] = [
9699
globalWrites: false,
97100
rollingIndexes: true,
98101
},
102+
userConnectionString: 'mongodb+srv://foo',
99103
},
100104
},
101105
{
@@ -118,6 +122,7 @@ const mockConnections: ConnectionInfo[] = [
118122
globalWrites: false,
119123
rollingIndexes: true,
120124
},
125+
userConnectionString: 'mongodb+srv://foo',
121126
},
122127
},
123128
{
@@ -140,6 +145,7 @@ const mockConnections: ConnectionInfo[] = [
140145
globalWrites: true,
141146
rollingIndexes: true,
142147
},
148+
userConnectionString: 'mongodb+srv://foo',
143149
},
144150
},
145151
];

packages/compass-connections/src/hooks/use-connections-with-status.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe('useConnectionsWithStatus', function () {
6060
}
6161
);
6262

63-
function getConnectionById(id) {
63+
function getConnectionById(id: string) {
6464
return result.current.find((conn) => {
6565
return conn.connectionInfo.id === id;
6666
});

packages/compass-connections/src/stores/connections-store-redux.spec.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ describe('CompassConnections store', function () {
240240
});
241241

242242
it('should show device auth code modal when OIDC flow triggers the notification', async function () {
243-
let resolveConnect;
243+
let resolveConnect: undefined | (() => void);
244244
const connectFn = sinon.stub().callsFake(() => {
245245
return new Promise((resolve) => {
246246
resolveConnect = () => resolve({});
@@ -278,6 +278,7 @@ describe('CompassConnections store', function () {
278278
expect(screen.getByText('ABCabc123')).to.exist;
279279
});
280280

281+
if (!resolveConnect) throw new Error('resolveConnect is not defined');
281282
resolveConnect();
282283

283284
await connectPromise;
@@ -373,7 +374,8 @@ describe('CompassConnections store', function () {
373374
});
374375

375376
// Send a heartbeat fail with an error that's not a non-retryable error code.
376-
dataService['emit']('serverHeartbeatFailed', {
377+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
378+
(dataService as any)['emit']('serverHeartbeatFailed', {
377379
failure: new Error('code: 1234, Not the error we are looking for'),
378380
});
379381

@@ -413,7 +415,8 @@ describe('CompassConnections store', function () {
413415
dataService.isConnected = () => true;
414416

415417
// Send a heartbeat fail with an error that's a non-retryable error code.
416-
dataService['emit']('serverHeartbeatFailed', {
418+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
419+
(dataService as any)['emit']('serverHeartbeatFailed', {
417420
failure: new Error('code: 3003, reason: Insufficient permissions'),
418421
});
419422

@@ -497,10 +500,12 @@ describe('CompassConnections store', function () {
497500
// proceeding
498501
connectionsStore.actions.createNewConnection();
499502

503+
const connectionInfoId =
504+
connectionsStore.getState().editingConnectionInfoId;
505+
if (!connectionInfoId) throw new Error('No editingConnectionInfoId set');
506+
500507
const editingConnection =
501-
connectionsStore.getState().connections.byId[
502-
connectionsStore.getState().editingConnectionInfoId
503-
];
508+
connectionsStore.getState().connections.byId[connectionInfoId];
504509

505510
const newConnection = {
506511
...editingConnection.info,

packages/compass-connections/src/utils/connection-supports.spec.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { connectionSupports } from './connection-supports';
22
import { type ConnectionInfo } from '@mongodb-js/connection-storage/provider';
33
import { expect } from 'chai';
44

5-
const mockConnections = [
5+
const mockConnections: ConnectionInfo[] = [
66
{
77
id: 'no-atlasMetadata',
88
connectionOptions: {
@@ -29,6 +29,7 @@ const mockConnections = [
2929
globalWrites: false,
3030
rollingIndexes: false,
3131
},
32+
userConnectionString: 'mongodb+srv://foo',
3233
},
3334
},
3435
{
@@ -51,6 +52,7 @@ const mockConnections = [
5152
globalWrites: false,
5253
rollingIndexes: false,
5354
},
55+
userConnectionString: 'mongodb+srv://foo',
5456
},
5557
},
5658
{
@@ -73,6 +75,7 @@ const mockConnections = [
7375
globalWrites: false,
7476
rollingIndexes: false,
7577
},
78+
userConnectionString: 'mongodb+srv://foo',
7679
},
7780
},
7881
{
@@ -95,6 +98,7 @@ const mockConnections = [
9598
globalWrites: false,
9699
rollingIndexes: true,
97100
},
101+
userConnectionString: 'mongodb+srv://foo',
98102
},
99103
},
100104
{
@@ -117,6 +121,7 @@ const mockConnections = [
117121
globalWrites: false,
118122
rollingIndexes: true,
119123
},
124+
userConnectionString: 'mongodb+srv://foo',
120125
},
121126
},
122127
{
@@ -139,6 +144,7 @@ const mockConnections = [
139144
globalWrites: true,
140145
rollingIndexes: true,
141146
},
147+
userConnectionString: 'mongodb+srv://foo',
142148
},
143149
},
144150
{
@@ -161,6 +167,7 @@ const mockConnections = [
161167
globalWrites: false,
162168
rollingIndexes: true,
163169
},
170+
userConnectionString: 'mongodb+srv://foo',
164171
},
165172
},
166173
{
@@ -183,6 +190,7 @@ const mockConnections = [
183190
globalWrites: false,
184191
rollingIndexes: false,
185192
},
193+
userConnectionString: 'mongodb+srv://foo',
186194
},
187195
},
188196
] as const;

packages/compass-connections/src/utils/telemetry.spec.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { expect } from 'chai';
99
import type { ConnectionInfo } from '@mongodb-js/connection-storage/renderer';
1010
import { createIpcTrack } from '@mongodb-js/compass-telemetry';
1111

12+
type ErrorWithCause = Error & { cause?: ErrorWithCause };
13+
1214
describe('Connections telemetry', function () {
1315
const connectionInfo: ConnectionInfo = {
1416
id: 'TEST',
@@ -78,26 +80,28 @@ describe('Connections telemetry', function () {
7880
});
7981

8082
it('should return an array with the error code', function () {
81-
const error: any = new Error('Test error');
83+
const error: Error & { code?: number } = new Error('Test error');
8284
error.code = 123;
8385

8486
const result = getErrorCodeCauseChain(error);
8587
expect(result).to.deep.equal([123]);
8688
});
8789

8890
it('should return an array of error codes from the cause chain', function () {
89-
const error: Error & { code?: number } = new Error('Test error');
91+
const error: ErrorWithCause & { code?: number } = new Error('Test error');
9092
error.code = 123;
9193

9294
// No code / codeName on error two.
93-
const errorTwo = new Error('Test error two');
95+
const errorTwo: ErrorWithCause = new Error('Test error two');
9496

95-
const errorThree: Error & { codeName?: string } = new Error(
97+
const errorThree: ErrorWithCause & { codeName?: string } = new Error(
9698
'Test error three'
9799
);
98100
errorThree.codeName = 'PINEAPPLE';
99101

100-
const errorFour: Error & { code?: number } = new Error('Test error four');
102+
const errorFour: ErrorWithCause & {
103+
code?: number;
104+
} = new Error('Test error four');
101105
errorFour.code = 1111;
102106

103107
error.cause = errorTwo;

0 commit comments

Comments
 (0)