mirror of
https://github.com/socketio/socket.io.git
synced 2026-04-30 03:00:39 -04:00
Merge branch 'orgmaster' into queryStringFix
* orgmaster: (44 commits) bump zuul Remove jspm browser config Run lint before test instead of before build ESlint manual fix Eslint autofix Add env to eslintrc Exclude generated files from linting updated babel-eslint dep to 4.1.7 (4.1.6 broken) refactor gulpfile Add eslint to gulpfile and create gulp task default fixed regex Rename gulp task webpack to build Remove commented make recipe removed babel react preset Makefile use gulp from node_modules instead of global Remove browserify stuff, add zuul-builder-webpack devDep Migrate zuul config from yml to js Refactor webpack config out to support/webpack.config.js removed ide-specific entries from gitignore updated makefile to use gulp commands ... Conflicts: lib/manager.js lib/socket.js
This commit is contained in:
6
test/.eslintrc.json
Normal file
6
test/.eslintrc.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"env": {
|
||||
"node": true,
|
||||
"mocha": true
|
||||
}
|
||||
}
|
||||
@@ -4,25 +4,25 @@ var hasCORS = require('has-cors');
|
||||
var textBlobBuilder = require('text-blob-builder');
|
||||
var env = require('./support/env');
|
||||
|
||||
describe('connection', function() {
|
||||
describe('connection', function () {
|
||||
this.timeout(70000);
|
||||
|
||||
it('should connect to localhost', function(done){
|
||||
it('should connect to localhost', function (done) {
|
||||
var socket = io({ forceNew: true });
|
||||
socket.emit('hi');
|
||||
socket.on('hi', function(data){
|
||||
socket.on('hi', function (data) {
|
||||
socket.disconnect();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should not connect when autoConnect option set to false', function() {
|
||||
it('should not connect when autoConnect option set to false', function () {
|
||||
var socket = io({ forceNew: true, autoConnect: false });
|
||||
expect(socket.io.engine).to.not.be.ok();
|
||||
socket.disconnect();
|
||||
});
|
||||
|
||||
it('should start two connections with same path', function(){
|
||||
it('should start two connections with same path', function () {
|
||||
var s1 = io('/');
|
||||
var s2 = io('/');
|
||||
|
||||
@@ -31,7 +31,7 @@ describe('connection', function() {
|
||||
s2.disconnect();
|
||||
});
|
||||
|
||||
it('should start two connections with same path and different querystrings', function(){
|
||||
it('should start two connections with same path and different querystrings', function () {
|
||||
var s1 = io('/?woot');
|
||||
var s2 = io('/');
|
||||
|
||||
@@ -40,38 +40,38 @@ describe('connection', function() {
|
||||
s2.disconnect();
|
||||
});
|
||||
|
||||
it('should work with acks', function(done){
|
||||
it('should work with acks', function (done) {
|
||||
var socket = io({ forceNew: true });
|
||||
socket.emit('ack');
|
||||
socket.on('ack', function(fn){
|
||||
socket.on('ack', function (fn) {
|
||||
fn(5, { test: true });
|
||||
});
|
||||
socket.on('got it', function(){
|
||||
socket.on('got it', function () {
|
||||
socket.disconnect();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should receive date with ack', function(done){
|
||||
it('should receive date with ack', function (done) {
|
||||
var socket = io({ forceNew: true });
|
||||
socket.emit('getAckDate', { test: true }, function(data){
|
||||
expect(data).to.be.a('string');
|
||||
socket.disconnect();
|
||||
done();
|
||||
socket.emit('getAckDate', { test: true }, function (data) {
|
||||
expect(data).to.be.a('string');
|
||||
socket.disconnect();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should work with false', function(done){
|
||||
it('should work with false', function (done) {
|
||||
var socket = io({ forceNew: true });
|
||||
socket.emit('false');
|
||||
socket.on('false', function(f){
|
||||
socket.on('false', function (f) {
|
||||
expect(f).to.be(false);
|
||||
socket.disconnect();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should receive utf8 multibyte characters', function(done) {
|
||||
it('should receive utf8 multibyte characters', function (done) {
|
||||
var correct = [
|
||||
'てすと',
|
||||
'Я Б Г Д Ж Й',
|
||||
@@ -82,10 +82,10 @@ describe('connection', function() {
|
||||
|
||||
var socket = io({ forceNew: true });
|
||||
var i = 0;
|
||||
socket.on('takeUtf8', function(data) {
|
||||
socket.on('takeUtf8', function (data) {
|
||||
expect(data).to.be(correct[i]);
|
||||
i++;
|
||||
if (i == correct.length) {
|
||||
if (i === correct.length) {
|
||||
socket.disconnect();
|
||||
done();
|
||||
}
|
||||
@@ -93,12 +93,12 @@ describe('connection', function() {
|
||||
socket.emit('getUtf8');
|
||||
});
|
||||
|
||||
it('should connect to a namespace after connection established', function(done) {
|
||||
it('should connect to a namespace after connection established', function (done) {
|
||||
var manager = io.Manager();
|
||||
var socket = manager.socket('/');
|
||||
socket.on('connect', function(){
|
||||
socket.on('connect', function () {
|
||||
var foo = manager.socket('/foo');
|
||||
foo.on('connect', function(){
|
||||
foo.on('connect', function () {
|
||||
foo.close();
|
||||
socket.close();
|
||||
manager.close();
|
||||
@@ -107,14 +107,14 @@ describe('connection', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should open a new namespace after connection gets closed', function(done){
|
||||
it('should open a new namespace after connection gets closed', function (done) {
|
||||
var manager = io.Manager();
|
||||
var socket = manager.socket('/');
|
||||
socket.on('connect', function() {
|
||||
socket.on('connect', function () {
|
||||
socket.disconnect();
|
||||
}).on('disconnect', function() {
|
||||
}).on('disconnect', function () {
|
||||
var foo = manager.socket('/foo');
|
||||
foo.on('connect', function() {
|
||||
foo.on('connect', function () {
|
||||
foo.disconnect();
|
||||
manager.close();
|
||||
done();
|
||||
@@ -122,24 +122,24 @@ describe('connection', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should reconnect by default', function(done){
|
||||
it('should reconnect by default', function (done) {
|
||||
var socket = io({ forceNew: true });
|
||||
socket.io.on('reconnect', function() {
|
||||
socket.io.on('reconnect', function () {
|
||||
socket.disconnect();
|
||||
done();
|
||||
});
|
||||
|
||||
setTimeout(function() {
|
||||
setTimeout(function () {
|
||||
socket.io.engine.close();
|
||||
}, 500);
|
||||
});
|
||||
|
||||
it('should reconnect manually', function(done) {
|
||||
it('should reconnect manually', function (done) {
|
||||
var socket = io({ forceNew: true });
|
||||
socket.once('connect', function() {
|
||||
socket.once('connect', function () {
|
||||
socket.disconnect();
|
||||
}).once('disconnect', function() {
|
||||
socket.once('connect', function() {
|
||||
}).once('disconnect', function () {
|
||||
socket.once('connect', function () {
|
||||
socket.disconnect();
|
||||
done();
|
||||
});
|
||||
@@ -147,33 +147,33 @@ describe('connection', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should reconnect automatically after reconnecting manually', function(done){
|
||||
it('should reconnect automatically after reconnecting manually', function (done) {
|
||||
var socket = io({ forceNew: true });
|
||||
socket.once('connect', function() {
|
||||
socket.once('connect', function () {
|
||||
socket.disconnect();
|
||||
}).once('disconnect', function() {
|
||||
socket.on('reconnect', function() {
|
||||
}).once('disconnect', function () {
|
||||
socket.on('reconnect', function () {
|
||||
socket.disconnect();
|
||||
done();
|
||||
});
|
||||
socket.connect();
|
||||
setTimeout(function() {
|
||||
setTimeout(function () {
|
||||
socket.io.engine.close();
|
||||
}, 500);
|
||||
});
|
||||
});
|
||||
|
||||
it('should attempt reconnects after a failed reconnect', function(done){
|
||||
it('should attempt reconnects after a failed reconnect', function (done) {
|
||||
var manager = io.Manager({ reconnection: true, timeout: 0, reconnectionAttempts: 2, reconnectionDelay: 10 });
|
||||
var socket = manager.socket('/timeout');
|
||||
socket.once('reconnect_failed', function() {
|
||||
socket.once('reconnect_failed', function () {
|
||||
var reconnects = 0;
|
||||
var reconnectCb = function() {
|
||||
var reconnectCb = function () {
|
||||
reconnects++;
|
||||
};
|
||||
|
||||
manager.on('reconnect_attempt', reconnectCb);
|
||||
manager.on('reconnect_failed', function failed() {
|
||||
manager.on('reconnect_failed', function failed () {
|
||||
expect(reconnects).to.be(2);
|
||||
socket.close();
|
||||
manager.close();
|
||||
@@ -183,15 +183,18 @@ describe('connection', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('reconnect delay should increase every time', function(done){
|
||||
it('reconnect delay should increase every time', function (done) {
|
||||
var manager = io.Manager({ reconnection: true, timeout: 0, reconnectionAttempts: 3, reconnectionDelay: 100, randomizationFactor: 0.2 });
|
||||
var socket = manager.socket('/timeout');
|
||||
var reconnects = 0, increasingDelay = true, startTime, prevDelay = 0;
|
||||
|
||||
socket.on('connect_error', function() {
|
||||
var reconnects = 0;
|
||||
var increasingDelay = true;
|
||||
var startTime;
|
||||
var prevDelay = 0;
|
||||
|
||||
socket.on('connect_error', function () {
|
||||
startTime = new Date().getTime();
|
||||
});
|
||||
socket.on('reconnect_attempt', function() {
|
||||
socket.on('reconnect_attempt', function () {
|
||||
reconnects++;
|
||||
var currentTime = new Date().getTime();
|
||||
var delay = currentTime - startTime;
|
||||
@@ -201,7 +204,7 @@ describe('connection', function() {
|
||||
prevDelay = delay;
|
||||
});
|
||||
|
||||
socket.on('reconnect_failed', function failed() {
|
||||
socket.on('reconnect_failed', function failed () {
|
||||
expect(reconnects).to.be(3);
|
||||
expect(increasingDelay).to.be.ok();
|
||||
socket.close();
|
||||
@@ -210,51 +213,51 @@ describe('connection', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('reconnect event should fire in socket', function(done){
|
||||
it('reconnect event should fire in socket', function (done) {
|
||||
var socket = io({ forceNew: true });
|
||||
|
||||
socket.on('reconnect', function() {
|
||||
socket.on('reconnect', function () {
|
||||
socket.disconnect();
|
||||
done();
|
||||
});
|
||||
|
||||
setTimeout(function() {
|
||||
setTimeout(function () {
|
||||
socket.io.engine.close();
|
||||
}, 500);
|
||||
});
|
||||
|
||||
it('should not reconnect when force closed', function(done){
|
||||
it('should not reconnect when force closed', function (done) {
|
||||
var socket = io('/invalid', { forceNew: true, timeout: 0, reconnectionDelay: 10 });
|
||||
socket.on('connect_error', function() {
|
||||
socket.on('reconnect_attempt', function() {
|
||||
socket.on('connect_error', function () {
|
||||
socket.on('reconnect_attempt', function () {
|
||||
expect().fail();
|
||||
});
|
||||
socket.disconnect();
|
||||
// set a timeout to let reconnection possibly fire
|
||||
setTimeout(function() {
|
||||
setTimeout(function () {
|
||||
done();
|
||||
}, 500);
|
||||
});
|
||||
});
|
||||
|
||||
it('should stop reconnecting when force closed', function(done){
|
||||
it('should stop reconnecting when force closed', function (done) {
|
||||
var socket = io('/invalid', { forceNew: true, timeout: 0, reconnectionDelay: 10 });
|
||||
socket.once('reconnect_attempt', function() {
|
||||
socket.on('reconnect_attempt', function() {
|
||||
socket.once('reconnect_attempt', function () {
|
||||
socket.on('reconnect_attempt', function () {
|
||||
expect().fail();
|
||||
});
|
||||
socket.disconnect();
|
||||
// set a timeout to let reconnection possibly fire
|
||||
setTimeout(function() {
|
||||
setTimeout(function () {
|
||||
done();
|
||||
}, 500);
|
||||
});
|
||||
});
|
||||
|
||||
it('should reconnect after stopping reconnection', function(done){
|
||||
it('should reconnect after stopping reconnection', function (done) {
|
||||
var socket = io('/invalid', { forceNew: true, timeout: 0, reconnectionDelay: 10 });
|
||||
socket.once('reconnect_attempt', function() {
|
||||
socket.on('reconnect_attempt', function() {
|
||||
socket.once('reconnect_attempt', function () {
|
||||
socket.on('reconnect_attempt', function () {
|
||||
socket.disconnect();
|
||||
done();
|
||||
});
|
||||
@@ -263,17 +266,17 @@ describe('connection', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should stop reconnecting on a socket and keep to reconnect on another', function(done){
|
||||
it('should stop reconnecting on a socket and keep to reconnect on another', function (done) {
|
||||
var manager = io.Manager();
|
||||
var socket1 = manager.socket('/');
|
||||
var socket2 = manager.socket('/asd');
|
||||
|
||||
manager.on('reconnect_attempt', function() {
|
||||
socket1.on('connect', function() {
|
||||
manager.on('reconnect_attempt', function () {
|
||||
socket1.on('connect', function () {
|
||||
expect().fail();
|
||||
});
|
||||
socket2.on('connect', function() {
|
||||
setTimeout(function() {
|
||||
socket2.on('connect', function () {
|
||||
setTimeout(function () {
|
||||
socket2.disconnect();
|
||||
manager.disconnect();
|
||||
done();
|
||||
@@ -282,22 +285,22 @@ describe('connection', function() {
|
||||
socket1.disconnect();
|
||||
});
|
||||
|
||||
setTimeout(function() {
|
||||
setTimeout(function () {
|
||||
manager.engine.close();
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
it('should try to reconnect twice and fail when requested two attempts with immediate timeout and reconnect enabled', function(done) {
|
||||
it('should try to reconnect twice and fail when requested two attempts with immediate timeout and reconnect enabled', function (done) {
|
||||
var manager = io.Manager({ reconnection: true, timeout: 0, reconnectionAttempts: 2, reconnectionDelay: 10 });
|
||||
var socket;
|
||||
|
||||
var reconnects = 0;
|
||||
var reconnectCb = function() {
|
||||
var reconnectCb = function () {
|
||||
reconnects++;
|
||||
};
|
||||
|
||||
manager.on('reconnect_attempt', reconnectCb);
|
||||
manager.on('reconnect_failed', function failed() {
|
||||
manager.on('reconnect_failed', function failed () {
|
||||
expect(reconnects).to.be(2);
|
||||
socket.close();
|
||||
manager.close();
|
||||
@@ -307,18 +310,18 @@ describe('connection', function() {
|
||||
socket = manager.socket('/timeout');
|
||||
});
|
||||
|
||||
it('should fire reconnect_* events on socket', function(done) {
|
||||
it('should fire reconnect_* events on socket', function (done) {
|
||||
var manager = io.Manager({ reconnection: true, timeout: 0, reconnectionAttempts: 2, reconnectionDelay: 10 });
|
||||
var socket = manager.socket('/timeout_socket');
|
||||
|
||||
var reconnects = 0;
|
||||
var reconnectCb = function(attempts) {
|
||||
var reconnectCb = function (attempts) {
|
||||
reconnects++;
|
||||
expect(attempts).to.be(reconnects);
|
||||
};
|
||||
|
||||
socket.on('reconnect_attempt', reconnectCb);
|
||||
socket.on('reconnect_failed', function failed() {
|
||||
socket.on('reconnect_failed', function failed () {
|
||||
expect(reconnects).to.be(2);
|
||||
socket.close();
|
||||
manager.close();
|
||||
@@ -326,34 +329,34 @@ describe('connection', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should fire error on socket', function(done) {
|
||||
it('should fire error on socket', function (done) {
|
||||
var manager = io.Manager({ reconnection: true });
|
||||
var socket = manager.socket('/timeout_socket');
|
||||
|
||||
socket.on('error', function(data) {
|
||||
socket.on('error', function (data) {
|
||||
expect(data.code).to.be('test');
|
||||
socket.close();
|
||||
manager.close();
|
||||
done();
|
||||
});
|
||||
|
||||
socket.on('connect', function() {
|
||||
socket.on('connect', function () {
|
||||
manager.engine.onPacket({ type: 'error', data: 'test' });
|
||||
});
|
||||
});
|
||||
|
||||
it('should fire reconnecting (on socket) with attempts number when reconnecting twice', function(done) {
|
||||
it('should fire reconnecting (on socket) with attempts number when reconnecting twice', function (done) {
|
||||
var manager = io.Manager({ reconnection: true, timeout: 0, reconnectionAttempts: 2, reconnectionDelay: 10 });
|
||||
var socket = manager.socket('/timeout_socket');
|
||||
|
||||
var reconnects = 0;
|
||||
var reconnectCb = function(attempts) {
|
||||
var reconnectCb = function (attempts) {
|
||||
reconnects++;
|
||||
expect(attempts).to.be(reconnects);
|
||||
};
|
||||
|
||||
socket.on('reconnecting', reconnectCb);
|
||||
socket.on('reconnect_failed', function failed() {
|
||||
socket.on('reconnect_failed', function failed () {
|
||||
expect(reconnects).to.be(2);
|
||||
socket.close();
|
||||
manager.close();
|
||||
@@ -361,18 +364,18 @@ describe('connection', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should not try to reconnect and should form a connection when connecting to correct port with default timeout', function(done) {
|
||||
it('should not try to reconnect and should form a connection when connecting to correct port with default timeout', function (done) {
|
||||
var manager = io.Manager({ reconnection: true, reconnectionDelay: 10 });
|
||||
var cb = function() {
|
||||
var cb = function () {
|
||||
socket.close();
|
||||
expect().fail();
|
||||
};
|
||||
manager.on('reconnect_attempt', cb);
|
||||
|
||||
var socket = manager.socket('/valid');
|
||||
socket.on('connect', function(){
|
||||
socket.on('connect', function () {
|
||||
// set a timeout to let reconnection possibly fire
|
||||
setTimeout(function() {
|
||||
setTimeout(function () {
|
||||
socket.close();
|
||||
manager.close();
|
||||
done();
|
||||
@@ -380,10 +383,10 @@ describe('connection', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should connect while disconnecting another socket', function(done) {
|
||||
it('should connect while disconnecting another socket', function (done) {
|
||||
var manager = io.Manager();
|
||||
var socket1 = manager.socket('/foo');
|
||||
socket1.on('connect', function() {
|
||||
socket1.on('connect', function () {
|
||||
var socket2 = manager.socket('/asd');
|
||||
socket2.on('connect', done);
|
||||
socket1.disconnect();
|
||||
@@ -393,17 +396,17 @@ describe('connection', function() {
|
||||
// Ignore incorrect connection test for old IE due to no support for
|
||||
// `script.onerror` (see: http://requirejs.org/docs/api.html#ieloadfail)
|
||||
if (!global.document || hasCORS) {
|
||||
it('should try to reconnect twice and fail when requested two attempts with incorrect address and reconnect enabled', function(done) {
|
||||
it('should try to reconnect twice and fail when requested two attempts with incorrect address and reconnect enabled', function (done) {
|
||||
var manager = io.Manager('http://localhost:3940', { reconnection: true, reconnectionAttempts: 2, reconnectionDelay: 10 });
|
||||
var socket = manager.socket('/asd');
|
||||
var reconnects = 0;
|
||||
var cb = function() {
|
||||
var cb = function () {
|
||||
reconnects++;
|
||||
};
|
||||
|
||||
manager.on('reconnect_attempt', cb);
|
||||
|
||||
manager.on('reconnect_failed', function() {
|
||||
manager.on('reconnect_failed', function () {
|
||||
expect(reconnects).to.be(2);
|
||||
socket.disconnect();
|
||||
manager.close();
|
||||
@@ -411,17 +414,17 @@ describe('connection', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should not try to reconnect with incorrect port when reconnection disabled', function(done) {
|
||||
it('should not try to reconnect with incorrect port when reconnection disabled', function (done) {
|
||||
var manager = io.Manager('http://localhost:9823', { reconnection: false });
|
||||
var cb = function() {
|
||||
var cb = function () {
|
||||
socket.close();
|
||||
expect().fail();
|
||||
};
|
||||
manager.on('reconnect_attempt', cb);
|
||||
|
||||
manager.on('connect_error', function(){
|
||||
manager.on('connect_error', function () {
|
||||
// set a timeout to let reconnection possibly fire
|
||||
setTimeout(function() {
|
||||
setTimeout(function () {
|
||||
socket.disconnect();
|
||||
manager.close();
|
||||
done();
|
||||
@@ -432,9 +435,9 @@ describe('connection', function() {
|
||||
});
|
||||
}
|
||||
|
||||
it('should emit date as string', function(done){
|
||||
it('should emit date as string', function (done) {
|
||||
var socket = io({ forceNew: true });
|
||||
socket.on('takeDate', function(data) {
|
||||
socket.on('takeDate', function (data) {
|
||||
socket.close();
|
||||
expect(data).to.be.a('string');
|
||||
done();
|
||||
@@ -442,9 +445,9 @@ describe('connection', function() {
|
||||
socket.emit('getDate');
|
||||
});
|
||||
|
||||
it('should emit date in object', function(done){
|
||||
it('should emit date in object', function (done) {
|
||||
var socket = io({ forceNew: true });
|
||||
socket.on('takeDateObj', function(data) {
|
||||
socket.on('takeDateObj', function (data) {
|
||||
socket.close();
|
||||
expect(data).to.be.an('object');
|
||||
expect(data.date).to.be.a('string');
|
||||
@@ -454,9 +457,9 @@ describe('connection', function() {
|
||||
});
|
||||
|
||||
if (!global.Blob && !global.ArrayBuffer) {
|
||||
it('should get base64 data as a last resort', function(done) {
|
||||
it('should get base64 data as a last resort', function (done) {
|
||||
var socket = io({ forceNew: true });
|
||||
socket.on('takebin', function(a) {
|
||||
socket.on('takebin', function (a) {
|
||||
socket.disconnect();
|
||||
expect(a.base64).to.be(true);
|
||||
expect(a.data).to.eql('YXNkZmFzZGY=');
|
||||
@@ -469,22 +472,22 @@ describe('connection', function() {
|
||||
if (global.ArrayBuffer) {
|
||||
var base64 = require('base64-arraybuffer');
|
||||
|
||||
it('should get binary data (as an ArrayBuffer)', function(done){
|
||||
it('should get binary data (as an ArrayBuffer)', function (done) {
|
||||
var socket = io({ forceNew: true });
|
||||
if (env.node) {
|
||||
socket.io.engine.binaryType = 'arraybuffer';
|
||||
}
|
||||
socket.emit('doge');
|
||||
socket.on('doge', function(buffer){
|
||||
socket.on('doge', function (buffer) {
|
||||
expect(buffer instanceof ArrayBuffer).to.be(true);
|
||||
socket.disconnect();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should send binary data (as an ArrayBuffer)', function(done){
|
||||
it('should send binary data (as an ArrayBuffer)', function (done) {
|
||||
var socket = io({ forceNew: true });
|
||||
socket.on('buffack', function(){
|
||||
socket.on('buffack', function () {
|
||||
socket.disconnect();
|
||||
done();
|
||||
});
|
||||
@@ -492,9 +495,9 @@ describe('connection', function() {
|
||||
socket.emit('buffa', buf);
|
||||
});
|
||||
|
||||
it('should send binary data (as an ArrayBuffer) mixed with json', function(done) {
|
||||
it('should send binary data (as an ArrayBuffer) mixed with json', function (done) {
|
||||
var socket = io({ forceNew: true });
|
||||
socket.on('jsonbuff-ack', function() {
|
||||
socket.on('jsonbuff-ack', function () {
|
||||
socket.disconnect();
|
||||
done();
|
||||
});
|
||||
@@ -502,9 +505,9 @@ describe('connection', function() {
|
||||
socket.emit('jsonbuff', {hello: 'lol', message: buf, goodbye: 'gotcha'});
|
||||
});
|
||||
|
||||
it('should send events with ArrayBuffers in the correct order', function(done) {
|
||||
it('should send events with ArrayBuffers in the correct order', function (done) {
|
||||
var socket = io({ forceNew: true });
|
||||
socket.on('abuff2-ack', function() {
|
||||
socket.on('abuff2-ack', function () {
|
||||
socket.disconnect();
|
||||
done();
|
||||
});
|
||||
@@ -515,9 +518,9 @@ describe('connection', function() {
|
||||
}
|
||||
|
||||
if (global.Blob && null != textBlobBuilder('xxx')) {
|
||||
it('should send binary data (as a Blob)', function(done){
|
||||
it('should send binary data (as a Blob)', function (done) {
|
||||
var socket = io({ forceNew: true });
|
||||
socket.on('back', function(){
|
||||
socket.on('back', function () {
|
||||
socket.disconnect();
|
||||
done();
|
||||
});
|
||||
@@ -525,9 +528,9 @@ describe('connection', function() {
|
||||
socket.emit('blob', blob);
|
||||
});
|
||||
|
||||
it('should send binary data (as a Blob) mixed with json', function(done) {
|
||||
it('should send binary data (as a Blob) mixed with json', function (done) {
|
||||
var socket = io({ forceNew: true });
|
||||
socket.on('jsonblob-ack', function() {
|
||||
socket.on('jsonblob-ack', function () {
|
||||
socket.disconnect();
|
||||
done();
|
||||
});
|
||||
@@ -535,9 +538,9 @@ describe('connection', function() {
|
||||
socket.emit('jsonblob', {hello: 'lol', message: blob, goodbye: 'gotcha'});
|
||||
});
|
||||
|
||||
it('should send events with Blobs in the correct order', function(done) {
|
||||
it('should send events with Blobs in the correct order', function (done) {
|
||||
var socket = io({ forceNew: true });
|
||||
socket.on('blob3-ack', function() {
|
||||
socket.on('blob3-ack', function () {
|
||||
socket.disconnect();
|
||||
done();
|
||||
});
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
var expect = require('expect.js');
|
||||
var io = require('../');
|
||||
|
||||
describe('socket', function(){
|
||||
describe('socket', function () {
|
||||
this.timeout(70000);
|
||||
|
||||
it('should have an accessible socket id equal to the engine.io socket id', function(done) {
|
||||
it('should have an accessible socket id equal to the engine.io socket id', function (done) {
|
||||
var socket = io({ forceNew: true });
|
||||
socket.on('connect', function(){
|
||||
socket.on('connect', function () {
|
||||
expect(socket.id).to.be.ok();
|
||||
expect(socket.id).to.eql(socket.io.engine.id);
|
||||
socket.disconnect();
|
||||
@@ -14,10 +14,10 @@ describe('socket', function(){
|
||||
});
|
||||
});
|
||||
|
||||
it('clears socket.id upon disconnection', function(done){
|
||||
it('clears socket.id upon disconnection', function (done) {
|
||||
var socket = io({ forceNew: true });
|
||||
socket.on('connect', function(){
|
||||
socket.on('disconnect', function(){
|
||||
socket.on('connect', function () {
|
||||
socket.on('disconnect', function () {
|
||||
expect(socket.id).to.not.be.ok();
|
||||
done();
|
||||
});
|
||||
@@ -26,25 +26,25 @@ describe('socket', function(){
|
||||
});
|
||||
});
|
||||
|
||||
it('doesn\'t fire a connect_error if we force disconnect in opening state', function(done){
|
||||
it('doesn\'t fire a connect_error if we force disconnect in opening state', function (done) {
|
||||
var socket = io({ forceNew: true, timeout: 100 });
|
||||
socket.disconnect();
|
||||
socket.on('connect_error', function(){
|
||||
socket.on('connect_error', function () {
|
||||
throw new Error('Unexpected');
|
||||
});
|
||||
setTimeout(function(){
|
||||
setTimeout(function () {
|
||||
done();
|
||||
}, 300);
|
||||
});
|
||||
|
||||
it('should ping and pong with latency', function(done){
|
||||
it('should ping and pong with latency', function (done) {
|
||||
var socket = io({ forceNew: true });
|
||||
socket.on('connect', function(){
|
||||
socket.on('connect', function () {
|
||||
var pinged;
|
||||
socket.once('ping', function(){
|
||||
socket.once('ping', function () {
|
||||
pinged = true;
|
||||
});
|
||||
socket.once('pong', function(ms){
|
||||
socket.once('pong', function (ms) {
|
||||
expect(pinged).to.be(true);
|
||||
expect(ms).to.be.a('number');
|
||||
socket.disconnect();
|
||||
@@ -53,16 +53,16 @@ describe('socket', function(){
|
||||
});
|
||||
});
|
||||
|
||||
it('should change socket.id upon reconnection', function(done){
|
||||
it('should change socket.id upon reconnection', function (done) {
|
||||
var socket = io({ forceNew: true });
|
||||
socket.on('connect', function(){
|
||||
socket.on('connect', function () {
|
||||
var id = socket.id;
|
||||
|
||||
socket.on('reconnect_attempt', function(){
|
||||
socket.on('reconnect_attempt', function () {
|
||||
expect(socket.id).to.not.be.ok();
|
||||
});
|
||||
|
||||
socket.on('reconnect', function() {
|
||||
socket.on('reconnect', function () {
|
||||
expect(socket.id).to.not.eql(id);
|
||||
socket.disconnect();
|
||||
done();
|
||||
@@ -72,10 +72,10 @@ describe('socket', function(){
|
||||
});
|
||||
});
|
||||
|
||||
it('should enable compression by default', function(done){
|
||||
it('should enable compression by default', function (done) {
|
||||
var socket = io({ forceNew: true });
|
||||
socket.on('connect', function(){
|
||||
socket.io.engine.once('packetCreate', function(packet){
|
||||
socket.on('connect', function () {
|
||||
socket.io.engine.once('packetCreate', function (packet) {
|
||||
expect(packet.options.compress).to.be(true);
|
||||
socket.disconnect();
|
||||
done();
|
||||
@@ -84,10 +84,10 @@ describe('socket', function(){
|
||||
});
|
||||
});
|
||||
|
||||
it('should disable compression', function(done){
|
||||
it('should disable compression', function (done) {
|
||||
var socket = io({ forceNew: true });
|
||||
socket.on('connect', function(){
|
||||
socket.io.engine.once('packetCreate', function(packet){
|
||||
socket.on('connect', function () {
|
||||
socket.io.engine.once('packetCreate', function (packet) {
|
||||
expect(packet.options.compress).to.be(false);
|
||||
socket.disconnect();
|
||||
done();
|
||||
@@ -96,10 +96,10 @@ describe('socket', function(){
|
||||
});
|
||||
});
|
||||
|
||||
it('should store query string as a property', function(done){
|
||||
var socket = io('/abc', {query: {a:'b'}}); //passes in as a query obj
|
||||
var socket2 = io('/abcd?b=c&d=e'); //passes in as a query string
|
||||
var socket3 = io('/abc', {query: {'&a':'&=?a'}}); //checks that it encodes a string.
|
||||
it('should store query string as a property', function (done) {
|
||||
var socket = io('/abc', {query: {a: 'b'}}); // passes in as a query obj
|
||||
var socket2 = io('/abcd?b=c&d=e'); // passes in as a query string
|
||||
var socket3 = io('/abc', {query: {'&a': '&=?a'}}); // checks that it encodes a string
|
||||
expect(socket.query).to.be('a=b');
|
||||
expect(socket2.query).to.be('b=c&d=e');
|
||||
expect(socket3.query).to.be('%26a=%26%3D%3Fa');
|
||||
|
||||
@@ -5,50 +5,50 @@ var io = require('socket.io');
|
||||
var server = io(process.env.ZUUL_PORT || 3210, { pingInterval: 2000 });
|
||||
var expect = require('expect.js');
|
||||
|
||||
server.of('/foo').on('connection', function(){
|
||||
server.of('/foo').on('connection', function () {
|
||||
// register namespace
|
||||
});
|
||||
|
||||
server.of('/timeout_socket').on('connection', function(){
|
||||
server.of('/timeout_socket').on('connection', function () {
|
||||
// register namespace
|
||||
});
|
||||
|
||||
server.of('/valid').on('connection', function(){
|
||||
server.of('/valid').on('connection', function () {
|
||||
// register namespace
|
||||
});
|
||||
|
||||
server.of('/asd').on('connection', function(){
|
||||
server.of('/asd').on('connection', function () {
|
||||
// register namespace
|
||||
});
|
||||
|
||||
server.on('connection', function(socket){
|
||||
server.on('connection', function (socket) {
|
||||
// simple test
|
||||
socket.on('hi', function(){
|
||||
socket.on('hi', function () {
|
||||
socket.emit('hi');
|
||||
});
|
||||
|
||||
// ack tests
|
||||
socket.on('ack', function(){
|
||||
socket.emit('ack', function(a, b){
|
||||
if (a == 5 && b.test) {
|
||||
socket.on('ack', function () {
|
||||
socket.emit('ack', function (a, b) {
|
||||
if (a === 5 && b.test) {
|
||||
socket.emit('got it');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('getAckDate', function(data, cb){
|
||||
socket.on('getAckDate', function (data, cb) {
|
||||
cb(new Date());
|
||||
});
|
||||
|
||||
socket.on('getDate', function(){
|
||||
socket.on('getDate', function () {
|
||||
socket.emit('takeDate', new Date());
|
||||
});
|
||||
|
||||
socket.on('getDateObj', function(){
|
||||
socket.on('getDateObj', function () {
|
||||
socket.emit('takeDateObj', { date: new Date() });
|
||||
});
|
||||
|
||||
socket.on('getUtf8', function() {
|
||||
socket.on('getUtf8', function () {
|
||||
socket.emit('takeUtf8', 'てすと');
|
||||
socket.emit('takeUtf8', 'Я Б Г Д Ж Й');
|
||||
socket.emit('takeUtf8', 'Ä ä Ü ü ß');
|
||||
@@ -57,23 +57,23 @@ server.on('connection', function(socket){
|
||||
});
|
||||
|
||||
// false test
|
||||
socket.on('false', function(){
|
||||
socket.on('false', function () {
|
||||
socket.emit('false', false);
|
||||
});
|
||||
|
||||
// binary test
|
||||
socket.on('doge', function(){
|
||||
socket.on('doge', function () {
|
||||
var buf = new Buffer('asdfasdf', 'utf8');
|
||||
socket.emit('doge', buf);
|
||||
});
|
||||
|
||||
// expect receiving binary to be buffer
|
||||
socket.on('buffa', function(a){
|
||||
socket.on('buffa', function (a) {
|
||||
if (Buffer.isBuffer(a)) socket.emit('buffack');
|
||||
});
|
||||
|
||||
// expect receiving binary with mixed JSON
|
||||
socket.on('jsonbuff', function(a) {
|
||||
socket.on('jsonbuff', function (a) {
|
||||
expect(a.hello).to.eql('lol');
|
||||
expect(Buffer.isBuffer(a.message)).to.be(true);
|
||||
expect(a.goodbye).to.eql('gotcha');
|
||||
@@ -82,22 +82,22 @@ server.on('connection', function(socket){
|
||||
|
||||
// expect receiving buffers in order
|
||||
var receivedAbuff1 = false;
|
||||
socket.on('abuff1', function(a) {
|
||||
socket.on('abuff1', function (a) {
|
||||
expect(Buffer.isBuffer(a)).to.be(true);
|
||||
receivedAbuff1 = true;
|
||||
});
|
||||
socket.on('abuff2', function(a) {
|
||||
socket.on('abuff2', function (a) {
|
||||
expect(receivedAbuff1).to.be(true);
|
||||
socket.emit('abuff2-ack');
|
||||
});
|
||||
|
||||
// expect sent blob to be buffer
|
||||
socket.on('blob', function(a){
|
||||
socket.on('blob', function (a) {
|
||||
if (Buffer.isBuffer(a)) socket.emit('back');
|
||||
});
|
||||
|
||||
// expect sent blob mixed with json to be buffer
|
||||
socket.on('jsonblob', function(a) {
|
||||
socket.on('jsonblob', function (a) {
|
||||
expect(a.hello).to.eql('lol');
|
||||
expect(Buffer.isBuffer(a.message)).to.be(true);
|
||||
expect(a.goodbye).to.eql('gotcha');
|
||||
@@ -107,16 +107,16 @@ server.on('connection', function(socket){
|
||||
// expect blobs sent in order to arrive in correct order
|
||||
var receivedblob1 = false;
|
||||
var receivedblob2 = false;
|
||||
socket.on('blob1', function(a) {
|
||||
socket.on('blob1', function (a) {
|
||||
expect(Buffer.isBuffer(a)).to.be(true);
|
||||
receivedblob1 = true;
|
||||
});
|
||||
socket.on('blob2', function(a) {
|
||||
socket.on('blob2', function (a) {
|
||||
expect(receivedblob1).to.be(true);
|
||||
expect(a).to.eql('second');
|
||||
receivedblob2 = true;
|
||||
});
|
||||
socket.on('blob3', function(a) {
|
||||
socket.on('blob3', function (a) {
|
||||
expect(Buffer.isBuffer(a)).to.be(true);
|
||||
expect(receivedblob1).to.be(true);
|
||||
expect(receivedblob2).to.be(true);
|
||||
@@ -124,7 +124,7 @@ server.on('connection', function(socket){
|
||||
});
|
||||
|
||||
// emit buffer to base64 receiving browsers
|
||||
socket.on('getbin', function() {
|
||||
socket.on('getbin', function () {
|
||||
var buf = new Buffer('asdfasdf', 'utf8');
|
||||
socket.emit('takebin', buf);
|
||||
});
|
||||
|
||||
19
test/url.js
19
test/url.js
@@ -3,9 +3,8 @@ var loc = {};
|
||||
var url = require('../lib/url');
|
||||
var expect = require('expect.js');
|
||||
|
||||
describe('url', function(){
|
||||
|
||||
it('works with undefined', function(){
|
||||
describe('url', function () {
|
||||
it('works with undefined', function () {
|
||||
loc.hostname = 'woot.com';
|
||||
loc.protocol = 'https:';
|
||||
loc.port = 4005;
|
||||
@@ -16,7 +15,7 @@ describe('url', function(){
|
||||
expect(parsed.port).to.be('4005');
|
||||
});
|
||||
|
||||
it('works with relative paths', function(){
|
||||
it('works with relative paths', function () {
|
||||
loc.hostname = 'woot.com';
|
||||
loc.protocol = 'https:';
|
||||
loc.port = 3000;
|
||||
@@ -27,7 +26,7 @@ describe('url', function(){
|
||||
expect(parsed.port).to.be('3000');
|
||||
});
|
||||
|
||||
it('works with no protocol', function(){
|
||||
it('works with no protocol', function () {
|
||||
loc.protocol = 'http:';
|
||||
var parsed = url('localhost:3000', loc);
|
||||
expect(parsed.host).to.be('localhost');
|
||||
@@ -35,7 +34,7 @@ describe('url', function(){
|
||||
expect(parsed.protocol).to.be('http');
|
||||
});
|
||||
|
||||
it('works with no schema', function(){
|
||||
it('works with no schema', function () {
|
||||
loc.protocol = 'http:';
|
||||
var parsed = url('//localhost:3000', loc);
|
||||
expect(parsed.host).to.be('localhost');
|
||||
@@ -43,7 +42,7 @@ describe('url', function(){
|
||||
expect(parsed.protocol).to.be('http');
|
||||
});
|
||||
|
||||
it('forces ports for unique url ids', function(){
|
||||
it('forces ports for unique url ids', function () {
|
||||
var id1 = url('http://google.com:80/');
|
||||
var id2 = url('http://google.com/');
|
||||
var id3 = url('https://google.com/');
|
||||
@@ -52,7 +51,7 @@ describe('url', function(){
|
||||
expect(id2.id).to.not.be(id3.id);
|
||||
});
|
||||
|
||||
it('identifies the namespace', function(){
|
||||
it('identifies the namespace', function () {
|
||||
loc.protocol = 'http:';
|
||||
loc.hostname = 'woot.com';
|
||||
|
||||
@@ -61,7 +60,7 @@ describe('url', function(){
|
||||
expect(url('http://google.com/').path).to.be('/');
|
||||
});
|
||||
|
||||
it('works with ipv6', function(){
|
||||
it('works with ipv6', function () {
|
||||
var parsed = url('http://[::1]');
|
||||
expect(parsed.protocol).to.be('http');
|
||||
expect(parsed.host).to.be('::1');
|
||||
@@ -69,7 +68,7 @@ describe('url', function(){
|
||||
expect(parsed.id).to.be('http://[::1]:80');
|
||||
});
|
||||
|
||||
it('works with ipv6 location', function(){
|
||||
it('works with ipv6 location', function () {
|
||||
loc.protocol = 'http:';
|
||||
loc.hostname = '[::1]';
|
||||
loc.port = '';
|
||||
|
||||
Reference in New Issue
Block a user