@@ -4,7 +4,7 @@ import * as sinon from 'sinon';
4
4
import {
5
5
BSON ,
6
6
BSONError ,
7
- Collection ,
7
+ type Collection ,
8
8
type MongoClient ,
9
9
MongoDBResponse ,
10
10
MongoError ,
@@ -164,8 +164,8 @@ describe('utf8 validation with cursors', function () {
164
164
beforeEach ( async function ( ) {
165
165
client = this . configuration . newClient ( ) ;
166
166
await client . connect ( ) ;
167
- const db = client . db ( " test" ) ;
168
- collection = db . collection ( " invalidutf8" ) ;
167
+ const db = client . db ( ' test' ) ;
168
+ collection = db . collection ( ' invalidutf8' ) ;
169
169
} ) ;
170
170
171
171
afterEach ( async function ( ) {
@@ -174,7 +174,7 @@ describe('utf8 validation with cursors', function () {
174
174
175
175
context ( 'when utf-8 validation is explicitly disabled' , function ( ) {
176
176
it ( 'documents can be read using a for-await loop without errors' , async function ( ) {
177
- for await ( const doc of collection . find ( { } , { enableUtf8Validation : false } ) ) ;
177
+ for await ( const _doc of collection . find ( { } , { enableUtf8Validation : false } ) ) ;
178
178
} ) ;
179
179
it ( 'documents can be read using next() without errors' , async function ( ) {
180
180
const cursor = collection . find ( { } , { enableUtf8Validation : false } ) ;
@@ -200,10 +200,10 @@ describe('utf8 validation with cursors', function () {
200
200
while ( await cursor . hasNext ( ) ) {
201
201
await cursor . tryNext ( ) ;
202
202
}
203
- } )
204
- } )
203
+ } ) ;
204
+ } ) ;
205
205
206
- async function expectReject ( fn : ( ) => Promise < void > , options ?: { regex ?: RegExp , errorClass } ) {
206
+ async function expectReject ( fn : ( ) => Promise < void > , options ?: { regex ?: RegExp ; errorClass } ) {
207
207
const regex = options ?. regex ?? / .* / ;
208
208
const errorClass = options ?. errorClass ?? MongoError ;
209
209
try {
@@ -217,95 +217,113 @@ describe('utf8 validation with cursors', function () {
217
217
218
218
context ( 'when utf-8 validation is explicitly enabled' , function ( ) {
219
219
it ( 'a for-await loop throw a BSON error' , async function ( ) {
220
- await expectReject ( async ( ) => {
221
- for await ( const doc of collection . find ( { } , { enableUtf8Validation : true } ) ) ;
222
- } , { errorClass : BSONError , regex : / I n v a l i d U T F - 8 s t r i n g i n B S O N d o c u m e n t / } )
220
+ await expectReject (
221
+ async ( ) => {
222
+ for await ( const doc of collection . find ( { } , { enableUtf8Validation : true } ) ) ;
223
+ } ,
224
+ { errorClass : BSONError , regex : / I n v a l i d U T F - 8 s t r i n g i n B S O N d o c u m e n t / }
225
+ ) ;
223
226
} ) ;
224
227
it ( 'next() throws a BSON error' , async function ( ) {
225
- await expectReject ( async ( ) => {
226
- const cursor = collection . find ( { } , { enableUtf8Validation : true } ) ;
227
-
228
- while ( await cursor . hasNext ( ) ) {
229
- await cursor . next ( ) ;
230
- }
231
- } , { errorClass : BSONError , regex : / I n v a l i d U T F - 8 s t r i n g i n B S O N d o c u m e n t / }
228
+ await expectReject (
229
+ async ( ) => {
230
+ const cursor = collection . find ( { } , { enableUtf8Validation : true } ) ;
231
+
232
+ while ( await cursor . hasNext ( ) ) {
233
+ await cursor . next ( ) ;
234
+ }
235
+ } ,
236
+ { errorClass : BSONError , regex : / I n v a l i d U T F - 8 s t r i n g i n B S O N d o c u m e n t / }
232
237
) ;
233
238
} ) ;
234
239
235
240
it ( 'toArray() throws a BSON error' , async function ( ) {
236
- await expectReject ( async ( ) => {
237
- const cursor = collection . find ( { } , { enableUtf8Validation : true } ) ;
238
- await cursor . toArray ( ) ;
239
- } , { errorClass : BSONError , regex : / I n v a l i d U T F - 8 s t r i n g i n B S O N d o c u m e n t / }
241
+ await expectReject (
242
+ async ( ) => {
243
+ const cursor = collection . find ( { } , { enableUtf8Validation : true } ) ;
244
+ await cursor . toArray ( ) ;
245
+ } ,
246
+ { errorClass : BSONError , regex : / I n v a l i d U T F - 8 s t r i n g i n B S O N d o c u m e n t / }
240
247
) ;
241
-
242
248
} ) ;
243
249
244
250
it ( '.stream() throws a BSONError' , async function ( ) {
245
- await expectReject ( async ( ) => {
246
- const cursor = collection . find ( { } , { enableUtf8Validation : true } ) ;
247
- await cursor . stream ( ) . toArray ( ) ;
248
- } , { errorClass : BSONError , regex : / I n v a l i d U T F - 8 s t r i n g i n B S O N d o c u m e n t / }
251
+ await expectReject (
252
+ async ( ) => {
253
+ const cursor = collection . find ( { } , { enableUtf8Validation : true } ) ;
254
+ await cursor . stream ( ) . toArray ( ) ;
255
+ } ,
256
+ { errorClass : BSONError , regex : / I n v a l i d U T F - 8 s t r i n g i n B S O N d o c u m e n t / }
249
257
) ;
250
258
} ) ;
251
259
252
260
it ( 'tryNext() throws a BSONError' , async function ( ) {
253
- await expectReject ( async ( ) => {
254
- const cursor = collection . find ( { } , { enableUtf8Validation : true } ) ;
255
-
256
- while ( await cursor . hasNext ( ) ) {
257
- await cursor . tryNext ( ) ;
258
- }
259
- } , { errorClass : BSONError , regex : / I n v a l i d U T F - 8 s t r i n g i n B S O N d o c u m e n t / }
261
+ await expectReject (
262
+ async ( ) => {
263
+ const cursor = collection . find ( { } , { enableUtf8Validation : true } ) ;
264
+
265
+ while ( await cursor . hasNext ( ) ) {
266
+ await cursor . tryNext ( ) ;
267
+ }
268
+ } ,
269
+ { errorClass : BSONError , regex : / I n v a l i d U T F - 8 s t r i n g i n B S O N d o c u m e n t / }
260
270
) ;
261
-
262
- } )
263
- } )
271
+ } ) ;
272
+ } ) ;
264
273
265
274
context ( 'utf-8 validation defaults to enabled' , function ( ) {
266
275
it ( 'a for-await loop throw a BSON error' , async function ( ) {
267
- await expectReject ( async ( ) => {
268
- for await ( const doc of collection . find ( { } ) ) ;
269
- } , { errorClass : BSONError , regex : / I n v a l i d U T F - 8 s t r i n g i n B S O N d o c u m e n t / } )
276
+ await expectReject (
277
+ async ( ) => {
278
+ for await ( const doc of collection . find ( { } ) ) ;
279
+ } ,
280
+ { errorClass : BSONError , regex : / I n v a l i d U T F - 8 s t r i n g i n B S O N d o c u m e n t / }
281
+ ) ;
270
282
} ) ;
271
283
it ( 'next() throws a BSON error' , async function ( ) {
272
- await expectReject ( async ( ) => {
273
- const cursor = collection . find ( { } ) ;
274
-
275
- while ( await cursor . hasNext ( ) ) {
276
- await cursor . next ( ) ;
277
- }
278
- } , { errorClass : BSONError , regex : / I n v a l i d U T F - 8 s t r i n g i n B S O N d o c u m e n t / }
284
+ await expectReject (
285
+ async ( ) => {
286
+ const cursor = collection . find ( { } ) ;
287
+
288
+ while ( await cursor . hasNext ( ) ) {
289
+ await cursor . next ( ) ;
290
+ }
291
+ } ,
292
+ { errorClass : BSONError , regex : / I n v a l i d U T F - 8 s t r i n g i n B S O N d o c u m e n t / }
279
293
) ;
280
294
} ) ;
281
295
282
296
it ( 'toArray() throws a BSON error' , async function ( ) {
283
- await expectReject ( async ( ) => {
284
- const cursor = collection . find ( { } ) ;
285
- await cursor . toArray ( ) ;
286
- } , { errorClass : BSONError , regex : / I n v a l i d U T F - 8 s t r i n g i n B S O N d o c u m e n t / }
297
+ await expectReject (
298
+ async ( ) => {
299
+ const cursor = collection . find ( { } ) ;
300
+ await cursor . toArray ( ) ;
301
+ } ,
302
+ { errorClass : BSONError , regex : / I n v a l i d U T F - 8 s t r i n g i n B S O N d o c u m e n t / }
287
303
) ;
288
-
289
304
} ) ;
290
305
291
306
it ( '.stream() throws a BSONError' , async function ( ) {
292
- await expectReject ( async ( ) => {
293
- const cursor = collection . find ( { } ) ;
294
- await cursor . stream ( ) . toArray ( ) ;
295
- } , { errorClass : BSONError , regex : / I n v a l i d U T F - 8 s t r i n g i n B S O N d o c u m e n t / }
307
+ await expectReject (
308
+ async ( ) => {
309
+ const cursor = collection . find ( { } ) ;
310
+ await cursor . stream ( ) . toArray ( ) ;
311
+ } ,
312
+ { errorClass : BSONError , regex : / I n v a l i d U T F - 8 s t r i n g i n B S O N d o c u m e n t / }
296
313
) ;
297
314
} ) ;
298
315
299
316
it ( 'tryNext() throws a BSONError' , async function ( ) {
300
- await expectReject ( async ( ) => {
301
- const cursor = collection . find ( { } ) ;
302
-
303
- while ( await cursor . hasNext ( ) ) {
304
- await cursor . tryNext ( ) ;
305
- }
306
- } , { errorClass : BSONError , regex : / I n v a l i d U T F - 8 s t r i n g i n B S O N d o c u m e n t / }
317
+ await expectReject (
318
+ async ( ) => {
319
+ const cursor = collection . find ( { } , { enableUtf8Validation : true } ) ;
320
+
321
+ while ( await cursor . hasNext ( ) ) {
322
+ await cursor . tryNext ( ) ;
323
+ }
324
+ } ,
325
+ { errorClass : BSONError , regex : / I n v a l i d U T F - 8 s t r i n g i n B S O N d o c u m e n t / }
307
326
) ;
308
-
309
- } )
310
- } )
311
- } )
327
+ } ) ;
328
+ } ) ;
329
+ } ) ;
0 commit comments