Skip to content

Commit 4f9f6bf

Browse files
authored
chore(shell-api): use strict TS config for testing (#2105)
1 parent 10d6b60 commit 4f9f6bf

32 files changed

+812
-690
lines changed

packages/cli-repl/src/mongosh-repl.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ describe('MongoshNodeRepl', function () {
6666
// eslint-disable-next-line @typescript-eslint/require-await
6767
cp.getConfig.callsFake(async (key: string) => config[key]);
6868
// eslint-disable-next-line @typescript-eslint/require-await
69-
cp.setConfig.callsFake(async (key: string, value: any) => {
69+
cp.setConfig.callsFake((key: string, value: any): 'success' => {
7070
config[key] = value;
7171
return 'success';
7272
});

packages/service-provider-server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
"scripts": {
1515
"compile": "tsc -p tsconfig.json",
16-
"test": "cross-env TS_NODE_PROJECT=../../configs/tsconfig-mongosh/tsconfig.test.json mocha -r \"../../scripts/import-expansions.js\" --timeout 60000 -r ts-node/register \"./src/**/*.spec.ts\"",
16+
"test": "mocha -r \"../../scripts/import-expansions.js\" --timeout 60000 -r ts-node/register \"./src/**/*.spec.ts\"",
1717
"test-ci": "node ../../scripts/run-if-package-requested.js npm test",
1818
"test-coverage": "nyc --no-clean --cwd ../.. --reporter=none npm run test",
1919
"test-ci-coverage": "nyc --no-clean --cwd ../.. --reporter=none npm run test-ci",

packages/service-provider-server/src/cli-service-provider.integration.spec.ts

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1+
import type { DropDatabaseResult } from './cli-service-provider';
12
import CliServiceProvider from './cli-service-provider';
23
import CompassServiceProvider from './compass/compass-service-provider';
34
import { expect } from 'chai';
45
import { EventEmitter } from 'events';
56
import { MongoClient } from 'mongodb';
6-
import type { Db } from 'mongodb';
7+
import type {
8+
AggregationCursor,
9+
BulkWriteResult,
10+
Db,
11+
DeleteResult,
12+
Document,
13+
FindCursor,
14+
InsertManyResult,
15+
InsertOneResult,
16+
UpdateResult,
17+
} from 'mongodb';
718
import {
819
skipIfServerVersion,
920
startSharedTestServer,
@@ -157,7 +168,7 @@ describe('CliServiceProvider [integration]', function () {
157168
'topology',
158169
'extraInfo',
159170
]);
160-
expect(connectionInfo.buildInfo.version.length > 1);
171+
expect(connectionInfo.buildInfo?.version.length).to.be.greaterThan(1);
161172
});
162173
});
163174

@@ -171,7 +182,7 @@ describe('CliServiceProvider [integration]', function () {
171182
'topology',
172183
'extraInfo',
173184
]);
174-
expect(connectionInfo.buildInfo.version.length > 1);
185+
expect(connectionInfo.buildInfo?.version.length).to.be.greaterThan(1);
175186
});
176187
});
177188
});
@@ -182,15 +193,15 @@ describe('CliServiceProvider [integration]', function () {
182193
function () {
183194
skipIfServerVersion(testServer, '< 4.4');
184195

185-
let result;
196+
let result: AggregationCursor;
186197

187198
beforeEach(function () {
188199
const pipeline = [
189200
{
190201
$addFields: {
191202
'attr.namespace': {
192203
$function: {
193-
body: function (value): any {
204+
body: function (value: any): any {
194205
if (value) {
195206
return value;
196207
}
@@ -213,7 +224,7 @@ describe('CliServiceProvider [integration]', function () {
213224
);
214225

215226
context('when running against a collection', function () {
216-
let result;
227+
let result: AggregationCursor;
217228

218229
beforeEach(function () {
219230
result = serviceProvider.aggregate('music', 'bands', [
@@ -228,7 +239,7 @@ describe('CliServiceProvider [integration]', function () {
228239
});
229240

230241
context('when running against a database', function () {
231-
let result;
242+
let result: AggregationCursor;
232243

233244
beforeEach(function () {
234245
result = serviceProvider.aggregateDb('admin', [{ $currentOp: {} }]);
@@ -243,7 +254,7 @@ describe('CliServiceProvider [integration]', function () {
243254

244255
describe('#bulkWrite', function () {
245256
context('when the filter is empty', function () {
246-
let result;
257+
let result: BulkWriteResult;
247258
const requests = [
248259
{
249260
insertOne: { name: 'Aphex Twin' },
@@ -259,14 +270,14 @@ describe('CliServiceProvider [integration]', function () {
259270
});
260271

261272
it('executes the count with an empty filter and resolves the result', function () {
262-
expect(result.result.nInserted).to.equal(1);
273+
expect((result as any).result.nInserted).to.equal(1);
263274
});
264275
});
265276
});
266277

267278
describe('#count', function () {
268279
context('when the filter is empty', function () {
269-
let result;
280+
let result: number;
270281

271282
beforeEach(async function () {
272283
result = await serviceProvider.count('music', 'bands');
@@ -280,7 +291,7 @@ describe('CliServiceProvider [integration]', function () {
280291

281292
describe('#countDocuments', function () {
282293
context('when the filter is empty', function () {
283-
let result;
294+
let result: number;
284295

285296
beforeEach(async function () {
286297
result = await serviceProvider.countDocuments('music', 'bands');
@@ -294,7 +305,7 @@ describe('CliServiceProvider [integration]', function () {
294305

295306
describe('#deleteMany', function () {
296307
context('when the filter is empty', function () {
297-
let result;
308+
let result: DeleteResult;
298309

299310
beforeEach(async function () {
300311
result = await serviceProvider.deleteMany('music', 'bands', {});
@@ -308,7 +319,7 @@ describe('CliServiceProvider [integration]', function () {
308319

309320
describe('#deleteOne', function () {
310321
context('when the filter is empty', function () {
311-
let result;
322+
let result: DeleteResult;
312323

313324
beforeEach(async function () {
314325
result = await serviceProvider.deleteOne('music', 'bands', {});
@@ -322,7 +333,7 @@ describe('CliServiceProvider [integration]', function () {
322333

323334
describe('#distinct', function () {
324335
context('when the distinct is valid', function () {
325-
let result;
336+
let result: Document[];
326337

327338
beforeEach(async function () {
328339
result = await serviceProvider.distinct('music', 'bands', 'name');
@@ -336,7 +347,7 @@ describe('CliServiceProvider [integration]', function () {
336347

337348
describe('#estimatedDocumentCount', function () {
338349
context('when no options are provided', function () {
339-
let result;
350+
let result: number;
340351

341352
beforeEach(async function () {
342353
result = await serviceProvider.estimatedDocumentCount('music', 'bands');
@@ -350,7 +361,7 @@ describe('CliServiceProvider [integration]', function () {
350361

351362
describe('#find', function () {
352363
context('when the find is valid', function () {
353-
let result;
364+
let result: FindCursor;
354365

355366
beforeEach(function () {
356367
result = serviceProvider.find('music', 'bands', { name: 'Aphex Twin' });
@@ -365,7 +376,7 @@ describe('CliServiceProvider [integration]', function () {
365376

366377
describe('#findOneAndDelete', function () {
367378
context('when the find is valid', function () {
368-
let result;
379+
let result: Document | null;
369380
const filter = { name: 'Aphex Twin' };
370381

371382
beforeEach(async function () {
@@ -377,14 +388,14 @@ describe('CliServiceProvider [integration]', function () {
377388
});
378389

379390
it('executes the command and resolves the result', function () {
380-
expect(result.ok).to.equal(1);
391+
expect(result?.ok).to.equal(1);
381392
});
382393
});
383394
});
384395

385396
describe('#findOneAndReplace', function () {
386397
context('when the find is valid', function () {
387-
let result;
398+
let result: Document;
388399
const filter = { name: 'Aphex Twin' };
389400
const replacement = { name: 'Richard James' };
390401

@@ -405,7 +416,7 @@ describe('CliServiceProvider [integration]', function () {
405416

406417
describe('#findOneAndUpdate', function () {
407418
context('when the find is valid', function () {
408-
let result;
419+
let result: Document;
409420
const filter = { name: 'Aphex Twin' };
410421
const update = { $set: { name: 'Richard James' } };
411422

@@ -426,7 +437,7 @@ describe('CliServiceProvider [integration]', function () {
426437

427438
describe('#insertMany', function () {
428439
context('when the insert is valid', function () {
429-
let result;
440+
let result: InsertManyResult;
430441

431442
beforeEach(async function () {
432443
result = await serviceProvider.insertMany('music', 'bands', [
@@ -446,7 +457,7 @@ describe('CliServiceProvider [integration]', function () {
446457

447458
describe('#insertOne', function () {
448459
context('when the insert is valid', function () {
449-
let result;
460+
let result: InsertOneResult;
450461

451462
beforeEach(async function () {
452463
result = await serviceProvider.insertOne('music', 'bands', {
@@ -465,15 +476,17 @@ describe('CliServiceProvider [integration]', function () {
465476
});
466477

467478
describe('#listDatabases', function () {
468-
let result;
479+
let result: Document;
469480

470481
beforeEach(async function () {
471482
result = await serviceProvider.listDatabases('admin');
472483
});
473484

474485
it('returns a list of databases', function () {
475486
expect(result.ok).to.equal(1);
476-
expect(result.databases.map((db) => db.name)).to.include('admin');
487+
expect(
488+
result.databases.map((db: { name: string }) => db.name)
489+
).to.include('admin');
477490
});
478491
});
479492

@@ -482,7 +495,7 @@ describe('CliServiceProvider [integration]', function () {
482495
const replacement = { name: 'Richard James' };
483496

484497
context('when the filter is empty', function () {
485-
let result;
498+
let result: UpdateResult;
486499

487500
beforeEach(async function () {
488501
result = await serviceProvider.replaceOne(
@@ -501,7 +514,7 @@ describe('CliServiceProvider [integration]', function () {
501514

502515
describe('#runCommand', function () {
503516
context('when the command is valid', function () {
504-
let result;
517+
let result: Document;
505518

506519
beforeEach(async function () {
507520
result = await serviceProvider.runCommand('admin', { ismaster: true });
@@ -517,7 +530,7 @@ describe('CliServiceProvider [integration]', function () {
517530
const filter = { name: 'Aphex Twin' };
518531
const update = { $set: { name: 'Richard James' } };
519532
context('when the filter is empty', function () {
520-
let result;
533+
let result: UpdateResult;
521534

522535
beforeEach(async function () {
523536
result = await serviceProvider.updateMany(
@@ -538,7 +551,7 @@ describe('CliServiceProvider [integration]', function () {
538551
const filter = { name: 'Aphex Twin' };
539552
const update = { $set: { name: 'Richard James' } };
540553
context('when the filter is empty', function () {
541-
let result;
554+
let result: UpdateResult;
542555

543556
beforeEach(async function () {
544557
result = await serviceProvider.updateOne(
@@ -570,7 +583,7 @@ describe('CliServiceProvider [integration]', function () {
570583

571584
describe('#dropDatabase', function () {
572585
context('when a database does not exist', function () {
573-
let result;
586+
let result: DropDatabaseResult;
574587

575588
it('returns {ok: 1}', async function () {
576589
result = await serviceProvider.dropDatabase(`test-db-${Date.now()}`);
@@ -579,7 +592,7 @@ describe('CliServiceProvider [integration]', function () {
579592
});
580593

581594
context('when a database exists', function () {
582-
let result;
595+
let result: DropDatabaseResult;
583596

584597
const dbExists = async (): Promise<boolean> => {
585598
return (await db.admin().listDatabases()).databases
@@ -734,7 +747,7 @@ describe('CliServiceProvider [integration]', function () {
734747
(collection) => collection.name === 'coll1'
735748
);
736749
expect(matchingCollection).to.not.be.undefined;
737-
expect(matchingCollection.options).to.deep.contain({
750+
expect(matchingCollection?.options).to.deep.contain({
738751
clusteredIndex: {
739752
v: 2,
740753
key: { _id: 1 },
@@ -792,7 +805,7 @@ describe('CliServiceProvider [integration]', function () {
792805

793806
describe('#driverMetadata', function () {
794807
it('returns information about the driver instance', function () {
795-
expect(serviceProvider.driverMetadata.driver.name).to.equal('nodejs');
808+
expect(serviceProvider.driverMetadata?.driver.name).to.equal('nodejs');
796809
});
797810
});
798811

0 commit comments

Comments
 (0)