Skip to content

Commit 8775fcd

Browse files
authored
fix: browser tests not working (#1628)
1 parent 0ed0754 commit 8775fcd

File tree

5 files changed

+24
-13
lines changed

5 files changed

+24
-13
lines changed

.github/workflows/mqttjs-test.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,20 @@ jobs:
2727
with:
2828
node-version: ${{ matrix.node-version }}
2929
cache: 'npm'
30-
- run: npm ci
31-
- name: Node Tests
30+
31+
- name: Install Dependencies
32+
run: npm ci
33+
34+
- name: Test NodeJS
3235
run: npm run test:node
3336
env:
3437
CI: true
3538
DEBUG: "mqttjs"
39+
3640
- name: Test Typescript
3741
run: npm run test:typescript
3842
env:
3943
CI: true
4044
DEBUG: "mqttjs"
4145

46+

lib/client.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ const validations = require('./validations')
1717
const xtend = require('xtend')
1818
const debug = require('debug')('mqttjs:client')
1919
const nextTick = process ? process.nextTick : function (callback) { setTimeout(callback, 0) }
20-
const setImmediate = global.setImmediate || function (callback) {
21-
const args = arguments.slice(1)
22-
process.nextTick(callback.bind(null, ...args))
20+
const setImmediate = global.setImmediate || function (...args) {
21+
const callback = args.shift()
22+
nextTick(callback.bind(null, ...args))
2323
}
2424

2525
const defaultConnectOptions = {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
"mkdirp": "^0.5.1",
124124
"mocha": "^9.2.0",
125125
"mqtt-connection": "^4.0.0",
126+
"mqtt-level-store": "^3.1.0",
126127
"nyc": "^15.0.1",
127128
"pre-commit": "^1.2.2",
128129
"release-it": "^15.11.0",
@@ -133,8 +134,7 @@
133134
"standard": "^16.0.4",
134135
"tape": "^5.5.2",
135136
"terser": "^5.14.2",
136-
"typescript": "^4.5.5",
137-
"mqtt-level-store": "^3.1.0"
137+
"typescript": "^4.5.5"
138138
},
139139
"standard": {
140140
"env": [

test/browser/server.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,14 @@ function start (startPort, done) {
116116
return server
117117
}
118118

119+
const port = process.env.PORT || process.env.AIRTAP_SUPPORT_PORT
120+
119121
if (require.main === module) {
120-
start(process.env.PORT || process.env.AIRTAP_PORT, function (err) {
122+
start(port, function (err) {
121123
if (err) {
122124
console.error(err)
123125
return
124126
}
125-
console.log('tunnelled server started on port', process.env.PORT || process.env.AIRTAP_PORT)
127+
console.log('tunnelled server started on port', port)
126128
})
127129
}

test/browser/test.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,19 @@ client.on('reconnect', function () {
2222
})
2323

2424
test('MQTT.js browser test', function (t) {
25-
t.plan(2)
25+
t.plan(4)
2626
client.on('connect', function () {
27-
client.on('message', function (msg) {
28-
t.equal(msg, 'Hello World!')
27+
client.on('message', function (topic, msg) {
28+
t.equal(topic, 'hello', 'should match topic')
29+
t.equal(msg.toString(), 'Hello World!', 'should match payload')
30+
client.end(() => {
31+
t.pass('client should close')
32+
})
2933
})
3034
client.subscribe('hello', function () {
3135
}).publish('hello', 'Hello World!')
3236
})
3337
client.once('close', function () {
34-
t.true(true)
38+
t.pass('should emit close')
3539
})
3640
})

0 commit comments

Comments
 (0)