Skip to content

Commit

Permalink
chore(e2e-tests): use strict TS config (#1860)
Browse files Browse the repository at this point in the history
  • Loading branch information
addaleax authored Mar 11, 2024
1 parent 1e76b37 commit fe78c6b
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 51 deletions.
124 changes: 115 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"@types/which": "^1.3.2",
"chai": "^4.2.0",
"cross-env": "^6.0.3",
"duplexpair": "^1.0.1",
"duplexpair": "^1.0.2",
"find-up": "^5.0.0",
"husky": "^8.0.3",
"mocha": "^10.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"url": "git://github.com/mongodb-js/mongosh.git"
},
"scripts": {
"test": "cross-env TS_NODE_PROJECT=../../configs/tsconfig-mongosh/tsconfig.test.json mocha -r \"../../scripts/import-expansions.js\" --timeout 15000 --colors -r ts-node/register \"./test/e2e*.spec.ts\"",
"test": "mocha -r \"../../scripts/import-expansions.js\" --timeout 15000 --colors -r ts-node/register \"./test/e2e*.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
43 changes: 29 additions & 14 deletions packages/e2e-tests/test/e2e-auth.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import type { MongoClientOptions } from 'mongodb';
import type { Db, Document, MongoClientOptions } from 'mongodb';
import { MongoClient } from 'mongodb';
import { eventually } from '../../../testing/eventually';
import { TestShell } from './test-shell';
Expand All @@ -8,7 +8,8 @@ import {
startSharedTestServer,
} from '../../../testing/integration-testing-hooks';

function createAssertUserExists(db, dbName): Function {
type AssertUserExists = (opts?: Document, username?: string) => Promise<void>;
function createAssertUserExists(db: Db, dbName: string): AssertUserExists {
return async (opts = {}, username = 'anna'): Promise<void> => {
const result = await db.command({ usersInfo: 1 });
expect(result.users.length).to.equal(1);
Expand All @@ -21,7 +22,12 @@ function createAssertUserExists(db, dbName): Function {
};
}

function createAssertRoleExists(db, dbName): Function {
type AssertRoleExists = (
roles: Document[],
privileges: Document[],
rolename?: string
) => Promise<void>;
function createAssertRoleExists(db: Db, dbName: string): AssertRoleExists {
return async (roles, privileges, rolename = 'anna'): Promise<void> => {
const result = await db.command({
rolesInfo: 1,
Expand All @@ -45,7 +51,16 @@ function createAssertRoleExists(db, dbName): Function {
};
}

function createAssertUserAuth(db, connectionString, dbName): Function {
type AssertUserAuth = (
pwd?: string,
username?: string,
keepClient?: boolean
) => Promise<void | MongoClient>;
function createAssertUserAuth(
db: Db,
connectionString: string,
dbName: string
): AssertUserAuth {
return async (
pwd = 'pwd',
username = 'anna',
Expand Down Expand Up @@ -73,16 +88,16 @@ describe('Auth e2e', function () {
skipIfApiStrict(); // connectionStatus is unversioned.

const testServer = startSharedTestServer();
let assertUserExists;
let assertUserAuth;
let assertRoleExists;
let assertUserExists: AssertUserExists;
let assertUserAuth: AssertUserAuth;
let assertRoleExists: AssertRoleExists;

let db;
let client;
let db: Db;
let client: MongoClient;
let shell: TestShell;
let dbName: string;
let examplePrivilege1;
let examplePrivilege2;
let examplePrivilege1: Document;
let examplePrivilege2: Document;

describe('with regular URI', function () {
beforeEach(async function () {
Expand Down Expand Up @@ -113,7 +128,7 @@ describe('Auth e2e', function () {
await db.dropDatabase();
await db.command({ dropAllUsersFromDatabase: 1 });

client.close();
await client.close();
});
afterEach(TestShell.cleanup);

Expand Down Expand Up @@ -316,7 +331,7 @@ describe('Auth e2e', function () {
const result = await db.command({ usersInfo: 1 });
expect(result.users.length).to.equal(1);
const user = result.users[0];
expect(user.roles.map((k) => k.role)).to.have.members([
expect(user.roles.map((k: any) => k.role)).to.have.members([
'dbOwner',
'dbAdmin',
'userAdmin',
Expand Down Expand Up @@ -1120,7 +1135,7 @@ describe('Auth e2e', function () {
await db.dropDatabase();
await db.command({ dropAllUsersFromDatabase: 1 });

client.close();
await client.close();
});
afterEach(TestShell.cleanup);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/e2e-tests/test/e2e-aws.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { TestShell } from './test-shell';

function assertEnvVariable(variableName: string): string {
if (process.env.MONGOSH_TEST_FORCE_API_STRICT) {
return undefined;
return '';
}
const value = process.env[variableName];
if (!value) {
Expand All @@ -16,7 +16,7 @@ function assertEnvVariable(variableName: string): string {
console.error(
`Expected environment variable but was not set: ${variableName}`
);
return undefined;
return '';
}
}
return value;
Expand Down
7 changes: 4 additions & 3 deletions packages/e2e-tests/test/e2e-bson.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { expect } from 'chai';
import type { Db } from 'mongodb';
import { MongoClient } from 'mongodb';
import { bson } from '@mongosh/service-provider-core';
import { TestShell } from './test-shell';
import { startSharedTestServer } from '../../../testing/integration-testing-hooks';

describe('BSON e2e', function () {
const testServer = startSharedTestServer();
let db;
let client;
let db: Db;
let client: MongoClient;
let shell: TestShell;
let dbName;
let dbName: string;

beforeEach(async function () {
const connectionString = await testServer.connectionString();
Expand Down
8 changes: 4 additions & 4 deletions packages/e2e-tests/test/e2e-fle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ describe('FLE tests', function () {
// The actual assertion here:
if (
!kmsServer.requests.some((req) =>
req.headers.authorization.includes(accessKeyId)
req.headers.authorization?.includes(accessKeyId)
) ||
(withSessionToken &&
!kmsServer.requests.some(
Expand Down Expand Up @@ -235,7 +235,7 @@ describe('FLE tests', function () {
);
await shell.executeLine(`db = plainMongo.getDB('${dbname}')`);
const keyVaultContents = await shell.executeLine('db.keyVault.find()');
expect(keyVaultContents).to.include(uuidRegexp.exec(keyId)[1]);
expect(keyVaultContents).to.include(uuidRegexp.exec(keyId)?.[1]);
});

it('works when a schemaMap option has been passed', async function () {
Expand Down Expand Up @@ -269,7 +269,7 @@ describe('FLE tests', function () {
);
await shell.executeLine(`db = plainMongo.getDB('${dbname}')`);
const keyVaultContents = await shell.executeLine('db.keyVault.find()');
expect(keyVaultContents).to.include(uuidRegexp.exec(keyId)[1]);
expect(keyVaultContents).to.include(uuidRegexp.exec(keyId)?.[1]);

await shell.executeLine(
'clientEncryption = keyMongo.getClientEncryption();'
Expand Down Expand Up @@ -901,7 +901,7 @@ describe('FLE tests', function () {
});
await shell.waitForPrompt();
// Wrapper for executeLine that expects single-line output
const runSingleLine = async (line) =>
const runSingleLine = async (line: string) =>
(await shell.executeLine(line)).split('\n')[0].trim();
await runSingleLine(
'local = { key: BinData(0, "kh4Gv2N8qopZQMQYMEtww/AkPsIrXNmEMxTrs3tUoTQZbZu4msdRUaR8U5fXD7A7QXYHcEvuu4WctJLoT+NvvV3eeIg3MD+K8H9SR794m/safgRHdIfy6PD+rFpvmFbY") }'
Expand Down
Loading

0 comments on commit fe78c6b

Please sign in to comment.