11import { strict as assert } from 'assert' ;
2- import { type Document , Long , UUID } from 'bson' ;
2+ import { Long , UUID } from 'bson' ;
33import { expect } from 'chai' ;
44import { on , once } from 'events' ;
55import { gte , lt } from 'semver' ;
@@ -323,27 +323,22 @@ describe('Change Streams', function () {
323323 test : async function ( ) {
324324 const configuration = this . configuration ;
325325 const client = configuration . newClient ( ) ;
326- let changeStream : ChangeStream < Document , ChangeStreamDocument < Document > > ;
327326
328- try {
329- await client . connect ( ) ;
330- const database = client . db ( 'integration_tests' ) ;
331- const changeStream = database . collection ( 'changeStreamCloseTest' ) . watch ( pipeline ) ;
327+ await client . connect ( ) ;
328+ const database = client . db ( 'integration_tests' ) ;
329+ const changeStream = database . collection ( 'changeStreamCloseTest' ) . watch ( pipeline ) ;
332330
333- assert . equal ( changeStream . closed , false ) ;
334- assert . equal ( changeStream . cursor . closed , false ) ;
331+ assert . equal ( changeStream . closed , false ) ;
332+ assert . equal ( changeStream . cursor . closed , false ) ;
335333
336- await changeStream . close ( ) ;
334+ await changeStream . close ( ) ;
337335
338- // Check the cursor is closed
339- expect ( changeStream . closed ) . to . be . true ;
340- expect ( changeStream . cursor ) . property ( 'closed' , true ) ;
341- } finally {
342- await client . close ( ) ;
343- if ( changeStream ) {
344- await changeStream . close ( ) ;
345- }
346- }
336+ // Check the cursor is closed
337+ expect ( changeStream . closed ) . to . be . true ;
338+ expect ( changeStream . cursor ) . property ( 'closed' , true ) ;
339+
340+ await changeStream . close ( ) ;
341+ await client . close ( ) ;
347342 }
348343 } ) ;
349344
@@ -355,31 +350,25 @@ describe('Change Streams', function () {
355350 test : async function ( ) {
356351 const configuration = this . configuration ;
357352 const client = configuration . newClient ( ) ;
358- let changeStream : ChangeStream < Document , ChangeStreamDocument < Document > > ;
359353
360354 await client . connect ( ) ;
361355
362356 const forbiddenStage = { } ;
363357 const forbiddenStageName = '$alksdjfhlaskdfjh' ;
364358 forbiddenStage [ forbiddenStageName ] = 2 ;
365359
366- try {
367- const database = client . db ( 'integration_tests' ) ;
368- changeStream = database . collection ( 'forbiddenStageTest' ) . watch ( [ forbiddenStage ] ) ;
360+ const database = client . db ( 'integration_tests' ) ;
361+ const changeStream = database . collection ( 'forbiddenStageTest' ) . watch ( [ forbiddenStage ] ) ;
362+
363+ const err = await changeStream . next ( ) . catch ( e => e ) ;
364+ assert . ok ( err ) ;
365+ assert . ok ( err . message ) ;
366+ assert . ok (
367+ err . message . indexOf ( `Unrecognized pipeline stage name: '${ forbiddenStageName } '` ) > - 1
368+ ) ;
369369
370- await changeStream . next ( ) ;
371- } catch ( err ) {
372- assert . ok ( err ) ;
373- assert . ok ( err . message ) ;
374- assert . ok (
375- err . message . indexOf ( `Unrecognized pipeline stage name: '${ forbiddenStageName } '` ) > - 1
376- ) ;
377- } finally {
378- await client . close ( ) ;
379- if ( changeStream ) {
380- await changeStream . close ( ) ;
381- }
382- }
370+ await changeStream . close ( ) ;
371+ await client . close ( ) ;
383372 }
384373 }
385374 ) ;
@@ -1310,15 +1299,13 @@ describe('Change Streams', function () {
13101299 await client . connect ( ) ;
13111300 const collection = client . db ( 'cs' ) . collection ( 'test' ) ;
13121301 const changeStream = collection . watch ( ) ;
1313- try {
1314- await changeStream . next ( ) ;
1315- } catch ( err ) {
1316- expect ( err ) . to . exist ;
1317- expect ( err ?. message ) . to . equal ( 'ChangeStream is closed' ) ;
1318- } finally {
1319- await changeStream . close ( ) ;
1320- await client . close ( ) ;
1321- }
1302+
1303+ const err = await changeStream . next ( ) . catch ( e => e ) ;
1304+ expect ( err ) . to . exist ;
1305+ expect ( err ?. message ) . to . equal ( 'ChangeStream is closed' ) ;
1306+
1307+ await changeStream . close ( ) ;
1308+ await client . close ( ) ;
13221309 } ) ;
13231310 } ) ;
13241311 } ) ;
0 commit comments