@@ -142,7 +142,7 @@ describe('client metadata module', () => {
142
142
describe ( 'makeClientMetadata()' , ( ) => {
143
143
context ( 'when no FAAS environment is detected' , ( ) => {
144
144
it ( 'does not append FAAS metadata' , ( ) => {
145
- const metadata = makeClientMetadata ( { driverInfo : { } , additionalDriverInfo : [ ] } ) ;
145
+ const metadata = makeClientMetadata ( { additionalDriverInfo : [ { } ] } ) ;
146
146
expect ( metadata ) . not . to . have . property (
147
147
'env' ,
148
148
'faas metadata applied in a non-faas environment'
@@ -167,16 +167,14 @@ describe('client metadata module', () => {
167
167
it ( 'throws an error if driverInfo.platform is too large' , ( ) => {
168
168
expect ( ( ) =>
169
169
makeClientMetadata ( {
170
- driverInfo : { platform : 'a' . repeat ( 512 ) } ,
171
- additionalDriverInfo : [ ]
170
+ additionalDriverInfo : [ { platform : 'a' . repeat ( 512 ) } ]
172
171
} )
173
172
) . to . throw ( MongoInvalidArgumentError , / p l a t f o r m / ) ;
174
173
} ) ;
175
174
176
175
it ( 'appends driverInfo.platform to the platform field' , ( ) => {
177
176
const options = {
178
- driverInfo : { platform : 'myPlatform' } ,
179
- additionalDriverInfo : [ ]
177
+ additionalDriverInfo : [ { platform : 'myPlatform' } ]
180
178
} ;
181
179
const metadata = makeClientMetadata ( options ) ;
182
180
expect ( metadata ) . to . deep . equal ( {
@@ -198,16 +196,12 @@ describe('client metadata module', () => {
198
196
context ( 'when driverInfo.name is provided' , ( ) => {
199
197
it ( 'throws an error if driverInfo.name is too large' , ( ) => {
200
198
expect ( ( ) =>
201
- makeClientMetadata ( { driverInfo : { name : 'a' . repeat ( 512 ) } , additionalDriverInfo : [ ] } )
199
+ makeClientMetadata ( { additionalDriverInfo : [ { name : 'a' . repeat ( 512 ) } ] } )
202
200
) . to . throw ( MongoInvalidArgumentError , / n a m e / ) ;
203
201
} ) ;
204
202
205
203
it ( 'appends driverInfo.name to the driver.name field' , ( ) => {
206
- const options = {
207
- driverInfo : { name : 'myName' } ,
208
- additionalDriverInfo : [ ]
209
- } ;
210
- const metadata = makeClientMetadata ( options ) ;
204
+ const metadata = makeClientMetadata ( { additionalDriverInfo : [ { name : 'myName' } ] } ) ;
211
205
expect ( metadata ) . to . deep . equal ( {
212
206
driver : {
213
207
name : 'nodejs|myName' ,
@@ -227,16 +221,14 @@ describe('client metadata module', () => {
227
221
context ( 'when driverInfo.version is provided' , ( ) => {
228
222
it ( 'throws an error if driverInfo.version is too large' , ( ) => {
229
223
expect ( ( ) =>
230
- makeClientMetadata ( { driverInfo : { version : 'a' . repeat ( 512 ) } , additionalDriverInfo : [ ] } )
224
+ makeClientMetadata ( { additionalDriverInfo : [ { version : 'a' . repeat ( 512 ) } ] } )
231
225
) . to . throw ( MongoInvalidArgumentError , / v e r s i o n / ) ;
232
226
} ) ;
233
227
234
228
it ( 'appends driverInfo.version to the version field' , ( ) => {
235
- const options = {
236
- driverInfo : { version : 'myVersion' } ,
237
- additionalDriverInfo : [ ]
238
- } ;
239
- const metadata = makeClientMetadata ( options ) ;
229
+ const metadata = makeClientMetadata ( {
230
+ additionalDriverInfo : [ { version : 'myVersion' } ]
231
+ } ) ;
240
232
expect ( metadata ) . to . deep . equal ( {
241
233
driver : {
242
234
name : 'nodejs' ,
@@ -254,7 +246,7 @@ describe('client metadata module', () => {
254
246
} ) ;
255
247
256
248
context ( 'when no custom driverInto is provided' , ( ) => {
257
- const metadata = makeClientMetadata ( { driverInfo : { } , additionalDriverInfo : [ ] } ) ;
249
+ const metadata = makeClientMetadata ( { additionalDriverInfo : [ ] } ) ;
258
250
259
251
it ( 'does not append the driver info to the metadata' , ( ) => {
260
252
expect ( metadata ) . to . deep . equal ( {
@@ -280,12 +272,10 @@ describe('client metadata module', () => {
280
272
context ( 'when app name is provided' , ( ) => {
281
273
context ( 'when the app name is over 128 bytes' , ( ) => {
282
274
const longString = 'a' . repeat ( 300 ) ;
283
- const options = {
275
+ const metadata = makeClientMetadata ( {
284
276
appName : longString ,
285
- driverInfo : { } ,
286
277
additionalDriverInfo : [ ]
287
- } ;
288
- const metadata = makeClientMetadata ( options ) ;
278
+ } ) ;
289
279
290
280
it ( 'truncates the application name to <=128 bytes' , ( ) => {
291
281
expect ( metadata . application ?. name ) . to . be . a ( 'string' ) ;
@@ -300,12 +290,10 @@ describe('client metadata module', () => {
300
290
'TODO(NODE-5150): fix appName truncation when multi-byte unicode charaters straddle byte 128' ,
301
291
( ) => {
302
292
const longString = '€' . repeat ( 300 ) ;
303
- const options = {
293
+ const metadata = makeClientMetadata ( {
304
294
appName : longString ,
305
- driverInfo : { } ,
306
295
additionalDriverInfo : [ ]
307
- } ;
308
- const metadata = makeClientMetadata ( options ) ;
296
+ } ) ;
309
297
310
298
it ( 'truncates the application name to 129 bytes' , ( ) => {
311
299
expect ( metadata . application ?. name ) . to . be . a ( 'string' ) ;
@@ -318,12 +306,10 @@ describe('client metadata module', () => {
318
306
) ;
319
307
320
308
context ( 'when the app name is under 128 bytes' , ( ) => {
321
- const options = {
309
+ const metadata = makeClientMetadata ( {
322
310
appName : 'myApplication' ,
323
- driverInfo : { } ,
324
311
additionalDriverInfo : [ ]
325
- } ;
326
- const metadata = makeClientMetadata ( options ) ;
312
+ } ) ;
327
313
328
314
it ( 'sets the application name to the value' , ( ) => {
329
315
expect ( metadata . application ?. name ) . to . equal ( 'myApplication' ) ;
@@ -339,40 +325,39 @@ describe('client metadata module', () => {
339
325
340
326
it ( 'sets platform to Deno' , ( ) => {
341
327
globalThis . Deno = { version : { deno : '1.2.3' } } ;
342
- const metadata = makeClientMetadata ( { driverInfo : { } , additionalDriverInfo : [ ] } ) ;
328
+ const metadata = makeClientMetadata ( { additionalDriverInfo : [ ] } ) ;
343
329
expect ( metadata . platform ) . to . equal ( 'Deno v1.2.3, LE' ) ;
344
330
} ) ;
345
331
346
332
it ( 'sets platform to Deno with driverInfo.platform' , ( ) => {
347
333
globalThis . Deno = { version : { deno : '1.2.3' } } ;
348
334
const metadata = makeClientMetadata ( {
349
- driverInfo : { platform : 'myPlatform' } ,
350
- additionalDriverInfo : [ ]
335
+ additionalDriverInfo : [ { platform : 'myPlatform' } ]
351
336
} ) ;
352
337
expect ( metadata . platform ) . to . equal ( 'Deno v1.2.3, LE|myPlatform' ) ;
353
338
} ) ;
354
339
355
340
it ( 'ignores version if Deno.version.deno is not a string' , ( ) => {
356
341
globalThis . Deno = { version : { deno : 1 } } ;
357
- const metadata = makeClientMetadata ( { driverInfo : { } , additionalDriverInfo : [ ] } ) ;
342
+ const metadata = makeClientMetadata ( { additionalDriverInfo : [ ] } ) ;
358
343
expect ( metadata . platform ) . to . equal ( 'Deno v0.0.0-unknown, LE' ) ;
359
344
} ) ;
360
345
361
346
it ( 'ignores version if Deno.version does not have a deno property' , ( ) => {
362
347
globalThis . Deno = { version : { somethingElse : '1.2.3' } } ;
363
- const metadata = makeClientMetadata ( { driverInfo : { } , additionalDriverInfo : [ ] } ) ;
348
+ const metadata = makeClientMetadata ( { additionalDriverInfo : [ ] } ) ;
364
349
expect ( metadata . platform ) . to . equal ( 'Deno v0.0.0-unknown, LE' ) ;
365
350
} ) ;
366
351
367
352
it ( 'ignores version if Deno.version is null' , ( ) => {
368
353
globalThis . Deno = { version : null } ;
369
- const metadata = makeClientMetadata ( { driverInfo : { } , additionalDriverInfo : [ ] } ) ;
354
+ const metadata = makeClientMetadata ( { additionalDriverInfo : [ ] } ) ;
370
355
expect ( metadata . platform ) . to . equal ( 'Deno v0.0.0-unknown, LE' ) ;
371
356
} ) ;
372
357
373
358
it ( 'ignores version if Deno is nullish' , ( ) => {
374
359
globalThis . Deno = null ;
375
- const metadata = makeClientMetadata ( { driverInfo : { } , additionalDriverInfo : [ ] } ) ;
360
+ const metadata = makeClientMetadata ( { additionalDriverInfo : [ ] } ) ;
376
361
expect ( metadata . platform ) . to . equal ( 'Deno v0.0.0-unknown, LE' ) ;
377
362
} ) ;
378
363
} ) ;
@@ -386,7 +371,7 @@ describe('client metadata module', () => {
386
371
globalThis . Bun = class {
387
372
static version = '1.2.3' ;
388
373
} ;
389
- const metadata = makeClientMetadata ( { driverInfo : { } , additionalDriverInfo : [ ] } ) ;
374
+ const metadata = makeClientMetadata ( { additionalDriverInfo : [ ] } ) ;
390
375
expect ( metadata . platform ) . to . equal ( 'Bun v1.2.3, LE' ) ;
391
376
} ) ;
392
377
@@ -395,8 +380,7 @@ describe('client metadata module', () => {
395
380
static version = '1.2.3' ;
396
381
} ;
397
382
const metadata = makeClientMetadata ( {
398
- driverInfo : { platform : 'myPlatform' } ,
399
- additionalDriverInfo : [ ]
383
+ additionalDriverInfo : [ { platform : 'myPlatform' } ]
400
384
} ) ;
401
385
expect ( metadata . platform ) . to . equal ( 'Bun v1.2.3, LE|myPlatform' ) ;
402
386
} ) ;
@@ -405,7 +389,7 @@ describe('client metadata module', () => {
405
389
globalThis . Bun = class {
406
390
static version = 1 ;
407
391
} ;
408
- const metadata = makeClientMetadata ( { driverInfo : { } , additionalDriverInfo : [ ] } ) ;
392
+ const metadata = makeClientMetadata ( { additionalDriverInfo : [ ] } ) ;
409
393
expect ( metadata . platform ) . to . equal ( 'Bun v0.0.0-unknown, LE' ) ;
410
394
} ) ;
411
395
@@ -414,17 +398,15 @@ describe('client metadata module', () => {
414
398
static version = 1 ;
415
399
} ;
416
400
const metadata = makeClientMetadata ( {
417
- driverInfo : { platform : 'myPlatform' } ,
418
- additionalDriverInfo : [ ]
401
+ additionalDriverInfo : [ { platform : 'myPlatform' } ]
419
402
} ) ;
420
403
expect ( metadata . platform ) . to . equal ( 'Bun v0.0.0-unknown, LE|myPlatform' ) ;
421
404
} ) ;
422
405
423
406
it ( 'ignores version if Bun is nullish' , ( ) => {
424
407
globalThis . Bun = null ;
425
408
const metadata = makeClientMetadata ( {
426
- driverInfo : { platform : 'myPlatform' } ,
427
- additionalDriverInfo : [ ]
409
+ additionalDriverInfo : [ { platform : 'myPlatform' } ]
428
410
} ) ;
429
411
expect ( metadata . platform ) . to . equal ( 'Bun v0.0.0-unknown, LE|myPlatform' ) ;
430
412
} ) ;
0 commit comments