Skip to content

Instantly share code, notes, and snippets.

@asyncanup
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asyncanup/271d7c696564e0b89c85 to your computer and use it in GitHub Desktop.
Save asyncanup/271d7c696564e0b89c85 to your computer and use it in GitHub Desktop.
Namespace bug in Socket.io 1.x
var assert = require('assert'),
http = require('http'),
sockets = require('socket.io'),
socketClient = require('socket.io-client');
describe('Socket.io', function () {
it('should take / as the default namespace', function (done) {
var port = 5001,
io = sockets.listen(port);
socketClient('http://localhost:' + port);
io.of('/').on('connection', function () {
done();
});
});
it('should treat empty string namespace as the default / namespace', function (done) {
var port = 5002,
io = sockets.listen(port);
socketClient('http://localhost:' + port);
io.of('').on('connection', function () {
done();
});
});
});
function handler(req, res) {
res.writeHead(200);
res.end("Woot!");
}

Socket.io Namespace Bug

Description

Socket.io treats / as its default namespace, and should treat empty string provided as namespace just the same.

That used to be the case earlier (seen before 1.x), but does not work as such anymore as shown in the included test (socket-io-namespace-bug.js)

In response to

Twitter conversation with @SocketIO

Reproduce

npm install -g mocha
npm install socket.io socket.io-client

mocha socket-io-namespace-bug.js

Output

  Socket.io
    ✓ should take / as the default namespace 
    1) should treat empty string namespace as the default / namespace


  1 passing (2s)
  1 failing

  1) Socket.io should treat empty string namespace as the default / namespace:
     Error: timeout of 2000ms exceeded
      at null.<anonymous> (/home/ubuntu/.nvm/v0.10.28/lib/node_modules/mocha/lib/runnable.js:157:19)
      at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment