1
- 'use strict' ;
1
+ import { expect } from 'chai' ;
2
+ import * as sinon from 'sinon' ;
2
3
3
- const { expect } = require ( 'chai' ) ;
4
- const sinon = require ( 'sinon' ) ;
5
- const { Topology } = require ( '../../mongodb' ) ;
4
+ import { Topology } from '../../../src/sdam/topology' ;
6
5
7
6
describe ( 'URI' , function ( ) {
8
7
let client ;
@@ -20,31 +19,23 @@ describe('URI', function () {
20
19
// in this case we are setting that node needs to be higher than 0.10.X to run
21
20
metadata : { requires : { topology : 'single' } } ,
22
21
23
- test : function ( done ) {
24
- var self = this ;
25
-
22
+ test : async function ( ) {
26
23
const authInformation = process . env . AUTH === 'auth' ? 'bob:pwd123@' : '' ;
27
24
// Connect using the connection string
28
25
const client = this . configuration . newClient (
29
26
`mongodb://${ authInformation } localhost:27017/?w=0`
30
27
) ;
31
28
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 ( ) ;
48
39
}
49
40
} ) ;
50
41
@@ -53,17 +44,15 @@ describe('URI', function () {
53
44
// in this case we are setting that node needs to be higher than 0.10.X to run
54
45
metadata : { requires : { topology : 'single' } } ,
55
46
56
- test : function ( done ) {
47
+ test : async function ( ) {
57
48
if ( process . platform === 'win32' ) {
58
- return done ( ) ;
49
+ return ;
59
50
}
60
51
61
52
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 ;
67
56
}
68
57
} ) ;
69
58
@@ -72,13 +61,12 @@ describe('URI', function () {
72
61
// in this case we are setting that node needs to be higher than 0.10.X to run
73
62
metadata : { requires : { topology : 'single' } } ,
74
63
75
- test : function ( done ) {
64
+ test : async function ( ) {
76
65
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 ( ) ;
82
70
}
83
71
} ) ;
84
72
@@ -114,17 +102,15 @@ describe('URI', function () {
114
102
115
103
it ( 'should correctly translate uri options' , {
116
104
metadata : { requires : { topology : 'replicaset' } } ,
117
- test : function ( done ) {
105
+ test : async function ( ) {
118
106
const config = this . configuration ;
119
107
const uri = `mongodb://${ config . host } :${ config . port } /${ config . db } ?replicaSet=${ config . replicasetName } ` ;
120
108
121
109
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 ( ) ;
128
114
}
129
115
} ) ;
130
116
@@ -136,7 +122,7 @@ describe('URI', function () {
136
122
expect ( options . credentials . mechanism ) . to . eql ( 'MONGODB-X509' ) ;
137
123
138
124
connectStub . restore ( ) ;
139
- return ;
125
+ return undefined ;
140
126
}
141
127
142
128
const topologyPrototype = Topology . prototype ;
0 commit comments