@@ -288,6 +288,94 @@ describe('client metadata module', () => {
288288 } ) ;
289289 } ) ;
290290 } ) ;
291+
292+ context ( 'when globalThis indicates alternative runtime' , ( ) => {
293+ context ( 'deno' , ( ) => {
294+ afterEach ( ( ) => {
295+ expect ( delete globalThis . Deno , 'failed to delete Deno global' ) . to . be . true ;
296+ } ) ;
297+
298+ it ( 'sets platform to Deno' , ( ) => {
299+ globalThis . Deno = { version : { deno : '1.2.3' } } ;
300+ const metadata = makeClientMetadata ( { driverInfo : { } } ) ;
301+ expect ( metadata . platform ) . to . equal ( 'Deno v1.2.3, LE' ) ;
302+ } ) ;
303+
304+ it ( 'sets platform to Deno with driverInfo.platform' , ( ) => {
305+ globalThis . Deno = { version : { deno : '1.2.3' } } ;
306+ const metadata = makeClientMetadata ( { driverInfo : { platform : 'myPlatform' } } ) ;
307+ expect ( metadata . platform ) . to . equal ( 'Deno v1.2.3, LE|myPlatform' ) ;
308+ } ) ;
309+
310+ it ( 'ignores version if Deno.version.deno is not a string' , ( ) => {
311+ globalThis . Deno = { version : { deno : 1 } } ;
312+ const metadata = makeClientMetadata ( { driverInfo : { } } ) ;
313+ expect ( metadata . platform ) . to . equal ( 'Deno v0.0.0-unknown, LE' ) ;
314+ } ) ;
315+
316+ it ( 'ignores version if Deno.version does not have a deno property' , ( ) => {
317+ globalThis . Deno = { version : { somethingElse : '1.2.3' } } ;
318+ const metadata = makeClientMetadata ( { driverInfo : { } } ) ;
319+ expect ( metadata . platform ) . to . equal ( 'Deno v0.0.0-unknown, LE' ) ;
320+ } ) ;
321+
322+ it ( 'ignores version if Deno.version is null' , ( ) => {
323+ globalThis . Deno = { version : null } ;
324+ const metadata = makeClientMetadata ( { driverInfo : { } } ) ;
325+ expect ( metadata . platform ) . to . equal ( 'Deno v0.0.0-unknown, LE' ) ;
326+ } ) ;
327+
328+ it ( 'ignores version if Deno is nullish' , ( ) => {
329+ globalThis . Deno = null ;
330+ const metadata = makeClientMetadata ( { driverInfo : { } } ) ;
331+ expect ( metadata . platform ) . to . equal ( 'Deno v0.0.0-unknown, LE' ) ;
332+ } ) ;
333+ } ) ;
334+
335+ context ( 'bun' , ( ) => {
336+ afterEach ( ( ) => {
337+ expect ( delete globalThis . Bun , 'failed to delete Bun global' ) . to . be . true ;
338+ } ) ;
339+
340+ it ( 'sets platform to Bun' , ( ) => {
341+ globalThis . Bun = class {
342+ static version = '1.2.3' ;
343+ } ;
344+ const metadata = makeClientMetadata ( { driverInfo : { } } ) ;
345+ expect ( metadata . platform ) . to . equal ( 'Bun v1.2.3, LE' ) ;
346+ } ) ;
347+
348+ it ( 'sets platform to Bun with driverInfo.platform' , ( ) => {
349+ globalThis . Bun = class {
350+ static version = '1.2.3' ;
351+ } ;
352+ const metadata = makeClientMetadata ( { driverInfo : { platform : 'myPlatform' } } ) ;
353+ expect ( metadata . platform ) . to . equal ( 'Bun v1.2.3, LE|myPlatform' ) ;
354+ } ) ;
355+
356+ it ( 'ignores version if Bun.version is not a string' , ( ) => {
357+ globalThis . Bun = class {
358+ static version = 1 ;
359+ } ;
360+ const metadata = makeClientMetadata ( { driverInfo : { } } ) ;
361+ expect ( metadata . platform ) . to . equal ( 'Bun v0.0.0-unknown, LE' ) ;
362+ } ) ;
363+
364+ it ( 'ignores version if Bun.version is not a string and sets driverInfo.platform' , ( ) => {
365+ globalThis . Bun = class {
366+ static version = 1 ;
367+ } ;
368+ const metadata = makeClientMetadata ( { driverInfo : { platform : 'myPlatform' } } ) ;
369+ expect ( metadata . platform ) . to . equal ( 'Bun v0.0.0-unknown, LE|myPlatform' ) ;
370+ } ) ;
371+
372+ it ( 'ignores version if Bun is nullish' , ( ) => {
373+ globalThis . Bun = null ;
374+ const metadata = makeClientMetadata ( { driverInfo : { platform : 'myPlatform' } } ) ;
375+ expect ( metadata . platform ) . to . equal ( 'Bun v0.0.0-unknown, LE|myPlatform' ) ;
376+ } ) ;
377+ } ) ;
378+ } ) ;
291379 } ) ;
292380
293381 describe ( 'FAAS metadata application to handshake' , ( ) => {
0 commit comments