diff --git a/.github/workflows/mqttjs-test.yml b/.github/workflows/mqttjs-test.yml index 43419f951..13bf1b8f4 100644 --- a/.github/workflows/mqttjs-test.yml +++ b/.github/workflows/mqttjs-test.yml @@ -27,15 +27,20 @@ jobs: with: node-version: ${{ matrix.node-version }} cache: 'npm' - - run: npm ci - - name: Node Tests + + - name: Install Dependencies + run: npm ci + + - name: Test NodeJS run: npm run test:node env: CI: true DEBUG: "mqttjs" + - name: Test Typescript run: npm run test:typescript env: CI: true DEBUG: "mqttjs" + diff --git a/lib/client.js b/lib/client.js index 0601dd2e7..5da746a92 100644 --- a/lib/client.js +++ b/lib/client.js @@ -17,9 +17,9 @@ const validations = require('./validations') const xtend = require('xtend') const debug = require('debug')('mqttjs:client') const nextTick = process ? process.nextTick : function (callback) { setTimeout(callback, 0) } -const setImmediate = global.setImmediate || function (callback) { - const args = arguments.slice(1) - process.nextTick(callback.bind(null, ...args)) +const setImmediate = global.setImmediate || function (...args) { + const callback = args.shift() + nextTick(callback.bind(null, ...args)) } const defaultConnectOptions = { diff --git a/package.json b/package.json index cba27acdf..1909e07ff 100644 --- a/package.json +++ b/package.json @@ -123,6 +123,7 @@ "mkdirp": "^0.5.1", "mocha": "^9.2.0", "mqtt-connection": "^4.0.0", + "mqtt-level-store": "^3.1.0", "nyc": "^15.0.1", "pre-commit": "^1.2.2", "release-it": "^15.11.0", @@ -133,8 +134,7 @@ "standard": "^16.0.4", "tape": "^5.5.2", "terser": "^5.14.2", - "typescript": "^4.5.5", - "mqtt-level-store": "^3.1.0" + "typescript": "^4.5.5" }, "standard": { "env": [ diff --git a/test/browser/server.js b/test/browser/server.js index b1dcf2969..b3da16edb 100644 --- a/test/browser/server.js +++ b/test/browser/server.js @@ -116,12 +116,14 @@ function start (startPort, done) { return server } +const port = process.env.PORT || process.env.AIRTAP_SUPPORT_PORT + if (require.main === module) { - start(process.env.PORT || process.env.AIRTAP_PORT, function (err) { + start(port, function (err) { if (err) { console.error(err) return } - console.log('tunnelled server started on port', process.env.PORT || process.env.AIRTAP_PORT) + console.log('tunnelled server started on port', port) }) } diff --git a/test/browser/test.js b/test/browser/test.js index 26873b989..357773bc4 100644 --- a/test/browser/test.js +++ b/test/browser/test.js @@ -22,15 +22,19 @@ client.on('reconnect', function () { }) test('MQTT.js browser test', function (t) { - t.plan(2) + t.plan(4) client.on('connect', function () { - client.on('message', function (msg) { - t.equal(msg, 'Hello World!') + client.on('message', function (topic, msg) { + t.equal(topic, 'hello', 'should match topic') + t.equal(msg.toString(), 'Hello World!', 'should match payload') + client.end(() => { + t.pass('client should close') + }) }) client.subscribe('hello', function () { }).publish('hello', 'Hello World!') }) client.once('close', function () { - t.true(true) + t.pass('should emit close') }) })