Skip to content

Commit

Permalink
fix: expose mqttjs version on MqttClient.VERSION (#1821)
Browse files Browse the repository at this point in the history
* fix: expose mqttjs version on MqttClient.VERSION

* fix: add tests

* fix: browser tests
  • Loading branch information
robertsLando committed Mar 15, 2024
1 parent f9b1204 commit 50776a7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/lib/client.ts
Expand Up @@ -390,6 +390,8 @@ export interface MqttClientEventCallbacks {
* (see Connection#connect)
*/
export default class MqttClient extends TypedEventEmitter<MqttClientEventCallbacks> {
public static VERSION = process.env.npm_package_version

/** Public fields */

/** It's true when client is connected to broker */
Expand Down Expand Up @@ -489,7 +491,7 @@ export default class MqttClient extends TypedEventEmitter<MqttClientEventCallbac
this.log = this.options.log || _debug('mqttjs:client')
this.noop = this._noop.bind(this)

this.log('MqttClient :: version:', process.env.npm_package_version)
this.log('MqttClient :: version:', MqttClient.VERSION)

if (isWebWorker) {
this.log('MqttClient :: environment', 'webworker')
Expand Down
3 changes: 3 additions & 0 deletions test/browser/test.js
Expand Up @@ -41,6 +41,9 @@ function testProto(proto, port, cb = () => { }) {
let client = null;

it('should connect-publish-subscribe', (done) => {

expect(typeof mqtt.Client.VERSION).to.equal('string')

client = mqtt.connect(`${proto}://localhost:${port}`, {
// log: console.log.bind(console),
clientId: `testClient-${browser}-${proto}`,
Expand Down
7 changes: 7 additions & 0 deletions test/client.ts
Expand Up @@ -17,6 +17,9 @@ import abstractClientTests from './abstract_client'
import { IClientOptions } from 'src/lib/client'
import { describe, it, after } from 'node:test'

// eslint-disable-next-line @typescript-eslint/no-var-requires
const pkgJson = require('../package.json')

const debug = _debug('mqttjs:client-test')

const ports = getPorts(2)
Expand All @@ -39,6 +42,10 @@ describe('MqttClient', () => {
process.exit(0)
})

it('should have static VERSION set', function _test(t) {
assert.equal(mqtt.MqttClient.VERSION, pkgJson.version)
})

abstractClientTests(server, config, ports)

describe('creating', () => {
Expand Down

0 comments on commit 50776a7

Please sign in to comment.