1- 'use strict' ;
1+ import { expect } from 'chai' ;
2+ import * as sinon from 'sinon' ;
23
3- const { expect } = require ( 'chai' ) ;
4- const sinon = require ( 'sinon' ) ;
5- const { Topology } = require ( '../../mongodb' ) ;
4+ import { Topology } from '../../../src/sdam/topology' ;
65
76describe ( 'URI' , function ( ) {
87 let client ;
@@ -20,31 +19,23 @@ describe('URI', function () {
2019 // in this case we are setting that node needs to be higher than 0.10.X to run
2120 metadata : { requires : { topology : 'single' } } ,
2221
23- test : function ( done ) {
24- var self = this ;
25-
22+ test : async function ( ) {
2623 const authInformation = process . env . AUTH === 'auth' ? 'bob:pwd123@' : '' ;
2724 // Connect using the connection string
2825 const client = this . configuration . newClient (
2926 `mongodb://${ authInformation } localhost:27017/?w=0`
3027 ) ;
3128
32- client . connect ( function ( err , client ) {
33- expect ( err ) . to . not . exist ;
34- var db = client . db ( self . configuration . db ) ;
35-
36- db . collection ( 'mongoclient_test' ) . update (
37- { a : 1 } ,
38- { $set : { b : 1 } } ,
39- { upsert : true } ,
40- function ( err , result ) {
41- expect ( err ) . to . not . exist ;
42- expect ( result ) . to . exist ;
43- expect ( result ) . property ( 'acknowledged' ) . to . be . false ;
44- client . close ( done ) ;
45- }
46- ) ;
47- } ) ;
29+ await client . connect ( ) ;
30+ const db = client . db ( this . configuration . db ) ;
31+
32+ const result = await db
33+ . collection ( 'mongoclient_test' )
34+ . updateOne ( { a : 1 } , { $set : { b : 1 } } , { upsert : true } ) ;
35+
36+ expect ( result ) . to . exist ;
37+ expect ( result ) . property ( 'acknowledged' ) . to . be . false ;
38+ await client . close ( ) ;
4839 }
4940 } ) ;
5041
@@ -53,17 +44,15 @@ describe('URI', function () {
5344 // in this case we are setting that node needs to be higher than 0.10.X to run
5445 metadata : { requires : { topology : 'single' } } ,
5546
56- test : function ( done ) {
47+ test : async function ( ) {
5748 if ( process . platform === 'win32' ) {
58- return done ( ) ;
49+ return ;
5950 }
6051
6152 const client = this . configuration . newClient ( 'mongodb://%2Ftmp%2Fmongodb-27017.sock' ) ;
62-
63- client . connect ( function ( err , client ) {
64- expect ( err ) . to . not . exist ;
65- client . close ( done ) ;
66- } ) ;
53+ await client . connect ( ) ;
54+ const err = await client . close ( ) . catch ( e => e ) ;
55+ expect ( err ) . to . not . exist ;
6756 }
6857 } ) ;
6958
@@ -72,13 +61,12 @@ describe('URI', function () {
7261 // in this case we are setting that node needs to be higher than 0.10.X to run
7362 metadata : { requires : { topology : 'single' } } ,
7463
75- test : function ( done ) {
64+ test : async function ( ) {
7665 const client = this . configuration . newClient ( 'mongodb://127.0.0.1:27017/?fsync=true' ) ;
77- client . connect ( ( err , client ) => {
78- var db = client . db ( this . configuration . db ) ;
79- expect ( db . writeConcern . journal ) . to . be . true ;
80- client . close ( done ) ;
81- } ) ;
66+ await client . connect ( ) ;
67+ const db = client . db ( this . configuration . db ) ;
68+ expect ( db . writeConcern . journal ) . to . be . true ;
69+ await client . close ( ) ;
8270 }
8371 } ) ;
8472
@@ -114,17 +102,15 @@ describe('URI', function () {
114102
115103 it ( 'should correctly translate uri options' , {
116104 metadata : { requires : { topology : 'replicaset' } } ,
117- test : function ( done ) {
105+ test : async function ( ) {
118106 const config = this . configuration ;
119107 const uri = `mongodb://${ config . host } :${ config . port } /${ config . db } ?replicaSet=${ config . replicasetName } ` ;
120108
121109 const client = this . configuration . newClient ( uri ) ;
122- client . connect ( ( err , client ) => {
123- expect ( err ) . to . not . exist ;
124- expect ( client ) . to . exist ;
125- expect ( client . options . replicaSet ) . to . exist . and . equal ( config . replicasetName ) ;
126- client . close ( done ) ;
127- } ) ;
110+ await client . connect ( ) ;
111+ expect ( client ) . to . exist ;
112+ expect ( client . options . replicaSet ) . to . exist . and . equal ( config . replicasetName ) ;
113+ await client . close ( ) ;
128114 }
129115 } ) ;
130116
@@ -136,7 +122,7 @@ describe('URI', function () {
136122 expect ( options . credentials . mechanism ) . to . eql ( 'MONGODB-X509' ) ;
137123
138124 connectStub . restore ( ) ;
139- return ;
125+ return undefined ;
140126 }
141127
142128 const topologyPrototype = Topology . prototype ;
0 commit comments