Skip to content

Commit

Permalink
add browser bundle test (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
sonnyp committed Dec 20, 2017
1 parent 9527592 commit bb1b335
Show file tree
Hide file tree
Showing 5 changed files with 358 additions and 17 deletions.
9 changes: 6 additions & 3 deletions Makefile
@@ -1,6 +1,6 @@
PATH := node_modules/.bin:$(PATH)

.PHONY: setup test clean bundle start stop restart size
.PHONY: setup test clean bundle start stop restart size bundle

setup:
node packages/xmpp.js/script.js
Expand All @@ -26,8 +26,8 @@ test-ci:
ava
eslint .
make restart
ava --serial --fail-fast test/
lerna run prepublish
ava --serial --fail-fast test/
make bundlesize

clean:
Expand All @@ -53,6 +53,9 @@ bundlesize:
gzip -kf9 packages/client/dist/xmpp.min.js
bundlesize

size:
bundle:
cd packages/client && yarn run prepublish

size:
make bundle
make bundlesize
5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -21,11 +21,14 @@
"eslint-plugin-standard": "^3.0.1",
"eslint-plugin-unicorn": "^3.0.1",
"exorcist": "^1.0.0",
"jsdom": "^11.5.1",
"lerna": "^2.5.1",
"node-fetch": "^1.7.3",
"prettier": "^1.9.2",
"sinon": "^4.1.3",
"uglify-es": "^3.2.2",
"util.promisify": "^1.0.0"
"util.promisify": "^1.0.0",
"ws": "^3.3.3"
},
"ava": {
"require": "babel-register",
Expand Down
4 changes: 3 additions & 1 deletion packages/client/index.js
Expand Up @@ -33,7 +33,9 @@ function xmpp() {

const _sasl = sasl()

streamFeatures.use(...starttls.streamFeature())
if (starttls.streamFeature) {
streamFeatures.use(...starttls.streamFeature())
}
router.use('stream:features', _sasl.route())
streamFeatures.use(...bind.streamFeature())
router.use('stream:features', sessionEstablishment())
Expand Down
49 changes: 49 additions & 0 deletions test/browser.js
@@ -0,0 +1,49 @@
'use strict'

const {JSDOM} = require('jsdom')
const fetch = require('node-fetch')
const WebSocket = require('ws')
const {readFileSync} = require('fs')

const test = require('ava')
const {jid} = require('../packages/client')
const debug = require('../packages/debug')
const server = require('../server')

process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'

const USERNAME = 'client'
const PASSWORD = 'foobar'
const domain = 'localhost'
const JID = jid(USERNAME, domain).toString()

const xmppjs = readFileSync('./packages/client/dist/xmpp.js', {
encoding: 'utf-8',
})

test.beforeEach(t => {
const {window} = new JSDOM(``, {runScripts: 'dangerously'})
window.WebSocket = WebSocket
window.fetch = fetch
const {document} = window
const scriptEl = document.createElement('script')
scriptEl.textContent = xmppjs
document.body.appendChild(scriptEl)
const {xmpp} = window
t.context = xmpp.xmpp
return server.restart()
})

test('client ws://', t => {
const {client} = t.context()
debug(client)

client.handle('authenticate', auth => {
t.is(typeof auth, 'function')
return auth(USERNAME, PASSWORD)
})

return client.start('ws://localhost:5280/xmpp-websocket').then(id => {
t.is(id.bare().toString(), JID)
})
})

0 comments on commit bb1b335

Please sign in to comment.