From 125862c918a45db22e7c219b109ea83f1588620e Mon Sep 17 00:00:00 2001 From: Daniel Lando Date: Fri, 15 Mar 2024 14:16:52 +0100 Subject: [PATCH 1/3] fix: expose mqttjs version on MqttClient.VERSION --- src/lib/client.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/client.ts b/src/lib/client.ts index fe299460d..d0da8419f 100644 --- a/src/lib/client.ts +++ b/src/lib/client.ts @@ -390,6 +390,8 @@ export interface MqttClientEventCallbacks { * (see Connection#connect) */ export default class MqttClient extends TypedEventEmitter { + public static VERSION = process.env.npm_package_version + /** Public fields */ /** It's true when client is connected to broker */ @@ -489,7 +491,7 @@ export default class MqttClient extends TypedEventEmitter Date: Fri, 15 Mar 2024 14:24:05 +0100 Subject: [PATCH 2/3] fix: add tests --- test/browser/test.js | 5 ++++- test/client.ts | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/test/browser/test.js b/test/browser/test.js index 3365f0407..8a08c7bcb 100644 --- a/test/browser/test.js +++ b/test/browser/test.js @@ -1,5 +1,5 @@ import { expect } from '@esm-bundle/chai'; -import mqtt from '../../'; // this will resolve to mqtt/dist/mqtt.esm.js +import mqtt, { MqttClient } from '../../'; // this will resolve to mqtt/dist/mqtt.esm.js // needed to test no-esm version /dist/mqtt.js /** @type { import('../../src') }*/ @@ -41,6 +41,9 @@ function testProto(proto, port, cb = () => { }) { let client = null; it('should connect-publish-subscribe', (done) => { + + expect(typeof MqttClient.VERSION).to.equal('string') + client = mqtt.connect(`${proto}://localhost:${port}`, { // log: console.log.bind(console), clientId: `testClient-${browser}-${proto}`, diff --git a/test/client.ts b/test/client.ts index 07413f1de..5c4fdf3d5 100644 --- a/test/client.ts +++ b/test/client.ts @@ -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) @@ -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', () => { From 070169a5d5b0e9cbf9574dd102d4aa2d01b0593e Mon Sep 17 00:00:00 2001 From: Daniel Lando Date: Fri, 15 Mar 2024 14:30:28 +0100 Subject: [PATCH 3/3] fix: browser tests --- test/browser/test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/browser/test.js b/test/browser/test.js index 8a08c7bcb..be2c5f8ae 100644 --- a/test/browser/test.js +++ b/test/browser/test.js @@ -1,5 +1,5 @@ import { expect } from '@esm-bundle/chai'; -import mqtt, { MqttClient } from '../../'; // this will resolve to mqtt/dist/mqtt.esm.js +import mqtt from '../../'; // this will resolve to mqtt/dist/mqtt.esm.js // needed to test no-esm version /dist/mqtt.js /** @type { import('../../src') }*/ @@ -42,7 +42,7 @@ function testProto(proto, port, cb = () => { }) { it('should connect-publish-subscribe', (done) => { - expect(typeof MqttClient.VERSION).to.equal('string') + expect(typeof mqtt.Client.VERSION).to.equal('string') client = mqtt.connect(`${proto}://localhost:${port}`, { // log: console.log.bind(console),