Skip to content

Commit

Permalink
chore: enforce consistent block spacing in mocha tests (#4048)
Browse files Browse the repository at this point in the history
  • Loading branch information
baileympearson authored Mar 22, 2024
1 parent a8670a7 commit d94439f
Show file tree
Hide file tree
Showing 73 changed files with 131 additions and 16 deletions.
18 changes: 2 additions & 16 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
// "plugin:mocha/recommended"
],
"env": {
"node": true,
Expand All @@ -27,21 +26,6 @@
},
"reportUnusedDisableDirectives": true,
"rules": {
"no-restricted-properties": [
"error",
{
"object": "describe",
"property": "only"
},
{
"object": "it",
"property": "only"
},
{
"object": "context",
"property": "only"
}
],
"no-restricted-globals": [
"error",
{
Expand Down Expand Up @@ -115,6 +99,8 @@
}
],
"mocha/no-async-describe": "error",
"mocha/no-exclusive-tests": "error",
"mocha/consistent-spacing-between-blocks": "error",
"no-restricted-syntax": [
"error",
{
Expand Down
1 change: 1 addition & 0 deletions test/action/dependency.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ describe('package.json', function () {

describe('mongodb imports', () => {
let imports: string[];

beforeEach(async function () {
for (const key of Object.keys(require.cache)) delete require.cache[key];
require('../../src');
Expand Down
5 changes: 5 additions & 0 deletions test/integration/change-streams/change_streams.prose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ describe('Change Stream prose tests', function () {
await client.close();
}
});

afterEach(async () => await mock.cleanup());

// TODO(NODE-3884): Add tests 1-4, 6-8. (#5 is removed from spec)
Expand Down Expand Up @@ -590,6 +591,7 @@ describe('Change Stream prose tests', function () {
expect(tokens[0]).to.deep.equal(successes[1].nextBatch[0]._id);
});
});

it('must return resumeAfter from the initial aggregate if the option was specified', function () {
const manager = new MockServerManager(this.configuration, {
aggregate: (function* () {
Expand Down Expand Up @@ -629,6 +631,7 @@ describe('Change Stream prose tests', function () {
expect(token).to.deep.equal(resumeAfter);
});
});

it('must be empty if resumeAfter options was not specified', function () {
const manager = new MockServerManager(this.configuration, {
aggregate: (function* () {
Expand Down Expand Up @@ -762,6 +765,7 @@ describe('Change Stream prose tests', function () {
expect(token).to.deep.equal(startAfter).and.to.not.deep.equal(resumeAfter);
});
});

it('must return resumeAfter from the initial aggregate if the option was specified', function () {
const manager = new MockServerManager(this.configuration, {
aggregate: (function* () {
Expand Down Expand Up @@ -797,6 +801,7 @@ describe('Change Stream prose tests', function () {
expect(token).to.deep.equal(resumeAfter);
});
});

it('must be empty if neither the startAfter nor resumeAfter options were specified', function () {
const manager = new MockServerManager(this.configuration, {
aggregate: (function* () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ const metadata = {
};
describe('Connection Pool Deadlock Prevention', function () {
installNodeDNSWorkaroundHooks();

beforeEach(async function () {
const url: string = this.configuration.url();

Expand Down Expand Up @@ -153,6 +154,7 @@ describe('Connection Pool Deadlock Prevention', function () {
});

const CASE1 = { maxPoolSize: 1, bypassAutoEncryption: false, useKeyVaultClient: false };

it(
'Case 1',
metadata,
Expand All @@ -177,6 +179,7 @@ describe('Connection Pool Deadlock Prevention', function () {
);

const CASE2 = { maxPoolSize: 1, bypassAutoEncryption: false, useKeyVaultClient: true };

it(
'Case 2',
metadata,
Expand Down Expand Up @@ -204,6 +207,7 @@ describe('Connection Pool Deadlock Prevention', function () {
);

const CASE3 = { maxPoolSize: 1, bypassAutoEncryption: true, useKeyVaultClient: false };

it(
'Case 3',
metadata,
Expand All @@ -222,6 +226,7 @@ describe('Connection Pool Deadlock Prevention', function () {
);

const CASE4 = { maxPoolSize: 1, bypassAutoEncryption: true, useKeyVaultClient: true };

it(
'Case 4',
metadata,
Expand All @@ -243,6 +248,7 @@ describe('Connection Pool Deadlock Prevention', function () {
);

const CASE5 = { maxPoolSize: 0, bypassAutoEncryption: false, useKeyVaultClient: false };

it(
'Case 5',
metadata,
Expand Down Expand Up @@ -270,6 +276,7 @@ describe('Connection Pool Deadlock Prevention', function () {
);

const CASE6 = { maxPoolSize: 0, bypassAutoEncryption: false, useKeyVaultClient: true };

it(
'Case 6',
metadata,
Expand Down Expand Up @@ -297,6 +304,7 @@ describe('Connection Pool Deadlock Prevention', function () {
);

const CASE7 = { maxPoolSize: 0, bypassAutoEncryption: true, useKeyVaultClient: false };

it(
'Case 7',
metadata,
Expand All @@ -315,6 +323,7 @@ describe('Connection Pool Deadlock Prevention', function () {
);

const CASE8 = { maxPoolSize: 0, bypassAutoEncryption: true, useKeyVaultClient: true };

it(
'Case 8',
metadata,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
const limitsDoc = loadLimits('limits-doc.json');

let hasRunFirstTimeSetup = false;

beforeEach(async function () {
if (hasRunFirstTimeSetup) {
// Even though we have to use a beforeEach here
Expand Down Expand Up @@ -1274,6 +1275,7 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
describe('via loading shared library', function () {
let clientEncrypted;
let client;

beforeEach(function () {
const { cryptSharedLibPath } = getEncryptExtraOptions();
if (!cryptSharedLibPath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ describe('Client Side Encryption (Legacy)', function () {
);

installNodeDNSWorkaroundHooks();

after(() => testContext.teardown());

before(function () {
return testContext.setup(this.configuration);
});
Expand Down
2 changes: 2 additions & 0 deletions test/integration/collection-management/collection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { setupDatabase } from '../shared';

describe('Collection', function () {
let configuration;

before(function () {
configuration = this.configuration;
return setupDatabase(configuration, ['listCollectionsDb', 'listCollectionsDb2', 'test_db']);
Expand All @@ -14,6 +15,7 @@ describe('Collection', function () {
describe('standard collection tests', function () {
let client: MongoClient;
let db: Db;

beforeEach(function () {
client = configuration.newClient(configuration.writeConcernMax(), {
maxPoolSize: 1
Expand Down
1 change: 1 addition & 0 deletions test/integration/collection-management/view.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { type CollectionInfo, type Db, type MongoClient } from '../../mongodb';
describe('Views', function () {
let client: MongoClient;
let db: Db;

beforeEach(async function () {
const configuration = this.configuration;
client = this.configuration.newClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,7 @@ describe('Command Monitoring', function () {

describe('Internal state references', function () {
let client;

beforeEach(function () {
client = this.configuration.newClient(
{ writeConcern: { w: 1 } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { type ConnectionPoolCreatedEvent, type Db, type MongoClient } from '../.
describe('Connection Pool', function () {
let client: MongoClient;
let db: Db;

afterEach(async function () {
if (client) {
if (db) {
Expand All @@ -15,6 +16,7 @@ describe('Connection Pool', function () {
await client.close();
}
});

describe('Events', function () {
describe('ConnectionPoolCreatedEvent', function () {
context('when no connection pool options are passed in', function () {
Expand Down
1 change: 1 addition & 0 deletions test/integration/crud/aggregation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { filterForCommands } from '../shared';

describe('Aggregation', function () {
let client;

beforeEach(async function () {
client = this.configuration.newClient();
});
Expand Down
1 change: 1 addition & 0 deletions test/integration/crud/bulk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe('Bulk', function () {
.createCollection('test')
.catch(() => null); // make ns exist
});

afterEach(async function () {
const cleanup = this.configuration.newClient();
await cleanup
Expand Down
1 change: 1 addition & 0 deletions test/integration/crud/crud.prose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ describe('CRUD Prose Spec Tests', () => {
*/

let collection;

beforeEach(async () => {
try {
await client.db().collection('wc_details').drop();
Expand Down
1 change: 1 addition & 0 deletions test/integration/crud/find.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { Code, ObjectId, Long, Binary, ReturnDocument } = require('../../mongodb'

describe('Find', function () {
let client;

beforeEach(async function () {
client = this.configuration.newClient();
});
Expand Down
2 changes: 2 additions & 0 deletions test/integration/crud/find_cursor_methods.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('Find Cursor', function () {
beforeEach(async function () {
client = this.configuration.newClient({ monitorCommands: true });
});

afterEach(async function () {
await client.close();
});
Expand All @@ -43,6 +44,7 @@ describe('Find Cursor', function () {

describe('#readBufferedDocuments', function () {
let cursor;

beforeEach(async () => {
const coll = client.db().collection('abstract_cursor');
cursor = coll.find({}, { batchSize: 5 });
Expand Down
1 change: 1 addition & 0 deletions test/integration/crud/insert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const ISODate = function (string) {

describe('crud - insert', function () {
let client;

beforeEach(async function () {
client = this.configuration.newClient();
});
Expand Down
2 changes: 2 additions & 0 deletions test/integration/crud/misc_cursors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ describe('Cursor', function () {
});

let client;

beforeEach(async function () {
client = this.configuration.newClient({ maxPoolSize: 1, monitorCommands: true });
});

afterEach(async function () {
await client.close();
});
Expand Down
1 change: 1 addition & 0 deletions test/integration/crud/remove.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { expect } = require('chai');

describe('Remove', function () {
let client;

beforeEach(async function () {
client = this.configuration.newClient();
});
Expand Down
2 changes: 2 additions & 0 deletions test/integration/crud/server_errors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ describe('Errors', function () {
});

let client;

beforeEach(function () {
client = this.configuration.newClient(this.configuration.writeConcernMax(), { maxPoolSize: 1 });
return client.connect();
});

afterEach(function () {
return client.close();
});
Expand Down
1 change: 1 addition & 0 deletions test/integration/gridfs/gridfs_stream.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const { GridFSBucket, ObjectId, MongoAPIError } = require('../../mongodb');
describe('GridFS Stream', function () {
let client;
let db;

beforeEach(async function () {
client = this.configuration.newClient();
db = client.db('gridfs_stream_tests');
Expand Down
5 changes: 5 additions & 0 deletions test/integration/index_management.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ describe('Indexes', function () {

describe('Collection.indexes()', function () {
beforeEach(() => collection.createIndex({ age: 1 }));

afterEach(() => collection.dropIndexes());

context('when `full` is not provided', () => {
Expand Down Expand Up @@ -130,6 +131,7 @@ describe('Indexes', function () {

describe('Collection.indexInformation()', function () {
beforeEach(() => collection.createIndex({ age: 1 }));

afterEach(() => collection.dropIndexes());

context('when `full` is not provided', () => {
Expand Down Expand Up @@ -162,6 +164,7 @@ describe('Indexes', function () {

describe('Collection.createIndex()', function () {
const started: CommandStartedEvent[] = [];

beforeEach(() => {
started.length = 0;
client.on('commandStarted', filterForCommands('createIndexes', started));
Expand All @@ -188,6 +191,7 @@ describe('Indexes', function () {

describe('Collection.createIndexes()', function () {
const started: CommandStartedEvent[] = [];

beforeEach(() => {
started.length = 0;
client.on('commandStarted', filterForCommands('createIndexes', started));
Expand Down Expand Up @@ -238,6 +242,7 @@ describe('Indexes', function () {

describe('Collection.indexExists()', function () {
beforeEach(() => collection.createIndex({ age: 1 }));

afterEach(() => collection.dropIndexes());

context('when provided a string index name', () => {
Expand Down
1 change: 1 addition & 0 deletions test/integration/max-staleness/max_staleness.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const test = {};
// TODO (NODE-3799): convert these to run against a real server
describe('Max Staleness', function () {
afterEach(() => mock.cleanup());

beforeEach(() => {
return mock.createServer().then(server => {
test.server = server;
Expand Down
Loading

0 comments on commit d94439f

Please sign in to comment.