Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(shell-api): use strict TS config for testing #2105

Merged
merged 3 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions packages/cli-repl/src/mongosh-repl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,12 @@ describe('MongoshNodeRepl', function () {
// eslint-disable-next-line @typescript-eslint/require-await
cp.getConfig.callsFake(async (key: string) => config[key]);
// eslint-disable-next-line @typescript-eslint/require-await
cp.setConfig.callsFake(async (key: string, value: any) => {
config[key] = value;
return 'success';
});
cp.setConfig.callsFake(
async (key: string, value: any): Promise<'success'> => {
config[key] = value;
return 'success';
}
);
cp.listConfigOptions.callsFake(() => Object.keys(config));
cp.exit.callsFake(((code) => bus.emit('test-exit-event', code)) as any);

Expand Down
2 changes: 1 addition & 1 deletion packages/service-provider-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"scripts": {
"compile": "tsc -p tsconfig.json",
"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\"",
"test": "mocha -r \"../../scripts/import-expansions.js\" --timeout 60000 -r ts-node/register \"./src/**/*.spec.ts\"",
"test-ci": "node ../../scripts/run-if-package-requested.js npm test",
"test-coverage": "nyc --no-clean --cwd ../.. --reporter=none npm run test",
"test-ci-coverage": "nyc --no-clean --cwd ../.. --reporter=none npm run test-ci",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import type { DropDatabaseResult } from './cli-service-provider';
import CliServiceProvider from './cli-service-provider';
import CompassServiceProvider from './compass/compass-service-provider';
import { expect } from 'chai';
import { EventEmitter } from 'events';
import { MongoClient } from 'mongodb';
import type { Db } from 'mongodb';
import type {
AggregationCursor,
BulkWriteResult,
Db,
DeleteResult,
Document,
FindCursor,
InsertManyResult,
InsertOneResult,
UpdateResult,
} from 'mongodb';
import {
skipIfServerVersion,
startSharedTestServer,
Expand Down Expand Up @@ -157,7 +168,7 @@ describe('CliServiceProvider [integration]', function () {
'topology',
'extraInfo',
]);
expect(connectionInfo.buildInfo.version.length > 1);
expect(connectionInfo.buildInfo?.version.length).to.be.greaterThan(1);
});
});

Expand All @@ -171,7 +182,7 @@ describe('CliServiceProvider [integration]', function () {
'topology',
'extraInfo',
]);
expect(connectionInfo.buildInfo.version.length > 1);
expect(connectionInfo.buildInfo?.version.length).to.be.greaterThan(1);
});
});
});
Expand All @@ -182,15 +193,15 @@ describe('CliServiceProvider [integration]', function () {
function () {
skipIfServerVersion(testServer, '< 4.4');

let result;
let result: AggregationCursor;

beforeEach(function () {
const pipeline = [
{
$addFields: {
'attr.namespace': {
$function: {
body: function (value): any {
body: function (value: any): any {
if (value) {
return value;
}
Expand All @@ -213,7 +224,7 @@ describe('CliServiceProvider [integration]', function () {
);

context('when running against a collection', function () {
let result;
let result: AggregationCursor;

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

context('when running against a database', function () {
let result;
let result: AggregationCursor;

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

describe('#bulkWrite', function () {
context('when the filter is empty', function () {
let result;
let result: BulkWriteResult;
const requests = [
{
insertOne: { name: 'Aphex Twin' },
Expand All @@ -259,14 +270,14 @@ describe('CliServiceProvider [integration]', function () {
});

it('executes the count with an empty filter and resolves the result', function () {
expect(result.result.nInserted).to.equal(1);
expect((result as any).result.nInserted).to.equal(1);
});
});
});

describe('#count', function () {
context('when the filter is empty', function () {
let result;
let result: number;

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

describe('#countDocuments', function () {
context('when the filter is empty', function () {
let result;
let result: number;

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

describe('#deleteMany', function () {
context('when the filter is empty', function () {
let result;
let result: DeleteResult;

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

describe('#deleteOne', function () {
context('when the filter is empty', function () {
let result;
let result: DeleteResult;

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

describe('#distinct', function () {
context('when the distinct is valid', function () {
let result;
let result: Document[];

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

describe('#estimatedDocumentCount', function () {
context('when no options are provided', function () {
let result;
let result: number;

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

describe('#find', function () {
context('when the find is valid', function () {
let result;
let result: FindCursor;

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

describe('#findOneAndDelete', function () {
context('when the find is valid', function () {
let result;
let result: Document | null;
const filter = { name: 'Aphex Twin' };

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

it('executes the command and resolves the result', function () {
expect(result.ok).to.equal(1);
expect(result?.ok).to.equal(1);
});
});
});

describe('#findOneAndReplace', function () {
context('when the find is valid', function () {
let result;
let result: Document;
const filter = { name: 'Aphex Twin' };
const replacement = { name: 'Richard James' };

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

describe('#findOneAndUpdate', function () {
context('when the find is valid', function () {
let result;
let result: Document;
const filter = { name: 'Aphex Twin' };
const update = { $set: { name: 'Richard James' } };

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

describe('#insertMany', function () {
context('when the insert is valid', function () {
let result;
let result: InsertManyResult;

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

describe('#insertOne', function () {
context('when the insert is valid', function () {
let result;
let result: InsertOneResult;

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

describe('#listDatabases', function () {
let result;
let result: Document;

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

it('returns a list of databases', function () {
expect(result.ok).to.equal(1);
expect(result.databases.map((db) => db.name)).to.include('admin');
expect(
result.databases.map((db: { name: string }) => db.name)
).to.include('admin');
});
});

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

context('when the filter is empty', function () {
let result;
let result: UpdateResult;

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

describe('#runCommand', function () {
context('when the command is valid', function () {
let result;
let result: Document;

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

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

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

describe('#dropDatabase', function () {
context('when a database does not exist', function () {
let result;
let result: DropDatabaseResult;

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

context('when a database exists', function () {
let result;
let result: DropDatabaseResult;

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

describe('#driverMetadata', function () {
it('returns information about the driver instance', function () {
expect(serviceProvider.driverMetadata.driver.name).to.equal('nodejs');
expect(serviceProvider.driverMetadata?.driver.name).to.equal('nodejs');
});
});

Expand Down
Loading
Loading