Skip to content

Commit abf8bdf

Browse files
authored
test(NODE-6032): convert tests run on serverless to TS and ensure all tests are running (#4045)
1 parent 8b91c30 commit abf8bdf

File tree

7 files changed

+46
-45
lines changed

7 files changed

+46
-45
lines changed

Diff for: .evergreen/run-serverless-tests.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ if [ -z ${SERVERLESS_ATLAS_PASSWORD+omitted} ]; then echo "SERVERLESS_ATLAS_PASS
1212

1313
npx mocha \
1414
--config test/mocha_mongodb.json \
15-
test/integration/crud/crud.spec.test.js \
16-
test/integration/crud/crud.prose.test.js \
17-
test/integration/retryable-reads/retryable_reads.spec.test.js \
15+
test/integration/crud/crud.spec.test.ts \
16+
test/integration/crud/crud.prose.test.ts \
17+
test/integration/retryable-reads/retryable_reads.spec.test.ts \
1818
test/integration/retryable-writes/retryable_writes.spec.test.ts \
1919
test/integration/sessions/sessions.spec.test.ts \
2020
test/integration/sessions/sessions.prose.test.ts \
2121
test/integration/sessions/sessions.test.ts \
22-
test/integration/transactions/transactions.spec.test.js \
22+
test/integration/transactions/transactions.spec.test.ts \
2323
test/integration/transactions/transactions.test.ts \
24-
test/integration/versioned-api/versioned_api.spec.test.js \
25-
test/integration/load-balancers/load_balancers.spec.test.js \
24+
test/integration/versioned-api/versioned_api.spec.test.ts \
25+
test/integration/load-balancers/load_balancers.spec.test.ts \
2626
test/integration/client-side-encryption/client_side_encryption.spec.test.ts \
2727
test/integration/run-command/run_command.spec.test.ts

Diff for: test/integration/crud/crud.prose.test.js renamed to test/integration/crud/crud.prose.test.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
const { expect } = require('chai');
2-
const { once } = require('events');
3-
const { MongoBulkWriteError, MongoServerError } = require('../../mongodb');
1+
import { expect } from 'chai';
2+
import { once } from 'events';
3+
4+
import { MongoBulkWriteError, type MongoClient, MongoServerError } from '../../mongodb';
45

56
describe('CRUD Prose Spec Tests', () => {
6-
let client;
7+
let client: MongoClient;
78

89
beforeEach(async function () {
910
client = this.configuration.newClient({ monitorCommands: true });
@@ -22,6 +23,8 @@ describe('CRUD Prose Spec Tests', () => {
2223
/**
2324
* Test that writeConcernError.errInfo in a command response is propagated as WriteConcernError.details (or equivalent) in the driver.
2425
* Using a 4.0+ server, set the following failpoint:
26+
* @example
27+
* ```js
2528
* {
2629
* "configureFailPoint": "failCommand",
2730
* "data": {
@@ -41,6 +44,7 @@ describe('CRUD Prose Spec Tests', () => {
4144
* },
4245
* "mode": { "times": 1 }
4346
* }
47+
* ```
4448
*
4549
* Then, perform an insert operation and assert that a WriteConcernError occurs and that
4650
* its details property is both accessible and matches the errInfo object from the failpoint.
@@ -55,15 +59,17 @@ describe('CRUD Prose Spec Tests', () => {
5559
/**
5660
* Test that writeErrors[].errInfo in a command response is propagated as WriteError.details (or equivalent) in the driver.
5761
* Using a 5.0+ server, create a collection with document validation like so:
62+
* @example
63+
* ```js
5864
* {
5965
* "create": "test",
6066
* "validator": {
6167
* "x": { $type: "string" }
6268
* }
6369
* }
64-
*
70+
*```
6571
* Enable command monitoring to observe CommandSucceededEvents.
66-
* Then, insert an invalid document (e.g. {x: 1})
72+
* Then, insert an invalid document (e.g. `{x: 1}`)
6773
* and assert that a WriteError occurs, that its code is 121 (i.e. DocumentValidationFailure),
6874
* and that its details property is accessible.
6975
* Additionally, assert that a CommandSucceededEvent was observed

Diff for: test/integration/crud/crud.spec.test.js renamed to test/integration/crud/crud.spec.test.ts

+12-17
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
'use strict';
1+
import { expect } from 'chai';
2+
import * as fs from 'fs';
3+
import * as path from 'path';
24

3-
const fs = require('fs');
4-
const path = require('path');
5-
const chai = require('chai');
6-
7-
const expect = chai.expect;
8-
chai.use(require('chai-subset'));
9-
10-
const { loadSpecTests } = require('../../spec/index');
11-
const { runUnifiedSuite } = require('../../tools/unified-spec-runner/runner');
5+
import { loadSpecTests } from '../../spec/index';
6+
import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner';
127

138
function enforceServerVersionLimits(requires, scenario) {
14-
const versionLimits = [];
9+
const versionLimits: string[] = [];
1510
if (scenario.minServerVersion) {
1611
versionLimits.push(`>=${scenario.minServerVersion}`);
1712
}
@@ -26,12 +21,12 @@ function enforceServerVersionLimits(requires, scenario) {
2621
}
2722
}
2823

29-
function findScenarios() {
30-
const route = [__dirname, '..', '..', 'spec', 'crud'].concat(Array.from(arguments));
24+
function findScenarios(...args: string[]) {
25+
const route = [__dirname, '..', '..', 'spec', 'crud'].concat(Array.from(args));
3126
return fs
32-
.readdirSync(path.resolve.apply(path, route))
27+
.readdirSync(path.resolve(...route))
3328
.filter(x => x.indexOf('json') !== -1)
34-
.map(x => [x, fs.readFileSync(path.resolve.apply(path, route.concat([x])), 'utf8')])
29+
.map(x => [x, fs.readFileSync(path.resolve(...route.concat([x])), 'utf8')])
3530
.map(x => [path.basename(x[0], '.json'), JSON.parse(x[1])]);
3631
}
3732

@@ -251,7 +246,7 @@ describe('CRUD spec v1', function () {
251246
function executeInsertTest(scenarioTest, db, collection) {
252247
const args = scenarioTest.operation.arguments;
253248
const documents = args.document || args.documents;
254-
let options = Object.assign({}, args.options);
249+
const options = Object.assign({}, args.options);
255250
delete options.document;
256251
delete options.documents;
257252

@@ -268,7 +263,7 @@ describe('CRUD spec v1', function () {
268263
function executeBulkTest(scenarioTest, db, collection) {
269264
const args = scenarioTest.operation.arguments;
270265
const operations = args.requests.map(operation => {
271-
let op = {};
266+
const op = {};
272267
op[operation.name] = operation['arguments'];
273268
if (operation['arguments'].collation) {
274269
op.collation = operation['arguments'].collation;

Diff for: test/integration/load-balancers/load_balancers.spec.test.js renamed to test/integration/load-balancers/load_balancers.spec.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
'use strict';
2-
const path = require('path');
3-
const { loadSpecTests } = require('../../spec/index');
4-
const { runUnifiedSuite } = require('../../tools/unified-spec-runner/runner');
1+
import * as path from 'path';
2+
3+
import { loadSpecTests } from '../../spec/index';
4+
import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner';
55

66
const filter = ({ description }) => {
77
if (description === 'change streams pin to a connection') {

Diff for: test/integration/retryable-reads/retryable_reads.spec.test.js renamed to test/integration/retryable-reads/retryable_reads.spec.test.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
const path = require('path');
2-
const { TestRunnerContext, generateTopologyTests } = require('../../tools/spec-runner');
3-
const { loadSpecTests } = require('../../spec');
4-
const { runUnifiedSuite } = require('../../tools/unified-spec-runner/runner');
1+
import * as path from 'path';
2+
3+
import { loadSpecTests } from '../../spec';
4+
import { generateTopologyTests, TestRunnerContext } from '../../tools/spec-runner';
5+
import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner';
56

67
describe('Retryable Reads (legacy)', function () {
78
const testContext = new TestRunnerContext();
@@ -42,5 +43,6 @@ describe('Retryable Reads (unified)', function () {
4243
return `The Node.js Driver does not support ${apiName}`;
4344
}
4445
}
46+
return false;
4547
});
4648
});

Diff for: test/integration/versioned-api/versioned_api.spec.test.js

-8
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { loadSpecTests } from '../../spec/';
2+
import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner';
3+
4+
describe('Versioned API', function () {
5+
runUnifiedSuite(loadSpecTests('versioned-api'));
6+
});

0 commit comments

Comments
 (0)