Skip to content

Commit 648212c

Browse files
committed
lint: fix ts issues in unified runner
1 parent 0a68ee2 commit 648212c

File tree

4 files changed

+108
-92
lines changed

4 files changed

+108
-92
lines changed

test/tools/unified-spec-runner/entities.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
12
import { expect } from 'chai';
23

34
import { ChangeStream } from '../../../src/change_stream';
@@ -179,7 +180,7 @@ export class FailPointMap extends Map<string, Document> {
179180
let address: string;
180181
if (addressOrClient instanceof MongoClient) {
181182
client = addressOrClient;
182-
address = client.topology.s.seedlist.join(',');
183+
address = client.topology!.s.seedlist.join(',');
183184
} else {
184185
// create a new client
185186
address = addressOrClient.toString();
@@ -300,7 +301,7 @@ export class EntitiesMap<E = Entity> extends Map<string, E> {
300301
getEntity(type: 'cursor', key: string, assertExists?: boolean): AbstractCursor;
301302
getEntity(type: 'stream', key: string, assertExists?: boolean): UnifiedChangeStream;
302303
getEntity(type: 'clientEncryption', key: string, assertExists?: boolean): ClientEncryption;
303-
getEntity(type: EntityTypeId, key: string, assertExists = true): Entity {
304+
getEntity(type: EntityTypeId, key: string, assertExists = true): Entity | undefined {
304305
const entity = this.get(key);
305306
if (!entity) {
306307
if (assertExists) throw new Error(`Entity '${key}' does not exist`);
@@ -373,14 +374,14 @@ export class EntitiesMap<E = Entity> extends Map<string, E> {
373374
const client = map.getEntity('client', entity.database.client);
374375
const db = client.db(
375376
entity.database.databaseName,
376-
patchDbOptions(entity.database.databaseOptions)
377+
patchDbOptions(entity.database.databaseOptions!)
377378
);
378379
map.set(entity.database.id, db);
379380
} else if ('collection' in entity) {
380381
const db = map.getEntity('db', entity.collection.database);
381382
const collection = db.collection(
382383
entity.collection.collectionName,
383-
patchCollectionOptions(entity.collection.collectionOptions)
384+
patchCollectionOptions(entity.collection.collectionOptions!)
384385
);
385386
map.set(entity.collection.id, collection);
386387
} else if ('session' in entity) {

test/tools/unified-spec-runner/match.ts

+31-22
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
12
import { expect } from 'chai';
23
import { inspect } from 'util';
34

@@ -265,11 +266,11 @@ export function specialCheck(
265266
entities: EntitiesMap,
266267
path: string[] = [],
267268
checkExtraKeys: boolean
268-
): boolean {
269+
): void {
269270
if (isUnsetOrMatchesOperator(expected)) {
270271
if (actual === null || actual === undefined) return;
271272

272-
resultCheck(actual, expected.$$unsetOrMatches, entities, path, checkExtraKeys);
273+
resultCheck(actual, expected.$$unsetOrMatches as any, entities, path, checkExtraKeys);
273274
} else if (isMatchesEntityOperator(expected)) {
274275
// $$matchesEntity
275276
const entity = entities.get(expected.$$matchesEntity);
@@ -291,15 +292,15 @@ export function specialCheck(
291292
// $$sessionLsid
292293
const session = entities.getEntity('session', expected.$$sessionLsid, false);
293294
expect(session, `Session ${expected.$$sessionLsid} does not exist in entities`).to.exist;
294-
const entitySessionHex = session.id.id.buffer.toString('hex').toUpperCase();
295+
const entitySessionHex = session.id!.id.buffer.toString('hex').toUpperCase();
295296
const actualSessionHex = actual.id.buffer.toString('hex').toUpperCase();
296297
expect(
297298
entitySessionHex,
298299
`Session entity ${expected.$$sessionLsid} does not match lsid`
299300
).to.equal(actualSessionHex);
300301
} else if (isTypeOperator(expected)) {
301302
// $$type
302-
let ok: boolean;
303+
let ok = false;
303304
const types = Array.isArray(expected.$$type) ? expected.$$type : [expected.$$type];
304305
for (const type of types) {
305306
ok ||= TYPE_MAP.get(type)(actual);
@@ -365,19 +366,23 @@ function compareCommandStartedEvents(
365366
entities: EntitiesMap,
366367
prefix: string
367368
) {
368-
if (expected.command) {
369-
resultCheck(actual.command, expected.command, entities, [`${prefix}.command`]);
369+
if (expected!.command) {
370+
resultCheck(actual.command, expected!.command, entities, [`${prefix}.command`]);
370371
}
371-
if (expected.commandName) {
372+
if (expected!.commandName) {
372373
expect(
373-
expected.commandName,
374-
`expected ${prefix}.commandName to equal ${expected.commandName} but received ${actual.commandName}`
374+
expected!.commandName,
375+
`expected ${prefix}.commandName to equal ${expected!.commandName} but received ${
376+
actual.commandName
377+
}`
375378
).to.equal(actual.commandName);
376379
}
377-
if (expected.databaseName) {
380+
if (expected!.databaseName) {
378381
expect(
379-
expected.databaseName,
380-
`expected ${prefix}.databaseName to equal ${expected.databaseName} but received ${actual.databaseName}`
382+
expected!.databaseName,
383+
`expected ${prefix}.databaseName to equal ${expected!.databaseName} but received ${
384+
actual.databaseName
385+
}`
381386
).to.equal(actual.databaseName);
382387
}
383388
}
@@ -388,13 +393,15 @@ function compareCommandSucceededEvents(
388393
entities: EntitiesMap,
389394
prefix: string
390395
) {
391-
if (expected.reply) {
392-
resultCheck(actual.reply, expected.reply, entities, [prefix]);
396+
if (expected!.reply) {
397+
resultCheck(actual.reply as Document, expected!.reply, entities, [prefix]);
393398
}
394-
if (expected.commandName) {
399+
if (expected!.commandName) {
395400
expect(
396-
expected.commandName,
397-
`expected ${prefix}.commandName to equal ${expected.commandName} but received ${actual.commandName}`
401+
expected!.commandName,
402+
`expected ${prefix}.commandName to equal ${expected!.commandName} but received ${
403+
actual.commandName
404+
}`
398405
).to.equal(actual.commandName);
399406
}
400407
}
@@ -405,10 +412,12 @@ function compareCommandFailedEvents(
405412
entities: EntitiesMap,
406413
prefix: string
407414
) {
408-
if (expected.commandName) {
415+
if (expected!.commandName) {
409416
expect(
410-
expected.commandName,
411-
`expected ${prefix}.commandName to equal ${expected.commandName} but received ${actual.commandName}`
417+
expected!.commandName,
418+
`expected ${prefix}.commandName to equal ${expected!.commandName} but received ${
419+
actual.commandName
420+
}`
412421
).to.equal(actual.commandName);
413422
}
414423
}
@@ -501,7 +510,7 @@ export function expectErrorCheck(
501510
error: Error | MongoError,
502511
expected: ExpectedError,
503512
entities: EntitiesMap
504-
): boolean {
513+
): void {
505514
const expectMessage = `\n\nOriginal Error Stack:\n${error.stack}\n\n`;
506515

507516
if (!isMongoCryptError(error)) {
@@ -547,6 +556,6 @@ export function expectErrorCheck(
547556
}
548557

549558
if (expected.expectResult != null) {
550-
resultCheck(error, expected.expectResult, entities);
559+
resultCheck(error, expected.expectResult as any, entities);
551560
}
552561
}

0 commit comments

Comments
 (0)