diff --git a/test/integration/uri-options/uri.test.js b/test/integration/uri-options/uri.test.ts similarity index 72% rename from test/integration/uri-options/uri.test.js rename to test/integration/uri-options/uri.test.ts index c5449f4beed..dde75c48f00 100644 --- a/test/integration/uri-options/uri.test.js +++ b/test/integration/uri-options/uri.test.ts @@ -1,8 +1,7 @@ -'use strict'; +import { expect } from 'chai'; +import * as sinon from 'sinon'; -const { expect } = require('chai'); -const sinon = require('sinon'); -const { Topology } = require('../../mongodb'); +import { Topology } from '../../../src/sdam/topology'; describe('URI', function () { let client; @@ -20,31 +19,23 @@ describe('URI', function () { // in this case we are setting that node needs to be higher than 0.10.X to run metadata: { requires: { topology: 'single' } }, - test: function (done) { - var self = this; - + test: async function () { const authInformation = process.env.AUTH === 'auth' ? 'bob:pwd123@' : ''; // Connect using the connection string const client = this.configuration.newClient( `mongodb://${authInformation}localhost:27017/?w=0` ); - client.connect(function (err, client) { - expect(err).to.not.exist; - var db = client.db(self.configuration.db); - - db.collection('mongoclient_test').update( - { a: 1 }, - { $set: { b: 1 } }, - { upsert: true }, - function (err, result) { - expect(err).to.not.exist; - expect(result).to.exist; - expect(result).property('acknowledged').to.be.false; - client.close(done); - } - ); - }); + await client.connect(); + const db = client.db(this.configuration.db); + + const result = await db + .collection('mongoclient_test') + .updateOne({ a: 1 }, { $set: { b: 1 } }, { upsert: true }); + + expect(result).to.exist; + expect(result).property('acknowledged').to.be.false; + await client.close(); } }); @@ -53,17 +44,15 @@ describe('URI', function () { // in this case we are setting that node needs to be higher than 0.10.X to run metadata: { requires: { topology: 'single' } }, - test: function (done) { + test: async function () { if (process.platform === 'win32') { - return done(); + return; } const client = this.configuration.newClient('mongodb://%2Ftmp%2Fmongodb-27017.sock'); - - client.connect(function (err, client) { - expect(err).to.not.exist; - client.close(done); - }); + await client.connect(); + const err = await client.close().catch(e => e); + expect(err).to.not.exist; } }); @@ -72,13 +61,12 @@ describe('URI', function () { // in this case we are setting that node needs to be higher than 0.10.X to run metadata: { requires: { topology: 'single' } }, - test: function (done) { + test: async function () { const client = this.configuration.newClient('mongodb://127.0.0.1:27017/?fsync=true'); - client.connect((err, client) => { - var db = client.db(this.configuration.db); - expect(db.writeConcern.journal).to.be.true; - client.close(done); - }); + await client.connect(); + const db = client.db(this.configuration.db); + expect(db.writeConcern.journal).to.be.true; + await client.close(); } }); @@ -114,17 +102,15 @@ describe('URI', function () { it('should correctly translate uri options', { metadata: { requires: { topology: 'replicaset' } }, - test: function (done) { + test: async function () { const config = this.configuration; const uri = `mongodb://${config.host}:${config.port}/${config.db}?replicaSet=${config.replicasetName}`; const client = this.configuration.newClient(uri); - client.connect((err, client) => { - expect(err).to.not.exist; - expect(client).to.exist; - expect(client.options.replicaSet).to.exist.and.equal(config.replicasetName); - client.close(done); - }); + await client.connect(); + expect(client).to.exist; + expect(client.options.replicaSet).to.exist.and.equal(config.replicasetName); + await client.close(); } }); @@ -136,7 +122,7 @@ describe('URI', function () { expect(options.credentials.mechanism).to.eql('MONGODB-X509'); connectStub.restore(); - return; + return undefined; } const topologyPrototype = Topology.prototype;