@@ -387,34 +387,34 @@ describe.only('CRUD API', function () {
387387 } ) ;
388388
389389 describe ( 'should correctly execute insert methods using crud api' , function ( ) {
390- let db : Db ;
391-
392- before ( function ( ) {
393- db = client . db ( ) ;
394- } ) ;
395-
396390 it ( '#insertMany()' , async function ( ) {
391+ const db = client . db ( ) ;
397392 const r = await db . collection ( 't2_1' ) . insertMany ( [ { a : 1 } , { a : 2 } ] ) ;
398393 expect ( r ) . property ( 'insertedCount' ) . to . equal ( 2 ) ;
399394 } ) ;
395+
400396 it ( 'bulk inserts' , async function ( ) {
397+ await client . connect ( ) ;
398+ const db = client . db ( ) ;
401399 const bulk = db . collection ( 't2_2' ) . initializeOrderedBulkOp ( ) ;
402400 bulk . insert ( { a : 1 } ) ;
403401 bulk . insert ( { a : 1 } ) ;
404402 await bulk . execute ( ) ;
405403 } ) ;
406404
407405 it ( '#insertOne()' , async function ( ) {
406+ const db = client . db ( ) ;
408407 const r = await db . collection ( 't2_3' ) . insertOne ( { a : 1 } , { writeConcern : { w : 1 } } ) ;
409408 expect ( r ) . property ( 'insertedId' ) . to . exist ;
410409 } ) ;
411410
412411 it ( 'bulk write unordered' , async function ( ) {
412+ const db = client . db ( ) ;
413413 const i = await db . collection ( 't2_5' ) . insertMany ( [ { c : 1 } ] , { writeConcern : { w : 1 } } ) ;
414414 expect ( i ) . property ( 'insertedCount' ) . to . equal ( 1 ) ;
415415
416416 const r = await db
417- . collection ( 't2_4 ' )
417+ . collection ( 't2_5 ' )
418418 . bulkWrite (
419419 [
420420 { insertOne : { document : { a : 1 } } } ,
@@ -442,11 +442,12 @@ describe.only('CRUD API', function () {
442442 } ) ;
443443
444444 it ( 'bulk write ordered' , async function ( ) {
445- const i = await db . collection ( 't2_7' ) . insertMany ( [ { c : 1 } ] , { writeConcern : { w : 1 } } ) ;
445+ const db = client . db ( ) ;
446+ const i = await db . collection ( 't2_6' ) . insertMany ( [ { c : 1 } ] , { writeConcern : { w : 1 } } ) ;
446447 expect ( i ) . property ( 'insertedCount' ) . to . equal ( 1 ) ;
447448
448449 const r = await db
449- . collection ( 't2_5 ' )
450+ . collection ( 't2_6 ' )
450451 . bulkWrite (
451452 [
452453 { insertOne : { document : { a : 1 } } } ,
@@ -480,13 +481,8 @@ describe.only('CRUD API', function () {
480481 requires : { topology : [ 'single' , 'replicaset' , 'sharded' ] }
481482 } ,
482483 function ( ) {
483- let db : Db ;
484-
485- before ( function ( ) {
486- db = client . db ( ) ;
487- } ) ;
488-
489484 it ( 'legacy update' , async function ( ) {
485+ const db = client . db ( ) ;
490486 const r = await db
491487 . collection ( 't3_1' )
492488 // @ts -expect-error Not allowed in TS, but allowed for legacy compat
@@ -495,6 +491,7 @@ describe.only('CRUD API', function () {
495491 } ) ;
496492
497493 it ( '#updateOne()' , async function ( ) {
494+ const db = client . db ( ) ;
498495 const i = await db . collection ( 't3_2' ) . insertMany ( [ { c : 1 } ] , { writeConcern : { w : 1 } } ) ;
499496 expect ( i ) . property ( 'insertedCount' ) . to . equal ( 1 ) ;
500497
@@ -512,6 +509,7 @@ describe.only('CRUD API', function () {
512509 } ) ;
513510
514511 it ( '#replaceOne()' , async function ( ) {
512+ const db = client . db ( ) ;
515513 const r1 = await db . collection ( 't3_3' ) . replaceOne ( { a : 1 } , { a : 2 } , { upsert : true } ) ;
516514 expect ( r1 ) . property ( 'upsertedCount' ) . to . equal ( 1 ) ;
517515 test . equal ( 0 , r1 . matchedCount ) ;
@@ -524,6 +522,7 @@ describe.only('CRUD API', function () {
524522 } ) ;
525523
526524 it ( '#updateMany()' , async function ( ) {
525+ const db = client . db ( ) ;
527526 const i = await db
528527 . collection ( 't3_4' )
529528 . insertMany ( [ { a : 1 } , { a : 1 } ] , { writeConcern : { w : 1 } } ) ;
@@ -889,7 +888,11 @@ describe.only('CRUD API', function () {
889888 ops . push ( { insertOne : { _id : 0 , a : i } } ) ;
890889
891890 const db = client . db ( ) ;
892- await db . collection ( 't20_1' ) . bulkWrite ( ops , { ordered : true , writeConcern : { w : 1 } } ) ;
891+ const err = await db
892+ . collection ( 't20_1' )
893+ . bulkWrite ( ops , { ordered : true , writeConcern : { w : 1 } } )
894+ . catch ( err => err ) ;
895+ test . ok ( err != null ) ;
893896 }
894897 } ) ;
895898
0 commit comments