49 lines
1.7 KiB
JavaScript
49 lines
1.7 KiB
JavaScript
const expect = require('chai').expect
|
|
const Faye = require('faye')
|
|
|
|
// for reference of _state contants,
|
|
// @see https://github.com/faye/faye/blob/60141e8d3942a88ba3de6a9b3aef9503bc1bb1e6/src/protocol/client.js#L178
|
|
const UNCONNECTED = 1
|
|
const CONNECTING = 2
|
|
const CONNECTED = 3
|
|
const DISCONNECTED = 4
|
|
|
|
describe('faye', function () {
|
|
describe('sending event', function () {
|
|
let client = new Faye.Client('http://localhost:3535/faye');
|
|
// let client = new Faye.Client('https://realtime.futureporn.net/faye');
|
|
client.connect()
|
|
it('should send a signal', function (done) {
|
|
const pub = client.publish('/signals', {
|
|
text: 'hello worldy 123!'
|
|
})
|
|
pub.callback(function () {
|
|
expect(client._state).to.equal(CONNECTED)
|
|
done()
|
|
})
|
|
pub.errback(function (e) {
|
|
throw new Error(e)
|
|
})
|
|
})
|
|
it('should receive a signal', function (done) {
|
|
const sub = client.subscribe('/signals', function(message) {
|
|
console.log('Got a message: ' + message.text);
|
|
expect(message.text).to.equal('Hello mocha!')
|
|
done()
|
|
});
|
|
sub.callback(function () {
|
|
expect(client._state).to.equal(CONNECTED)
|
|
})
|
|
sub.errback(function (e) {
|
|
throw new Error(e)
|
|
})
|
|
})
|
|
this.afterEach(function () {
|
|
expect(client._state).to.equal(CONNECTED)
|
|
})
|
|
this.afterAll(function () {
|
|
client.disconnect()
|
|
expect(client._state).to.equal(DISCONNECTED)
|
|
})
|
|
})
|
|
}) |