Skip to content
10 changes: 5 additions & 5 deletions .evergreen/run-serverless-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ if [ -z ${SERVERLESS_ATLAS_USER+omitted} ]; then echo "SERVERLESS_ATLAS_USER is
if [ -z ${SERVERLESS_ATLAS_PASSWORD+omitted} ]; then echo "SERVERLESS_ATLAS_PASSWORD is unset" && exit 1; fi

npx mocha --file test/tools/runner/index.js \
test/functional/crud_spec.test.js \
test/functional/retryable_reads.test.js \
test/functional/retryable_writes.test.js \
test/integration/crud/crud.spec.test.js \
test/integration/retryable-reads/retryable_reads.spec.test.js \
test/integration/retryable-writes/retryable_writes.spec.test.js \
test/functional/sessions.test.js \
test/functional/transactions.test.js \
test/functional/versioned-api.test.js \
test/functional/load-balancer-spec.test.js
test/integration/versioned-api/versioned_api.spec.test.js \
test/integration/load-balancers/load_balancers.spec.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ const {
withClientV2,
withMonitoredClient,
setupDatabase,
ignoreNsNotFound
} = require('./shared');
const test = require('./shared').assert;
const { MongoDriverError, MongoBatchReExecutionError } = require('../../src/error');
const { Long, MongoBulkWriteError } = require('../../src');
ignoreNsNotFound,
assert: test
} = require('../shared');
const { Long, MongoBatchReExecutionError, MongoDriverError } = require('../../../src');
const crypto = require('crypto');
const chai = require('chai');
const expect = chai.expect;
Expand All @@ -21,48 +20,6 @@ describe('Bulk', function () {
return setupDatabase(this.configuration);
});

describe('Write Errors', () => {
describe('errInfo property on insertMany', () => {
let client;

beforeEach(async function () {
client = this.configuration.newClient({ monitorCommands: true });
await client.connect();
});

afterEach(async () => {
if (client) {
await client.close();
}
});

it('should be accessible', {
metadata: { requires: { mongodb: '>=5.0.0' } },
async test() {
try {
await client.db().collection('wc_details').drop();
} catch {
// don't care
}

const collection = await client
.db()
.createCollection('wc_details', { validator: { x: { $type: 'string' } } });

try {
await collection.insertMany([{ x: /not a string/ }]);
expect.fail('The insert should fail the validation that x must be a string');
} catch (error) {
expect(error).to.be.instanceOf(MongoBulkWriteError);
expect(error).to.have.property('code', 121);
expect(error).to.have.property('writeErrors').that.is.an('array');
expect(error.writeErrors[0]).to.have.property('errInfo').that.is.an('object');
}
}
});
});
});

it('should correctly handle ordered single batch api write command error', {
metadata: {
requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] }
Expand Down
43 changes: 43 additions & 0 deletions test/integration/crud/crud.prose.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const { expect } = require('chai');
const { MongoBulkWriteError } = require('../../../src');

describe('CRUD Prose Spec Tests', () => {
let client;

beforeEach(async function () {
client = this.configuration.newClient({ monitorCommands: true });
await client.connect();
});

afterEach(async () => {
if (client) {
await client.close();
}
});

// Note: This test does not fully implement the described test, it's missing command monitoring assertions
it('2. WriteError.details exposes writeErrors[].errInfo', {
metadata: { requires: { mongodb: '>=5.0.0' } },
async test() {
try {
await client.db().collection('wc_details').drop();
} catch {
// don't care
}

const collection = await client
.db()
.createCollection('wc_details', { validator: { x: { $type: 'string' } } });

try {
await collection.insertMany([{ x: /not a string/ }]);
expect.fail('The insert should fail the validation that x must be a string');
} catch (error) {
expect(error).to.be.instanceOf(MongoBulkWriteError);
expect(error).to.have.property('code', 121);
expect(error).to.have.property('writeErrors').that.is.an('array');
expect(error.writeErrors[0]).to.have.property('errInfo').that.is.an('object');
}
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const chai = require('chai');
const expect = chai.expect;
chai.use(require('chai-subset'));

const { loadSpecTests } = require('../spec/index');
const { runUnifiedTest } = require('../tools/unified-spec-runner/runner');
const { loadSpecTests } = require('../../spec/index');
const { runUnifiedTest } = require('../../tools/unified-spec-runner/runner');

function enforceServerVersionLimits(requires, scenario) {
const versionLimits = [];
Expand All @@ -26,7 +26,7 @@ function enforceServerVersionLimits(requires, scenario) {
}

function findScenarios() {
const route = [__dirname, '..', 'spec', 'crud'].concat(Array.from(arguments));
const route = [__dirname, '..', '..', 'spec', 'crud'].concat(Array.from(arguments));
return fs
.readdirSync(path.resolve.apply(path, route))
.filter(x => x.indexOf('json') !== -1)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use strict';
const test = require('./shared').assert;
const { assert: test, setupDatabase } = require('../shared');
const { expect } = require('chai');
const { ReturnDocument, ObjectId } = require('../../src');
const setupDatabase = require('./shared').setupDatabase;
const { ReturnDocument, ObjectId } = require('../../../src');

// instanceof cannot be use reliably to detect the new models in js due to scoping and new
// contexts killing class info find/distinct/count thus cannot be overloaded without breaking
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');
const { loadSpecTests } = require('../../spec/index');
const { runUnifiedSuite } = require('../../tools/unified-spec-runner/runner');

const SKIP = [
// Verified they use the same connection but the Node implementation executes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
'use strict';
const { Long } = require('bson');
const { expect } = require('chai');
const mock = require('../tools/mock');
const { ReadPreference } = require('../../src');
const mock = require('../../tools/mock');
const { ReadPreference } = require('../../../src');

const test = {};
// TODO (NODE-3799): convert these to run against a real server
describe('Max Staleness', function () {
afterEach(() => mock.cleanup());
beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use strict';

const TestRunnerContext = require('./spec-runner').TestRunnerContext;
const generateTopologyTests = require('./spec-runner').generateTopologyTests;
const loadSpecTests = require('../spec').loadSpecTests;
const { TestRunnerContext, generateTopologyTests } = require('../../tools/spec-runner');
const { loadSpecTests } = require('../../spec');

describe('Retryable Reads', function () {
const testContext = new TestRunnerContext();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

const expect = require('chai').expect;
const loadSpecTests = require('../spec').loadSpecTests;
const parseRunOn = require('../functional/spec-runner').parseRunOn;
const { expect } = require('chai');
const { loadSpecTests } = require('../../spec');
const { parseRunOn } = require('../../tools/spec-runner');

describe('Retryable Writes', function () {
let ctx = {};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

const { expect } = require('chai');
const { loadSpecTests } = require('../spec/index');
const { runUnifiedTest } = require('../tools/unified-spec-runner/runner');
const { loadSpecTests } = require('../../spec/');
const { runUnifiedTest } = require('../../tools/unified-spec-runner/runner');

describe('Versioned API', function () {
it('should throw an error if serverApi version is provided via the uri', {
Expand Down