Permalink
Browse files

Merge pull request #224 from 3rd-Eden/of

Added test suite + of method on the namespace so we have a simular api on
  • Loading branch information...
2 parents c274187 + 31a89ac commit e8c50dbd5ed6f26f3c55ca26c40c95ff91dec41b @rauchg rauchg committed Jul 12, 2011
Showing with 68 additions and 0 deletions.
  1. +11 −0 lib/namespace.js
  2. +12 −0 support/test-runner/app.js
  3. +45 −0 test/socket.test.js
View
@@ -42,6 +42,17 @@
SocketNamespace.prototype.$emit = io.EventEmitter.prototype.emit;
+ /**
+ * Creates a new namespace, by proxying the request to the socket. This
+ * allows us to use the synax as we do on the server.
+ *
+ * @api public
+ */
+
+ SocketNamespace.prototype.of = function () {
+ return this.socket.of.apply(this.socket, arguments);
+ };
+
/**
* Sends a packet.
*
View
@@ -179,6 +179,18 @@ suite('socket.test.js', function () {
});
});
+ server('test different namespace connection methods', function (io) {
+ io.of('/a').on('connection', function (socket) {
+ socket.send('a');
+ });
+ io.of('/b').on('connection', function (socket) {
+ socket.send('b');
+ });
+ io.of('/c').on('connection', function (socket) {
+ socket.send('c');
+ });
+ });
+
server('test disconnecting from namespaces', function (io) {
io.of('/a').on('connection', function (socket) {});
io.of('/b').on('connection', function (socket) {});
View
@@ -137,6 +137,51 @@
},
+ 'test different namespace connection methods': function (next) {
+ var io = create('/a')
+ , connect = 0
+ , message = 0
+ , socket = io.socket;
+
+ function finish () {
+ socket.of('').disconnect();
+ connect.should().equal(3);
+ message.should().equal(3);
+ next();
+ }
+
+ io.on('connect', function () {
+ ++connect;
+ }).on('message', function (data) {
+ data.should().eql('a');
+
+ if (++message === 3) finish();
+ }).on('error', function (msg) {
+ throw new Error(msg || 'Received an error');
+ });
+
+ socket.of('/b').on('connect', function () {
+ ++connect;
+ }).on('message', function (data) {
+ data.should().eql('b');
+
+ if (++message === 3) finish();
+ }).on('error', function (msg) {
+ throw new Error(msg || 'Received an error');
+ });
+
+ io.of('/c').on('connect', function () {
+ ++connect;
+ }).on('message', function (data) {
+ data.should().eql('c');
+
+ if (++message === 3) finish();
+ }).on('error', function (msg) {
+ throw new Error(msg || 'Received an error');
+ });
+
+ },
+
'test disconnecting from namespaces': function (next) {
var socket = create().socket
, namespaces = 2

0 comments on commit e8c50db

Please sign in to comment.