From 24c17d7fae226190fd6cc8313192cd09dc7791de Mon Sep 17 00:00:00 2001 From: Pavel Safronov Date: Fri, 26 Sep 2025 13:36:59 -0700 Subject: [PATCH 1/3] migrate --- test/integration/uri-options/uri.test.js | 64 ++++++++++-------------- 1 file changed, 26 insertions(+), 38 deletions(-) diff --git a/test/integration/uri-options/uri.test.js b/test/integration/uri-options/uri.test.js index c5449f4beed..22d0f4b6f5c 100644 --- a/test/integration/uri-options/uri.test.js +++ b/test/integration/uri-options/uri.test.js @@ -2,7 +2,7 @@ const { expect } = require('chai'); const sinon = require('sinon'); -const { Topology } = require('../../mongodb'); +const { Topology } = require('../../../src/sdam/topology'); describe('URI', function () { let client; @@ -20,7 +20,7 @@ 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 () { var self = this; const authInformation = process.env.AUTH === 'auth' ? 'bob:pwd123@' : ''; @@ -29,22 +29,16 @@ describe('URI', function () { `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(); + var db = client.db(self.configuration.db); + + const result = await db + .collection('mongoclient_test') + .update({ a: 1 }, { $set: { b: 1 } }, { upsert: true }); + + expect(result).to.exist; + expect(result).property('acknowledged').to.be.false; + await client.close(); } }); @@ -53,17 +47,14 @@ 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(); + await client.close(); } }); @@ -72,13 +63,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(); + var db = client.db(this.configuration.db); + expect(db.writeConcern.journal).to.be.true; + await client.close(); } }); @@ -114,17 +104,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(); } }); From 618c3d0b6462568d1e8f4399b382aca6d2527d92 Mon Sep 17 00:00:00 2001 From: Pavel Safronov Date: Fri, 26 Sep 2025 15:37:35 -0700 Subject: [PATCH 2/3] change file from js to ts --- .../uri-options/{uri.test.js => uri.test.ts} | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) rename test/integration/uri-options/{uri.test.js => uri.test.ts} (92%) diff --git a/test/integration/uri-options/uri.test.js b/test/integration/uri-options/uri.test.ts similarity index 92% rename from test/integration/uri-options/uri.test.js rename to test/integration/uri-options/uri.test.ts index 22d0f4b6f5c..243fbacfb92 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('../../../src/sdam/topology'); +import { Topology } from '../../../src/sdam/topology'; describe('URI', function () { let client; @@ -21,8 +20,6 @@ describe('URI', function () { metadata: { requires: { topology: 'single' } }, test: async function () { - var self = this; - const authInformation = process.env.AUTH === 'auth' ? 'bob:pwd123@' : ''; // Connect using the connection string const client = this.configuration.newClient( @@ -30,11 +27,11 @@ describe('URI', function () { ); await client.connect(); - var db = client.db(self.configuration.db); + const db = client.db(this.configuration.db); const result = await db .collection('mongoclient_test') - .update({ a: 1 }, { $set: { b: 1 } }, { upsert: true }); + .updateOne({ a: 1 }, { $set: { b: 1 } }, { upsert: true }); expect(result).to.exist; expect(result).property('acknowledged').to.be.false; @@ -66,7 +63,7 @@ describe('URI', function () { test: async function () { const client = this.configuration.newClient('mongodb://127.0.0.1:27017/?fsync=true'); await client.connect(); - var db = client.db(this.configuration.db); + const db = client.db(this.configuration.db); expect(db.writeConcern.journal).to.be.true; await client.close(); } @@ -124,7 +121,7 @@ describe('URI', function () { expect(options.credentials.mechanism).to.eql('MONGODB-X509'); connectStub.restore(); - return; + return undefined; } const topologyPrototype = Topology.prototype; From 2ee8bbd0e9c47d009b5c2653a0996f0981ed3ea9 Mon Sep 17 00:00:00 2001 From: Pavel Safronov Date: Mon, 29 Sep 2025 08:23:47 -0700 Subject: [PATCH 3/3] pr feedback --- test/integration/uri-options/uri.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/integration/uri-options/uri.test.ts b/test/integration/uri-options/uri.test.ts index 243fbacfb92..dde75c48f00 100644 --- a/test/integration/uri-options/uri.test.ts +++ b/test/integration/uri-options/uri.test.ts @@ -51,7 +51,8 @@ describe('URI', function () { const client = this.configuration.newClient('mongodb://%2Ftmp%2Fmongodb-27017.sock'); await client.connect(); - await client.close(); + const err = await client.close().catch(e => e); + expect(err).to.not.exist; } });