Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: assumption about Bun typeof
  • Loading branch information
nbbeeken committed Apr 12, 2023
commit 8dae68df8feb7f649799a4e1d87029211567bbeb
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