@@ -6,79 +6,79 @@ import { pipeline } from 'stream/promises';
6
6
import { setTimeout } from 'timers/promises' ;
7
7
8
8
async function setUpCollection ( client : MongoClient ) {
9
- const collection = client . db ( 'foo' ) . collection < { name : string } > ( 'bar' ) ;
10
- const documents : Array < { name : string } > = Array . from ( { length : 5 } ) . map ( i => ( {
11
- name : String ( i )
12
- } ) ) ;
13
- await collection . insertMany ( documents )
14
- return collection ;
9
+ const collection = client . db ( 'foo' ) . collection < { name : string } > ( 'bar' ) ;
10
+ const documents : Array < { name : string } > = Array . from ( { length : 5 } ) . map ( i => ( {
11
+ name : String ( i )
12
+ } ) ) ;
13
+ await collection . insertMany ( documents )
14
+ return collection ;
15
15
}
16
16
17
17
describe ( 'explicit resource management smoke tests' , function ( ) {
18
- describe ( 'MongoClient' , function ( ) {
19
- it ( 'does not crash or error when used with await-using syntax' , async function ( ) {
18
+ describe ( 'MongoClient' , function ( ) {
19
+ it ( 'does not crash or error when used with await-using syntax' , async function ( ) {
20
20
await using client = new MongoClient ( process . env . MONGODB_URI ! ) ;
21
21
await client . connect ( ) ;
22
- } )
23
- } )
24
-
25
- describe ( 'Cursors' , function ( ) {
26
- it ( 'does not crash or error when used with await-using syntax' , async function ( ) {
27
- await using client = new MongoClient ( process . env . MONGODB_URI ! ) ;
28
- await client . connect ( ) ;
29
-
30
- const collection = await setUpCollection ( client ) ;
31
-
32
- await using cursor = collection . find ( ) ;
33
- await cursor . next ( ) ;
34
- await cursor . next ( ) ;
35
- await cursor . next ( ) ;
36
- } )
37
-
38
- describe ( 'cursor streams' , function ( ) {
39
- it ( 'does not crash or error when used with await-using syntax' , async function ( ) {
40
- await using client = new MongoClient ( process . env . MONGODB_URI ! ) ;
41
- await client . connect ( ) ;
42
-
43
- const collection = await setUpCollection ( client ) ;
44
-
45
- await using readable = collection . find ( ) . stream ( ) ;
46
- } )
47
- } )
48
- } )
49
-
50
- describe ( 'Sessions' , function ( ) {
51
- it ( 'does not crash or error when used with await-using syntax' , async function ( ) {
52
- await using client = new MongoClient ( process . env . MONGODB_URI ! ) ;
53
- await client . connect ( ) ;
54
-
55
- await using session = client . startSession ( ) ;
56
- } )
57
- } )
58
-
59
- describe ( 'ChangeStreams' , function ( ) {
60
- it ( 'does not crash or error when used with await-using syntax' , async function ( ) {
61
- await using client = new MongoClient ( process . env . MONGODB_URI ! ) ;
62
- await client . connect ( ) ;
63
-
64
- const collection = await setUpCollection ( client ) ;
65
- await using cs = collection . watch ( ) ;
66
-
67
- setTimeout ( 1000 ) . then ( ( ) => collection . insertOne ( { name : 'bailey' } ) ) ;
68
- await cs . next ( ) ;
69
- } )
70
- } ) ;
71
-
72
- describe ( 'GridFSDownloadStream' , function ( ) {
73
- it ( 'does not crash or error when used with await-using syntax' , async function ( ) {
74
- await using client = new MongoClient ( process . env . MONGODB_URI ! ) ;
75
- await client . connect ( ) ;
76
-
77
- const bucket = new GridFSBucket ( client . db ( 'foo' ) ) ;
78
- const uploadStream = bucket . openUploadStream ( 'foo.txt' )
79
- await pipeline ( Readable . from ( "AAAAAAA" . split ( '' ) ) , uploadStream ) ;
80
-
81
- await using downloadStream = bucket . openDownloadStreamByName ( 'foo.txt' ) ;
82
- } )
83
- } ) ;
22
+ } )
23
+ } )
24
+
25
+ describe ( 'Cursors' , function ( ) {
26
+ it ( 'does not crash or error when used with await-using syntax' , async function ( ) {
27
+ await using client = new MongoClient ( process . env . MONGODB_URI ! ) ;
28
+ await client . connect ( ) ;
29
+
30
+ const collection = await setUpCollection ( client ) ;
31
+
32
+ await using cursor = collection . find ( ) ;
33
+ await cursor . next ( ) ;
34
+ await cursor . next ( ) ;
35
+ await cursor . next ( ) ;
36
+ } )
37
+
38
+ describe ( 'cursor streams' , function ( ) {
39
+ it ( 'does not crash or error when used with await-using syntax' , async function ( ) {
40
+ await using client = new MongoClient ( process . env . MONGODB_URI ! ) ;
41
+ await client . connect ( ) ;
42
+
43
+ const collection = await setUpCollection ( client ) ;
44
+
45
+ await using readable = collection . find ( ) . stream ( ) ;
46
+ } )
47
+ } )
48
+ } )
49
+
50
+ describe ( 'Sessions' , function ( ) {
51
+ it ( 'does not crash or error when used with await-using syntax' , async function ( ) {
52
+ await using client = new MongoClient ( process . env . MONGODB_URI ! ) ;
53
+ await client . connect ( ) ;
54
+
55
+ await using session = client . startSession ( ) ;
56
+ } )
57
+ } )
58
+
59
+ describe ( 'ChangeStreams' , function ( ) {
60
+ it ( 'does not crash or error when used with await-using syntax' , async function ( ) {
61
+ await using client = new MongoClient ( process . env . MONGODB_URI ! ) ;
62
+ await client . connect ( ) ;
63
+
64
+ const collection = await setUpCollection ( client ) ;
65
+ await using cs = collection . watch ( ) ;
66
+
67
+ setTimeout ( 1000 ) . then ( ( ) => collection . insertOne ( { name : 'bailey' } ) ) ;
68
+ await cs . next ( ) ;
69
+ } )
70
+ } ) ;
71
+
72
+ describe ( 'GridFSDownloadStream' , function ( ) {
73
+ it ( 'does not crash or error when used with await-using syntax' , async function ( ) {
74
+ await using client = new MongoClient ( process . env . MONGODB_URI ! ) ;
75
+ await client . connect ( ) ;
76
+
77
+ const bucket = new GridFSBucket ( client . db ( 'foo' ) ) ;
78
+ const uploadStream = bucket . openUploadStream ( 'foo.txt' )
79
+ await pipeline ( Readable . from ( "AAAAAAA" . split ( '' ) ) , uploadStream ) ;
80
+
81
+ await using downloadStream = bucket . openDownloadStreamByName ( 'foo.txt' ) ;
82
+ } )
83
+ } ) ;
84
84
} )
0 commit comments