From 8dae68df8feb7f649799a4e1d87029211567bbeb Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Wed, 12 Apr 2023 16:02:32 -0400 Subject: [PATCH] fix: assumption about Bun typeof --- src/cmap/handshake/client_metadata.ts | 5 ++++- test/unit/cmap/handshake/client_metadata.test.ts | 12 +++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/cmap/handshake/client_metadata.ts b/src/cmap/handshake/client_metadata.ts index 3aab82c3d6..6a07e73a3f 100644 --- a/src/cmap/handshake/client_metadata.ts +++ b/src/cmap/handshake/client_metadata.ts @@ -277,7 +277,10 @@ function getRuntimeInfo(): string { if ('Bun' in globalThis) { const version = - Bun != null && typeof Bun === 'object' && 'version' in Bun && typeof Bun.version === 'string' + Bun != null && + (typeof Bun === 'function' || typeof Bun === 'object') && + 'version' in Bun && + typeof Bun.version === 'string' ? Bun.version : '0.0.0'; diff --git a/test/unit/cmap/handshake/client_metadata.test.ts b/test/unit/cmap/handshake/client_metadata.test.ts index 31694a7adc..d94700af1c 100644 --- a/test/unit/cmap/handshake/client_metadata.test.ts +++ b/test/unit/cmap/handshake/client_metadata.test.ts @@ -344,12 +344,22 @@ describe('client metadata module', () => { expect(delete globalThis.Bun, 'failed to delete Bun global').to.be.true; }); - it('sets platform to Bun', () => { + it('sets platform to Bun if typeof is object', () => { globalThis.Bun = { version: '1.2.3' }; const metadata = makeClientMetadata({ driverInfo: {} }); expect(metadata.platform).to.equal('Bun v1.2.3, LE'); }); + it('sets platform to Bun if typeof is function', () => { + function Bun() { + return null; + } + Bun.version = '1.2.3'; + globalThis.Bun = Bun; + const metadata = makeClientMetadata({ driverInfo: {} }); + expect(metadata.platform).to.equal('Bun v1.2.3, LE'); + }); + it('sets platform to Bun with driverInfo.platform', () => { globalThis.Bun = { version: '1.2.3' }; const metadata = makeClientMetadata({ driverInfo: { platform: 'myPlatform' } });