Skip to content

Commit

Permalink
fix: assumption about Bun typeof
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbeeken committed Apr 12, 2023
1 parent 5f10d3d commit 8dae68d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/cmap/handshake/client_metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
12 changes: 11 additions & 1 deletion test/unit/cmap/handshake/client_metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' } });
Expand Down

0 comments on commit 8dae68d

Please sign in to comment.