Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: expose mqttjs version on MqttClient.VERSION #1821

Merged
merged 3 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion src/lib/client.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading