Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
94 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
ui: mocha-bdd | ||
server: ./test/support/browser_server.js | ||
browsers: | ||
- name: chrome | ||
version: latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
'use strict'; | ||
|
||
// weird hack to work on browserify | ||
// here we have a strange dependency loop | ||
require('stream'); | ||
require('readable-stream'); | ||
|
||
var jschan = {}; | ||
module.exports = jschan; | ||
|
||
jschan.memorySession = require('./memory/session'); | ||
jschan.streamSession = require('./stream/session'); | ||
jschan.websocketClientSession = require('./websocket/client'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
'use strict'; | ||
|
||
var jschan = require('../../lib/jschan.js'); | ||
var server = jschan.websocketServer(); | ||
|
||
function handleMsg(msg) { | ||
var stream = msg.returnChannel; | ||
delete msg.returnChannel; | ||
stream.end(msg); | ||
} | ||
|
||
function handleChannel(chan) { | ||
chan.on('data', handleMsg); | ||
} | ||
|
||
function handleSession(session) { | ||
session.on('channel', handleChannel); | ||
} | ||
|
||
server.on('session', handleSession); | ||
|
||
if (process.env.ZUUL_PORT) { | ||
server.listen(process.env.ZUUL_PORT); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
'use strict'; | ||
|
||
if (!process.browser) { | ||
// this is a browser test | ||
return; | ||
} | ||
|
||
var jschan = require('../lib/jschan'); | ||
var expect = require('must'); | ||
|
||
describe('websocket client on browserify', function() { | ||
var session; | ||
|
||
beforeEach(function() { | ||
session = jschan.websocketClientSession('ws://localhost:8080'); | ||
}); | ||
|
||
afterEach(function(done) { | ||
if (!session) { | ||
return done(); | ||
} | ||
|
||
session.close(done); | ||
}); | ||
|
||
it('should work with an echo server', function(done) { | ||
var chan = session.createWriteChannel(); | ||
var ret = chan.createReadChannel(); | ||
|
||
ret.on('data', function(res) { | ||
expect(res).to.eql({ hello: 'world' }); | ||
done(); | ||
}); | ||
|
||
chan.end({ | ||
hello:'world', | ||
returnChannel: ret | ||
}); | ||
}); | ||
}); |