Skip to content

Commit

Permalink
fix: browser tests not working (#1628)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando authored Jul 3, 2023
1 parent 0ed0754 commit 8775fcd
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/mqttjs-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"


6 changes: 3 additions & 3 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": [
Expand Down
6 changes: 4 additions & 2 deletions test/browser/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
12 changes: 8 additions & 4 deletions test/browser/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})

0 comments on commit 8775fcd

Please sign in to comment.