Skip to content

Commit ae4c11e

Browse files
authored
chore: add browser tests to ci (#1627)
1 parent 0871a66 commit ae4c11e

File tree

9 files changed

+114
-21
lines changed

9 files changed

+114
-21
lines changed

.airtap.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
providers:
2+
- airtap-playwright
3+
ui: mocha-bdd
4+
browsers:
5+
- name: chromium
6+
supports:
7+
headless: true
8+

.airtaprc.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

.github/workflows/mqttjs-test.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,12 @@ jobs:
4242
env:
4343
CI: true
4444
DEBUG: "mqttjs"
45+
46+
- name: Test Browser
47+
timeout-minutes: 2
48+
run: |
49+
npm run browser-build
50+
npm run unit-test:browser
51+
4552

4653

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ test/typescript/*.js
1717
test/typescript/*.map
1818
# VS Code stuff
1919
**/typings/**
20-
20+
.vscode/
2121
.npmrc
22+

lib/connect/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const MqttClient = require('../client')
44
const Store = require('../store')
55
const DefaultMessageIdProvider = require('../default-message-id-provider')
66
const UniqueMessageIdProvider = require('../unique-message-id-provider')
7-
const IS_BROWSER = require('../is-browser').IS_BROWSER
7+
const { IS_BROWSER } = require('../is-browser')
88
const url = require('url')
99
const xtend = require('xtend')
1010
const debug = require('debug')('mqttjs')

lib/connect/ws.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const WS = require('ws')
55
const debug = require('debug')('mqttjs:ws')
66
const duplexify = require('duplexify')
77
const Transform = require('readable-stream').Transform
8-
const IS_BROWSER = require('../is-browser').IS_BROWSER
8+
const { IS_BROWSER } = require('../is-browser')
99

1010
const WSS_OPTIONS = [
1111
'rejectUnauthorized',
@@ -100,9 +100,9 @@ function createWebSocket (client, url, opts) {
100100

101101
function createBrowserWebSocket (client, opts) {
102102
const websocketSubProtocol =
103-
(opts.protocolId === 'MQIsdp') && (opts.protocolVersion === 3)
104-
? 'mqttv3.1'
105-
: 'mqtt'
103+
(opts.protocolId === 'MQIsdp') && (opts.protocolVersion === 3)
104+
? 'mqttv3.1'
105+
: 'mqtt'
106106

107107
const url = buildUrl(opts, client)
108108
/* global WebSocket */

package-lock.json

Lines changed: 75 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
"@types/ws": "^7.4.7",
114114
"aedes": "^0.46.2",
115115
"airtap": "^4.0.4",
116+
"airtap-playwright": "^1.0.1",
116117
"browserify": "^17.0.0",
117118
"chai": "^4.2.0",
118119
"chokidar": "^3.5.3",

test/browser/test.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

33
const test = require('tape')
4-
const mqtt = require('../../lib/connect')
4+
const mqtt = require('../../dist/mqtt.min')
55
const _URL = require('url')
66
// eslint-disable-next-line
77
const parsed = _URL.parse(document.URL)
@@ -22,7 +22,7 @@ client.on('reconnect', function () {
2222
})
2323

2424
test('MQTT.js browser test', function (t) {
25-
t.plan(4)
25+
t.plan(6)
2626
client.on('connect', function () {
2727
client.on('message', function (topic, msg) {
2828
t.equal(topic, 'hello', 'should match topic')
@@ -31,9 +31,21 @@ test('MQTT.js browser test', function (t) {
3131
t.pass('client should close')
3232
})
3333
})
34-
client.subscribe('hello', function () {
35-
}).publish('hello', 'Hello World!')
34+
35+
client.subscribe('hello', function (err) {
36+
t.error(err, 'no error on subscribe')
37+
if (!err) {
38+
client.publish('hello', 'Hello World!', function (err) {
39+
t.error(err, 'no error on publish')
40+
})
41+
}
42+
})
3643
})
44+
45+
client.on('error', function (err) {
46+
t.fail(err, 'no error')
47+
})
48+
3749
client.once('close', function () {
3850
t.pass('should emit close')
3951
})

0 commit comments

Comments
 (0)