From c2785fcbb181a3046e24d98f925cea6d19a73e4b Mon Sep 17 00:00:00 2001 From: Kevin Roark Date: Thu, 20 Feb 2014 17:23:49 -0500 Subject: [PATCH] fixed spacing on test and updated build --- socket.io.js | 2 +- test/connection.js | 142 ++++++++++++++++++++++----------------------- 2 files changed, 72 insertions(+), 72 deletions(-) diff --git a/socket.io.js b/socket.io.js index b5315dab..1881bac1 100644 --- a/socket.io.js +++ b/socket.io.js @@ -7301,7 +7301,7 @@ exports.decode = function(obj) { if ('string' == typeof obj) { return decodeString(obj); } - else if (Buffer.isBuffer(obj) || + else if ((global.Buffer && Buffer.isBuffer(obj)) || (global.ArrayBuffer && obj instanceof ArrayBuffer) || (global.Blob && obj instanceof Blob)) { return decodeBuffer(obj); diff --git a/test/connection.js b/test/connection.js index 1e7c5938..27eb16a2 100644 --- a/test/connection.js +++ b/test/connection.js @@ -53,94 +53,94 @@ describe('connection', function() { }); if (!global.Blob && !global.ArrayBuffer) { - it('should get base64 data as a last resort', function(done) { - socket.on('takebin', function(a) { - expect(a.base64).to.be(true); - var bytes = b64.toByteArray(a.data); - var dataString = String.fromCharCode.apply(String, bytes); - expect(dataString).to.eql('asdfasdf'); - done(); - }); - socket.emit('getbin'); + it('should get base64 data as a last resort', function(done) { + socket.on('takebin', function(a) { + expect(a.base64).to.be(true); + var bytes = b64.toByteArray(a.data); + var dataString = String.fromCharCode.apply(String, bytes); + expect(dataString).to.eql('asdfasdf'); + done(); }); + socket.emit('getbin'); + }); } if (global.ArrayBuffer) { - var base64 = require('base64-arraybuffer'); + var base64 = require('base64-arraybuffer'); - it('should get binary data (as an ArrayBuffer)', function(done){ - socket.emit('doge'); - socket.on('doge', function(buffer){ - expect(buffer instanceof ArrayBuffer).to.be(true); - done(); - }); + it('should get binary data (as an ArrayBuffer)', function(done){ + socket.emit('doge'); + socket.on('doge', function(buffer){ + expect(buffer instanceof ArrayBuffer).to.be(true); + done(); }); + }); - it('should send binary data (as an ArrayBuffer)', function(done){ - socket.on('buffack', function(){ - done(); - }); - var buf = base64.decode("asdfasdf"); - socket.emit('buffa', buf); + it('should send binary data (as an ArrayBuffer)', function(done){ + socket.on('buffack', function(){ + done(); }); + var buf = base64.decode("asdfasdf"); + socket.emit('buffa', buf); + }); - it('should send binary data (as an ArrayBuffer) mixed with json', function(done) { - socket.on('jsonbuff-ack', function() { - done(); - }); - var buf = base64.decode("howdy"); - socket.emit('jsonbuff', {hello: 'lol', message: buf, goodbye: 'gotcha'}); + it('should send binary data (as an ArrayBuffer) mixed with json', function(done) { + socket.on('jsonbuff-ack', function() { + done(); }); + var buf = base64.decode("howdy"); + socket.emit('jsonbuff', {hello: 'lol', message: buf, goodbye: 'gotcha'}); + }); - it('should send events with ArrayBuffers in the correct order', function(done) { - socket.on('abuff2-ack', function() { - done(); - }); - var buf = base64.decode("abuff1"); - socket.emit('abuff1', buf); - socket.emit('abuff2', 'please arrive second'); + it('should send events with ArrayBuffers in the correct order', function(done) { + socket.on('abuff2-ack', function() { + done(); }); + var buf = base64.decode("abuff1"); + socket.emit('abuff1', buf); + socket.emit('abuff2', 'please arrive second'); + }); } if (global.Blob && null != getTextBlob('xxx')) { - it('should send binary data (as a Blob)', function(done){ - socket.on('back', function(){ - done(); - }); - var blob = getTextBlob('hello world'); - socket.emit('blob', blob); - }); - - it('should send binary data (as a Blob) mixed with json', function(done) { - socket.on('jsonblob-ack', function() { - done(); - }); - var blob = getTextBlob('EEEEEEEEE'); - socket.emit('jsonblob', {hello: 'lol', message: blob, goodbye: 'gotcha'}); - }); - - it('should send events with Blobs in the correct order', function(done) { - socket.on('blob3-ack', function() { - done(); - }); - var blob = getTextBlob('BLOBBLOB'); - socket.emit('blob1', blob); - socket.emit('blob2', 'second'); - socket.emit('blob3', blob); - }); - - it('should clear its packet buffer in case of disconnect', function(done) { - var blob = getTextBlob('BLOBBLOB'); - for (var i=0; i < 10; i++) { // fill the buffer - socket.emit('asdf', blob); - } - expect(socket.io.packetBuffer.length).to.not.be(0); - expect(socket.io.encoding).to.be(true); - socket.io.disconnect(); - expect(socket.io.packetBuffer.length).to.be(0); - expect(socket.io.encoding).to.be(false); + it('should send binary data (as a Blob)', function(done){ + socket.on('back', function(){ done(); }); + var blob = getTextBlob('hello world'); + socket.emit('blob', blob); + }); + + it('should send binary data (as a Blob) mixed with json', function(done) { + socket.on('jsonblob-ack', function() { + done(); + }); + var blob = getTextBlob('EEEEEEEEE'); + socket.emit('jsonblob', {hello: 'lol', message: blob, goodbye: 'gotcha'}); + }); + + it('should send events with Blobs in the correct order', function(done) { + socket.on('blob3-ack', function() { + done(); + }); + var blob = getTextBlob('BLOBBLOB'); + socket.emit('blob1', blob); + socket.emit('blob2', 'second'); + socket.emit('blob3', blob); + }); + + it('should clear its packet buffer in case of disconnect', function(done) { + var blob = getTextBlob('BLOBBLOB'); + for (var i=0; i < 10; i++) { // fill the buffer + socket.emit('asdf', blob); + } + expect(socket.io.packetBuffer.length).to.not.be(0); + expect(socket.io.encoding).to.be(true); + socket.io.disconnect(); + expect(socket.io.packetBuffer.length).to.be(0); + expect(socket.io.encoding).to.be(false); + done(); + }); } });