From abf8bdfc8dbae85356a7cef9d476e619a79e53d9 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Wed, 20 Mar 2024 12:30:40 -0400 Subject: [PATCH] test(NODE-6032): convert tests run on serverless to TS and ensure all tests are running (#4045) --- .evergreen/run-serverless-tests.sh | 12 ++++---- ...{crud.prose.test.js => crud.prose.test.ts} | 18 ++++++++---- .../{crud.spec.test.js => crud.spec.test.ts} | 29 ++++++++----------- ...ec.test.js => load_balancers.spec.test.ts} | 8 ++--- ...c.test.js => retryable_reads.spec.test.ts} | 10 ++++--- .../versioned-api/versioned_api.spec.test.js | 8 ----- .../versioned-api/versioned_api.spec.test.ts | 6 ++++ 7 files changed, 46 insertions(+), 45 deletions(-) rename test/integration/crud/{crud.prose.test.js => crud.prose.test.ts} (94%) rename test/integration/crud/{crud.spec.test.js => crud.spec.test.ts} (95%) rename test/integration/load-balancers/{load_balancers.spec.test.js => load_balancers.spec.test.ts} (90%) rename test/integration/retryable-reads/{retryable_reads.spec.test.js => retryable_reads.spec.test.ts} (84%) delete mode 100644 test/integration/versioned-api/versioned_api.spec.test.js create mode 100644 test/integration/versioned-api/versioned_api.spec.test.ts diff --git a/.evergreen/run-serverless-tests.sh b/.evergreen/run-serverless-tests.sh index b0c58637b1..bc4c83ed67 100755 --- a/.evergreen/run-serverless-tests.sh +++ b/.evergreen/run-serverless-tests.sh @@ -12,16 +12,16 @@ if [ -z ${SERVERLESS_ATLAS_PASSWORD+omitted} ]; then echo "SERVERLESS_ATLAS_PASS npx mocha \ --config test/mocha_mongodb.json \ - test/integration/crud/crud.spec.test.js \ - test/integration/crud/crud.prose.test.js \ - test/integration/retryable-reads/retryable_reads.spec.test.js \ + test/integration/crud/crud.spec.test.ts \ + test/integration/crud/crud.prose.test.ts \ + test/integration/retryable-reads/retryable_reads.spec.test.ts \ test/integration/retryable-writes/retryable_writes.spec.test.ts \ test/integration/sessions/sessions.spec.test.ts \ test/integration/sessions/sessions.prose.test.ts \ test/integration/sessions/sessions.test.ts \ - test/integration/transactions/transactions.spec.test.js \ + test/integration/transactions/transactions.spec.test.ts \ test/integration/transactions/transactions.test.ts \ - test/integration/versioned-api/versioned_api.spec.test.js \ - test/integration/load-balancers/load_balancers.spec.test.js \ + test/integration/versioned-api/versioned_api.spec.test.ts \ + test/integration/load-balancers/load_balancers.spec.test.ts \ test/integration/client-side-encryption/client_side_encryption.spec.test.ts \ test/integration/run-command/run_command.spec.test.ts diff --git a/test/integration/crud/crud.prose.test.js b/test/integration/crud/crud.prose.test.ts similarity index 94% rename from test/integration/crud/crud.prose.test.js rename to test/integration/crud/crud.prose.test.ts index b4dd851e6d..b24c1bb133 100644 --- a/test/integration/crud/crud.prose.test.js +++ b/test/integration/crud/crud.prose.test.ts @@ -1,9 +1,10 @@ -const { expect } = require('chai'); -const { once } = require('events'); -const { MongoBulkWriteError, MongoServerError } = require('../../mongodb'); +import { expect } from 'chai'; +import { once } from 'events'; + +import { MongoBulkWriteError, type MongoClient, MongoServerError } from '../../mongodb'; describe('CRUD Prose Spec Tests', () => { - let client; + let client: MongoClient; beforeEach(async function () { client = this.configuration.newClient({ monitorCommands: true }); @@ -22,6 +23,8 @@ describe('CRUD Prose Spec Tests', () => { /** * Test that writeConcernError.errInfo in a command response is propagated as WriteConcernError.details (or equivalent) in the driver. * Using a 4.0+ server, set the following failpoint: + * @example + * ```js * { * "configureFailPoint": "failCommand", * "data": { @@ -41,6 +44,7 @@ describe('CRUD Prose Spec Tests', () => { * }, * "mode": { "times": 1 } * } + * ``` * * Then, perform an insert operation and assert that a WriteConcernError occurs and that * its details property is both accessible and matches the errInfo object from the failpoint. @@ -55,15 +59,17 @@ describe('CRUD Prose Spec Tests', () => { /** * Test that writeErrors[].errInfo in a command response is propagated as WriteError.details (or equivalent) in the driver. * Using a 5.0+ server, create a collection with document validation like so: + * @example + * ```js * { * "create": "test", * "validator": { * "x": { $type: "string" } * } * } - * + *``` * Enable command monitoring to observe CommandSucceededEvents. - * Then, insert an invalid document (e.g. {x: 1}) + * Then, insert an invalid document (e.g. `{x: 1}`) * and assert that a WriteError occurs, that its code is 121 (i.e. DocumentValidationFailure), * and that its details property is accessible. * Additionally, assert that a CommandSucceededEvent was observed diff --git a/test/integration/crud/crud.spec.test.js b/test/integration/crud/crud.spec.test.ts similarity index 95% rename from test/integration/crud/crud.spec.test.js rename to test/integration/crud/crud.spec.test.ts index ce145c038c..4b43d49a5d 100644 --- a/test/integration/crud/crud.spec.test.js +++ b/test/integration/crud/crud.spec.test.ts @@ -1,17 +1,12 @@ -'use strict'; +import { expect } from 'chai'; +import * as fs from 'fs'; +import * as path from 'path'; -const fs = require('fs'); -const path = require('path'); -const chai = require('chai'); - -const expect = chai.expect; -chai.use(require('chai-subset')); - -const { loadSpecTests } = require('../../spec/index'); -const { runUnifiedSuite } = require('../../tools/unified-spec-runner/runner'); +import { loadSpecTests } from '../../spec/index'; +import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner'; function enforceServerVersionLimits(requires, scenario) { - const versionLimits = []; + const versionLimits: string[] = []; if (scenario.minServerVersion) { versionLimits.push(`>=${scenario.minServerVersion}`); } @@ -26,12 +21,12 @@ function enforceServerVersionLimits(requires, scenario) { } } -function findScenarios() { - const route = [__dirname, '..', '..', 'spec', 'crud'].concat(Array.from(arguments)); +function findScenarios(...args: string[]) { + const route = [__dirname, '..', '..', 'spec', 'crud'].concat(Array.from(args)); return fs - .readdirSync(path.resolve.apply(path, route)) + .readdirSync(path.resolve(...route)) .filter(x => x.indexOf('json') !== -1) - .map(x => [x, fs.readFileSync(path.resolve.apply(path, route.concat([x])), 'utf8')]) + .map(x => [x, fs.readFileSync(path.resolve(...route.concat([x])), 'utf8')]) .map(x => [path.basename(x[0], '.json'), JSON.parse(x[1])]); } @@ -251,7 +246,7 @@ describe('CRUD spec v1', function () { function executeInsertTest(scenarioTest, db, collection) { const args = scenarioTest.operation.arguments; const documents = args.document || args.documents; - let options = Object.assign({}, args.options); + const options = Object.assign({}, args.options); delete options.document; delete options.documents; @@ -268,7 +263,7 @@ describe('CRUD spec v1', function () { function executeBulkTest(scenarioTest, db, collection) { const args = scenarioTest.operation.arguments; const operations = args.requests.map(operation => { - let op = {}; + const op = {}; op[operation.name] = operation['arguments']; if (operation['arguments'].collation) { op.collation = operation['arguments'].collation; diff --git a/test/integration/load-balancers/load_balancers.spec.test.js b/test/integration/load-balancers/load_balancers.spec.test.ts similarity index 90% rename from test/integration/load-balancers/load_balancers.spec.test.js rename to test/integration/load-balancers/load_balancers.spec.test.ts index f4622dac0f..578a9860d0 100644 --- a/test/integration/load-balancers/load_balancers.spec.test.js +++ b/test/integration/load-balancers/load_balancers.spec.test.ts @@ -1,7 +1,7 @@ -'use strict'; -const path = require('path'); -const { loadSpecTests } = require('../../spec/index'); -const { runUnifiedSuite } = require('../../tools/unified-spec-runner/runner'); +import * as path from 'path'; + +import { loadSpecTests } from '../../spec/index'; +import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner'; const filter = ({ description }) => { if (description === 'change streams pin to a connection') { diff --git a/test/integration/retryable-reads/retryable_reads.spec.test.js b/test/integration/retryable-reads/retryable_reads.spec.test.ts similarity index 84% rename from test/integration/retryable-reads/retryable_reads.spec.test.js rename to test/integration/retryable-reads/retryable_reads.spec.test.ts index 9dbe1166b1..c60d574d7f 100644 --- a/test/integration/retryable-reads/retryable_reads.spec.test.js +++ b/test/integration/retryable-reads/retryable_reads.spec.test.ts @@ -1,7 +1,8 @@ -const path = require('path'); -const { TestRunnerContext, generateTopologyTests } = require('../../tools/spec-runner'); -const { loadSpecTests } = require('../../spec'); -const { runUnifiedSuite } = require('../../tools/unified-spec-runner/runner'); +import * as path from 'path'; + +import { loadSpecTests } from '../../spec'; +import { generateTopologyTests, TestRunnerContext } from '../../tools/spec-runner'; +import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner'; describe('Retryable Reads (legacy)', function () { const testContext = new TestRunnerContext(); @@ -42,5 +43,6 @@ describe('Retryable Reads (unified)', function () { return `The Node.js Driver does not support ${apiName}`; } } + return false; }); }); diff --git a/test/integration/versioned-api/versioned_api.spec.test.js b/test/integration/versioned-api/versioned_api.spec.test.js deleted file mode 100644 index 4e8724d758..0000000000 --- a/test/integration/versioned-api/versioned_api.spec.test.js +++ /dev/null @@ -1,8 +0,0 @@ -'use strict'; - -const { loadSpecTests } = require('../../spec/'); -const { runUnifiedSuite } = require('../../tools/unified-spec-runner/runner'); - -describe('Versioned API', function () { - runUnifiedSuite(loadSpecTests('versioned-api')); -}); diff --git a/test/integration/versioned-api/versioned_api.spec.test.ts b/test/integration/versioned-api/versioned_api.spec.test.ts new file mode 100644 index 0000000000..36fcc393aa --- /dev/null +++ b/test/integration/versioned-api/versioned_api.spec.test.ts @@ -0,0 +1,6 @@ +import { loadSpecTests } from '../../spec/'; +import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner'; + +describe('Versioned API', function () { + runUnifiedSuite(loadSpecTests('versioned-api')); +});