Skip to content

Commit d94439f

Browse files
chore: enforce consistent block spacing in mocha tests (#4048)
1 parent a8670a7 commit d94439f

File tree

73 files changed

+131
-16
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+131
-16
lines changed

.eslintrc.json

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"plugin:@typescript-eslint/eslint-recommended",
1919
"plugin:@typescript-eslint/recommended",
2020
"plugin:prettier/recommended"
21-
// "plugin:mocha/recommended"
2221
],
2322
"env": {
2423
"node": true,
@@ -27,21 +26,6 @@
2726
},
2827
"reportUnusedDisableDirectives": true,
2928
"rules": {
30-
"no-restricted-properties": [
31-
"error",
32-
{
33-
"object": "describe",
34-
"property": "only"
35-
},
36-
{
37-
"object": "it",
38-
"property": "only"
39-
},
40-
{
41-
"object": "context",
42-
"property": "only"
43-
}
44-
],
4529
"no-restricted-globals": [
4630
"error",
4731
{
@@ -115,6 +99,8 @@
11599
}
116100
],
117101
"mocha/no-async-describe": "error",
102+
"mocha/no-exclusive-tests": "error",
103+
"mocha/consistent-spacing-between-blocks": "error",
118104
"no-restricted-syntax": [
119105
"error",
120106
{

test/action/dependency.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ describe('package.json', function () {
132132

133133
describe('mongodb imports', () => {
134134
let imports: string[];
135+
135136
beforeEach(async function () {
136137
for (const key of Object.keys(require.cache)) delete require.cache[key];
137138
require('../../src');

test/integration/change-streams/change_streams.prose.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ describe('Change Stream prose tests', function () {
111111
await client.close();
112112
}
113113
});
114+
114115
afterEach(async () => await mock.cleanup());
115116

116117
// TODO(NODE-3884): Add tests 1-4, 6-8. (#5 is removed from spec)
@@ -590,6 +591,7 @@ describe('Change Stream prose tests', function () {
590591
expect(tokens[0]).to.deep.equal(successes[1].nextBatch[0]._id);
591592
});
592593
});
594+
593595
it('must return resumeAfter from the initial aggregate if the option was specified', function () {
594596
const manager = new MockServerManager(this.configuration, {
595597
aggregate: (function* () {
@@ -629,6 +631,7 @@ describe('Change Stream prose tests', function () {
629631
expect(token).to.deep.equal(resumeAfter);
630632
});
631633
});
634+
632635
it('must be empty if resumeAfter options was not specified', function () {
633636
const manager = new MockServerManager(this.configuration, {
634637
aggregate: (function* () {
@@ -762,6 +765,7 @@ describe('Change Stream prose tests', function () {
762765
expect(token).to.deep.equal(startAfter).and.to.not.deep.equal(resumeAfter);
763766
});
764767
});
768+
765769
it('must return resumeAfter from the initial aggregate if the option was specified', function () {
766770
const manager = new MockServerManager(this.configuration, {
767771
aggregate: (function* () {
@@ -797,6 +801,7 @@ describe('Change Stream prose tests', function () {
797801
expect(token).to.deep.equal(resumeAfter);
798802
});
799803
});
804+
800805
it('must be empty if neither the startAfter nor resumeAfter options were specified', function () {
801806
const manager = new MockServerManager(this.configuration, {
802807
aggregate: (function* () {

test/integration/client-side-encryption/client_side_encryption.prose.12.deadlock.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ const metadata = {
105105
};
106106
describe('Connection Pool Deadlock Prevention', function () {
107107
installNodeDNSWorkaroundHooks();
108+
108109
beforeEach(async function () {
109110
const url: string = this.configuration.url();
110111

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

155156
const CASE1 = { maxPoolSize: 1, bypassAutoEncryption: false, useKeyVaultClient: false };
157+
156158
it(
157159
'Case 1',
158160
metadata,
@@ -177,6 +179,7 @@ describe('Connection Pool Deadlock Prevention', function () {
177179
);
178180

179181
const CASE2 = { maxPoolSize: 1, bypassAutoEncryption: false, useKeyVaultClient: true };
182+
180183
it(
181184
'Case 2',
182185
metadata,
@@ -204,6 +207,7 @@ describe('Connection Pool Deadlock Prevention', function () {
204207
);
205208

206209
const CASE3 = { maxPoolSize: 1, bypassAutoEncryption: true, useKeyVaultClient: false };
210+
207211
it(
208212
'Case 3',
209213
metadata,
@@ -222,6 +226,7 @@ describe('Connection Pool Deadlock Prevention', function () {
222226
);
223227

224228
const CASE4 = { maxPoolSize: 1, bypassAutoEncryption: true, useKeyVaultClient: true };
229+
225230
it(
226231
'Case 4',
227232
metadata,
@@ -243,6 +248,7 @@ describe('Connection Pool Deadlock Prevention', function () {
243248
);
244249

245250
const CASE5 = { maxPoolSize: 0, bypassAutoEncryption: false, useKeyVaultClient: false };
251+
246252
it(
247253
'Case 5',
248254
metadata,
@@ -270,6 +276,7 @@ describe('Connection Pool Deadlock Prevention', function () {
270276
);
271277

272278
const CASE6 = { maxPoolSize: 0, bypassAutoEncryption: false, useKeyVaultClient: true };
279+
273280
it(
274281
'Case 6',
275282
metadata,
@@ -297,6 +304,7 @@ describe('Connection Pool Deadlock Prevention', function () {
297304
);
298305

299306
const CASE7 = { maxPoolSize: 0, bypassAutoEncryption: true, useKeyVaultClient: false };
307+
300308
it(
301309
'Case 7',
302310
metadata,
@@ -315,6 +323,7 @@ describe('Connection Pool Deadlock Prevention', function () {
315323
);
316324

317325
const CASE8 = { maxPoolSize: 0, bypassAutoEncryption: true, useKeyVaultClient: true };
326+
318327
it(
319328
'Case 8',
320329
metadata,

test/integration/client-side-encryption/client_side_encryption.prose.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
565565
const limitsDoc = loadLimits('limits-doc.json');
566566

567567
let hasRunFirstTimeSetup = false;
568+
568569
beforeEach(async function () {
569570
if (hasRunFirstTimeSetup) {
570571
// Even though we have to use a beforeEach here
@@ -1274,6 +1275,7 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
12741275
describe('via loading shared library', function () {
12751276
let clientEncrypted;
12761277
let client;
1278+
12771279
beforeEach(function () {
12781280
const { cryptSharedLibPath } = getEncryptExtraOptions();
12791281
if (!cryptSharedLibPath) {

test/integration/client-side-encryption/client_side_encryption.spec.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ describe('Client Side Encryption (Legacy)', function () {
6969
);
7070

7171
installNodeDNSWorkaroundHooks();
72+
7273
after(() => testContext.teardown());
74+
7375
before(function () {
7476
return testContext.setup(this.configuration);
7577
});

test/integration/collection-management/collection.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { setupDatabase } from '../shared';
66

77
describe('Collection', function () {
88
let configuration;
9+
910
before(function () {
1011
configuration = this.configuration;
1112
return setupDatabase(configuration, ['listCollectionsDb', 'listCollectionsDb2', 'test_db']);
@@ -14,6 +15,7 @@ describe('Collection', function () {
1415
describe('standard collection tests', function () {
1516
let client: MongoClient;
1617
let db: Db;
18+
1719
beforeEach(function () {
1820
client = configuration.newClient(configuration.writeConcernMax(), {
1921
maxPoolSize: 1

test/integration/collection-management/view.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { type CollectionInfo, type Db, type MongoClient } from '../../mongodb';
55
describe('Views', function () {
66
let client: MongoClient;
77
let db: Db;
8+
89
beforeEach(async function () {
910
const configuration = this.configuration;
1011
client = this.configuration.newClient();

test/integration/command-logging-and-monitoring/command_monitoring.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ describe('Command Monitoring', function () {
607607

608608
describe('Internal state references', function () {
609609
let client;
610+
610611
beforeEach(function () {
611612
client = this.configuration.newClient(
612613
{ writeConcern: { w: 1 } },

test/integration/connection-monitoring-and-pooling/connection_pool.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { type ConnectionPoolCreatedEvent, type Db, type MongoClient } from '../.
77
describe('Connection Pool', function () {
88
let client: MongoClient;
99
let db: Db;
10+
1011
afterEach(async function () {
1112
if (client) {
1213
if (db) {
@@ -15,6 +16,7 @@ describe('Connection Pool', function () {
1516
await client.close();
1617
}
1718
});
19+
1820
describe('Events', function () {
1921
describe('ConnectionPoolCreatedEvent', function () {
2022
context('when no connection pool options are passed in', function () {

test/integration/crud/aggregation.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { filterForCommands } from '../shared';
55

66
describe('Aggregation', function () {
77
let client;
8+
89
beforeEach(async function () {
910
client = this.configuration.newClient();
1011
});

test/integration/crud/bulk.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ describe('Bulk', function () {
3333
.createCollection('test')
3434
.catch(() => null); // make ns exist
3535
});
36+
3637
afterEach(async function () {
3738
const cleanup = this.configuration.newClient();
3839
await cleanup

test/integration/crud/crud.prose.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ describe('CRUD Prose Spec Tests', () => {
7777
*/
7878

7979
let collection;
80+
8081
beforeEach(async () => {
8182
try {
8283
await client.db().collection('wc_details').drop();

test/integration/crud/find.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const { Code, ObjectId, Long, Binary, ReturnDocument } = require('../../mongodb'
77

88
describe('Find', function () {
99
let client;
10+
1011
beforeEach(async function () {
1112
client = this.configuration.newClient();
1213
});

test/integration/crud/find_cursor_methods.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ describe('Find Cursor', function () {
1919
beforeEach(async function () {
2020
client = this.configuration.newClient({ monitorCommands: true });
2121
});
22+
2223
afterEach(async function () {
2324
await client.close();
2425
});
@@ -43,6 +44,7 @@ describe('Find Cursor', function () {
4344

4445
describe('#readBufferedDocuments', function () {
4546
let cursor;
47+
4648
beforeEach(async () => {
4749
const coll = client.db().collection('abstract_cursor');
4850
cursor = coll.find({}, { batchSize: 5 });

test/integration/crud/insert.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const ISODate = function (string) {
6363

6464
describe('crud - insert', function () {
6565
let client;
66+
6667
beforeEach(async function () {
6768
client = this.configuration.newClient();
6869
});

test/integration/crud/misc_cursors.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ describe('Cursor', function () {
2525
});
2626

2727
let client;
28+
2829
beforeEach(async function () {
2930
client = this.configuration.newClient({ maxPoolSize: 1, monitorCommands: true });
3031
});
32+
3133
afterEach(async function () {
3234
await client.close();
3335
});

test/integration/crud/remove.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const { expect } = require('chai');
33

44
describe('Remove', function () {
55
let client;
6+
67
beforeEach(async function () {
78
client = this.configuration.newClient();
89
});

test/integration/crud/server_errors.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ describe('Errors', function () {
1414
});
1515

1616
let client;
17+
1718
beforeEach(function () {
1819
client = this.configuration.newClient(this.configuration.writeConcernMax(), { maxPoolSize: 1 });
1920
return client.connect();
2021
});
22+
2123
afterEach(function () {
2224
return client.close();
2325
});

test/integration/gridfs/gridfs_stream.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const { GridFSBucket, ObjectId, MongoAPIError } = require('../../mongodb');
1111
describe('GridFS Stream', function () {
1212
let client;
1313
let db;
14+
1415
beforeEach(async function () {
1516
client = this.configuration.newClient();
1617
db = client.db('gridfs_stream_tests');

test/integration/index_management.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ describe('Indexes', function () {
101101

102102
describe('Collection.indexes()', function () {
103103
beforeEach(() => collection.createIndex({ age: 1 }));
104+
104105
afterEach(() => collection.dropIndexes());
105106

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

131132
describe('Collection.indexInformation()', function () {
132133
beforeEach(() => collection.createIndex({ age: 1 }));
134+
133135
afterEach(() => collection.dropIndexes());
134136

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

163165
describe('Collection.createIndex()', function () {
164166
const started: CommandStartedEvent[] = [];
167+
165168
beforeEach(() => {
166169
started.length = 0;
167170
client.on('commandStarted', filterForCommands('createIndexes', started));
@@ -188,6 +191,7 @@ describe('Indexes', function () {
188191

189192
describe('Collection.createIndexes()', function () {
190193
const started: CommandStartedEvent[] = [];
194+
191195
beforeEach(() => {
192196
started.length = 0;
193197
client.on('commandStarted', filterForCommands('createIndexes', started));
@@ -238,6 +242,7 @@ describe('Indexes', function () {
238242

239243
describe('Collection.indexExists()', function () {
240244
beforeEach(() => collection.createIndex({ age: 1 }));
245+
241246
afterEach(() => collection.dropIndexes());
242247

243248
context('when provided a string index name', () => {

test/integration/max-staleness/max_staleness.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const test = {};
99
// TODO (NODE-3799): convert these to run against a real server
1010
describe('Max Staleness', function () {
1111
afterEach(() => mock.cleanup());
12+
1213
beforeEach(() => {
1314
return mock.createServer().then(server => {
1415
test.server = server;

0 commit comments

Comments
 (0)