Skip to content

Commit

Permalink
test(NODE-6032): convert tests run on serverless to TS and ensure all…
Browse files Browse the repository at this point in the history
… tests are running (#4045)
  • Loading branch information
nbbeeken committed Mar 20, 2024
1 parent 8b91c30 commit abf8bdf
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 45 deletions.
12 changes: 6 additions & 6 deletions .evergreen/run-serverless-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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 });
Expand All @@ -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": {
Expand All @@ -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.
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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}`);
}
Expand All @@ -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])]);
}

Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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') {
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -42,5 +43,6 @@ describe('Retryable Reads (unified)', function () {
return `The Node.js Driver does not support ${apiName}`;
}
}
return false;
});
});
8 changes: 0 additions & 8 deletions test/integration/versioned-api/versioned_api.spec.test.js

This file was deleted.

6 changes: 6 additions & 0 deletions test/integration/versioned-api/versioned_api.spec.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { loadSpecTests } from '../../spec/';
import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner';

describe('Versioned API', function () {
runUnifiedSuite(loadSpecTests('versioned-api'));
});

0 comments on commit abf8bdf

Please sign in to comment.