first commit
This commit is contained in:
108
node_modules/binaryjs/test/client.js
generated
vendored
Normal file
108
node_modules/binaryjs/test/client.js
generated
vendored
Normal file
@ -0,0 +1,108 @@
|
||||
var assert = require('assert');
|
||||
var binaryjs = require('../');
|
||||
var BinaryServer = binaryjs.BinaryServer;
|
||||
var BinaryClient = binaryjs.BinaryClient;
|
||||
var http = require('http');
|
||||
|
||||
var server, client, serverUrl = 'ws://localhost:9101';
|
||||
|
||||
describe('BinaryClient', function(){
|
||||
beforeEach(function(){
|
||||
server = new BinaryServer({port: 9101});
|
||||
});
|
||||
afterEach(function(){
|
||||
server.close();
|
||||
});
|
||||
describe('events for clients', function(){
|
||||
it('should be opennable and closeable', function(done){
|
||||
server.on('connection', function(client){
|
||||
client.on('close', function(){
|
||||
done();
|
||||
});
|
||||
});
|
||||
var client = new BinaryClient(serverUrl);
|
||||
client.on('open', function(){
|
||||
client.close();
|
||||
});
|
||||
});
|
||||
it('should receive streams', function(done){
|
||||
server.on('connection', function(client){
|
||||
client.on('stream', function(){
|
||||
done();
|
||||
});
|
||||
});
|
||||
var client = new BinaryClient(serverUrl);
|
||||
client.on('open', function(){
|
||||
|
||||
client.createStream();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('sending data', function(){
|
||||
it('should be able to send buffers', function(done){
|
||||
var string = 'test';
|
||||
server.on('connection', function(client){
|
||||
client.on('stream', function(stream){
|
||||
stream.on('data', function(data){
|
||||
assert.equal(data.toString(), string);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
var client = new BinaryClient(serverUrl);
|
||||
client.on('open', function(){
|
||||
client.send(new Buffer(string));
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('.streams', function(){
|
||||
it('should contain a list of streams', function(done){
|
||||
server.on('connection', function(client){
|
||||
var i = 0;
|
||||
var startLength = Object.keys(client.streams).length;
|
||||
client.on('stream', function(stream){
|
||||
assert.equal(client.streams[stream.id], stream);
|
||||
if(++i == 4) {
|
||||
var endLength = Object.keys(client.streams).length;
|
||||
assert.equal(endLength - startLength, i);
|
||||
done();
|
||||
}
|
||||
});
|
||||
var stream = client.createStream();
|
||||
assert.equal(client.streams[stream.id], stream);
|
||||
i++;
|
||||
stream = client.createStream();
|
||||
assert.equal(client.streams[stream.id], stream);
|
||||
i++;
|
||||
});
|
||||
var client = new BinaryClient(serverUrl);
|
||||
client.on('open', function(){
|
||||
client.createStream();
|
||||
client.createStream();
|
||||
});
|
||||
});
|
||||
it('should delete streams upon close event', function(done){
|
||||
var closed = 0;
|
||||
server.on('connection', function(client){
|
||||
client.on('stream', function(stream){
|
||||
stream.on('close', function(){
|
||||
assert(!(stream.id in client.streams));
|
||||
done();
|
||||
});
|
||||
});
|
||||
var stream = client.createStream();
|
||||
stream.on('close', function(){
|
||||
assert(!(stream.id in client.streams));
|
||||
});
|
||||
stream.destroy();
|
||||
});
|
||||
var client = new BinaryClient(serverUrl);
|
||||
client.on('open', function(){
|
||||
var stream = client.createStream();
|
||||
stream.destroy();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
44
node_modules/binaryjs/test/server.js
generated
vendored
Normal file
44
node_modules/binaryjs/test/server.js
generated
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
var assert = require('assert');
|
||||
var binaryjs = require('../');
|
||||
var BinaryServer = binaryjs.BinaryServer;
|
||||
var BinaryClient = binaryjs.BinaryClient;
|
||||
var http = require('http');
|
||||
|
||||
var server, client, serverUrl = 'ws://localhost:9101';
|
||||
|
||||
describe('BinaryServer', function(){
|
||||
describe('creating servers', function(){
|
||||
it('should allow creating servers with a port', function(){
|
||||
server = new BinaryServer({port: 9101});
|
||||
});
|
||||
it('should allow creating servers with an http server', function(){
|
||||
new BinaryServer({port: 9102});
|
||||
});
|
||||
});
|
||||
describe('.clients', function(){
|
||||
it('should contain a list of clients', function(done){
|
||||
var i = 0;
|
||||
var startLength = Object.keys(server.clients).length;
|
||||
server.on('connection', function(client){
|
||||
assert.equal(server.clients[client.id], client);
|
||||
if(++i == 3) {
|
||||
var endLength = Object.keys(server.clients).length;
|
||||
assert.equal(endLength - startLength, i);
|
||||
done();
|
||||
}
|
||||
});
|
||||
new BinaryClient(serverUrl);
|
||||
new BinaryClient(serverUrl);
|
||||
new BinaryClient(serverUrl);
|
||||
});
|
||||
});
|
||||
describe('.close()', function(){
|
||||
it('should prevent future clients connecting', function(done){
|
||||
server.close();
|
||||
var client = new BinaryClient(serverUrl);
|
||||
client.on('error', function(){
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
67
node_modules/binaryjs/test/stream.js
generated
vendored
Normal file
67
node_modules/binaryjs/test/stream.js
generated
vendored
Normal file
@ -0,0 +1,67 @@
|
||||
var assert = require('assert');
|
||||
var binaryjs = require('../');
|
||||
var BinaryServer = binaryjs.BinaryServer;
|
||||
var BinaryClient = binaryjs.BinaryClient;
|
||||
var http = require('http');
|
||||
|
||||
var server, client, serverUrl = 'ws://localhost:9101';
|
||||
|
||||
describe('BinaryStream', function(){
|
||||
beforeEach(function(){
|
||||
server = new BinaryServer({port: 9101});
|
||||
});
|
||||
afterEach(function(){
|
||||
server.close();
|
||||
});
|
||||
describe('Messaging', function(){
|
||||
it('should send and receive messages', function(done){
|
||||
server.on('connection', function(client){
|
||||
client.on('stream', function(stream){
|
||||
stream.on('data', function(){
|
||||
done();
|
||||
});
|
||||
stream.write('hi');
|
||||
});
|
||||
});
|
||||
var client = new BinaryClient(serverUrl);
|
||||
client.on('open', function(){
|
||||
var stream = client.createStream();
|
||||
stream.on('data', function(){
|
||||
stream.write('bye');
|
||||
});
|
||||
});
|
||||
});
|
||||
it('should send and receive pause, resume, and end', function(done){
|
||||
server.on('connection', function(client){
|
||||
client.on('stream', function(stream){
|
||||
stream.on('pause', function(){
|
||||
assert(stream.paused);
|
||||
});
|
||||
stream.resume();
|
||||
stream.on('resume', function(){
|
||||
assert(!stream.paused);
|
||||
});
|
||||
stream.on('end', function(){
|
||||
assert(!stream.readable);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
var client = new BinaryClient(serverUrl);
|
||||
client.on('open', function(){
|
||||
var stream = client.createStream();
|
||||
stream.pause();
|
||||
stream.on('pause', function(){
|
||||
assert(stream.paused);
|
||||
});
|
||||
stream.on('resume', function(){
|
||||
assert(!stream.paused);
|
||||
stream.end();
|
||||
});
|
||||
stream.on('end', function(){
|
||||
assert(!stream.readable);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user