1- import { once } from 'node:events' ;
21import { finished } from 'node:stream/promises' ;
32
43import { expect } from 'chai' ;
@@ -372,10 +371,11 @@ describe.only('CRUD API', function () {
372371 let count = 0 ;
373372 cursor . match ( { a : 1 } ) ;
374373 const stream = cursor . stream ( ) ;
374+ const willFinish = finished ( stream , { cleanup : true } ) ;
375375 stream . on ( 'data' , function ( ) {
376376 count = count + 1 ;
377377 } ) ;
378- await once ( cursor , 'end' ) ;
378+ await willFinish ;
379379 test . equal ( 3 , count ) ;
380380 } ) ;
381381
@@ -387,13 +387,16 @@ describe.only('CRUD API', function () {
387387 } ) ;
388388
389389 describe ( 'should correctly execute insert methods using crud api' , function ( ) {
390- const db = client . db ( ) ;
390+ let db : Db ;
391+
392+ before ( function ( ) {
393+ db = client . db ( ) ;
394+ } ) ;
391395
392396 it ( '#insertMany()' , async function ( ) {
393397 const r = await db . collection ( 't2_1' ) . insertMany ( [ { a : 1 } , { a : 2 } ] ) ;
394398 expect ( r ) . property ( 'insertedCount' ) . to . equal ( 2 ) ;
395399 } ) ;
396-
397400 it ( 'bulk inserts' , async function ( ) {
398401 const bulk = db . collection ( 't2_2' ) . initializeOrderedBulkOp ( ) ;
399402 bulk . insert ( { a : 1 } ) ;
@@ -477,7 +480,11 @@ describe.only('CRUD API', function () {
477480 requires : { topology : [ 'single' , 'replicaset' , 'sharded' ] }
478481 } ,
479482 function ( ) {
480- const db = client . db ( ) ;
483+ let db : Db ;
484+
485+ before ( function ( ) {
486+ db = client . db ( ) ;
487+ } ) ;
481488
482489 it ( 'legacy update' , async function ( ) {
483490 const r = await db
0 commit comments