Permalink
Browse files

stream tests + bust into diff files

  • Loading branch information...
1 parent d94b799 commit da69630f8ff0906a9390ff3e97e012e51c9f01bf @ericz ericz committed Jul 24, 2012
Showing with 113 additions and 48 deletions.
  1. +2 −48 test/{test.js → client.js}
  2. +44 −0 test/server.js
  3. +67 −0 test/stream.js
@@ -6,43 +6,6 @@ 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();
- });
- });
- });
-});
-
describe('BinaryClient', function(){
beforeEach(function(){
server = new BinaryServer({port: 9101});
@@ -120,11 +83,12 @@ describe('BinaryClient', function(){
});
});
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();
+ done();
});
});
var stream = client.createStream();
@@ -142,13 +106,3 @@ describe('BinaryClient', function(){
});
});
-describe('BinaryStream', function(){
- beforeEach(function(){
- server = new BinaryServer({port: 9101});
- });
- afterEach(function(){
- server.close();
- });
- describe('events for clients', function(){
- });
-});
View
@@ -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();
+ });
+ });
+ });
+});
View
@@ -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);
+ });
+ });
+ });
+ });
+});

0 comments on commit da69630

Please sign in to comment.