<commit_before>
/*!
 * socket.io-node
 * Copyright(c) 2011 LearnBoost <<EMAIL>>
 * MIT Licensed
 */

(function (module, io, should) {

  if ('object' == typeof global) {
    return module.exports = { '': function () {} };
  }

  module.exports = {

    'test connecting the socket and disconnecting': function (next) {
      var socket = create();
      socket.on('connect', function () {
        socket.disconnect();
        next();
      });
    },

    'test receiving messages': function (next) {
      var socket = create()
        , connected = false
        , messages = 0;

      socket.on('connect', function () {
        connected = true;
      });

      socket.on('message', function (i) {
        String(++messages).should().equal(i);
      });

      socket.on('disconnect', function (reason) {
        connected.should().be_true;
        messages.should().equal(3);
        reason.should().eql('booted');
        next();
      });
    },

    'test sending messages': function (next) {
      var socket = create();

      socket.on('connect', function () {
        socket.send('echo');

        socket.on('message', function (msg) {
          msg.should().equal('echo');
          socket.disconnect();
          next();
        });
      });
    },

    'test acks sent from client': function (next) {
      var socket = create();

      socket.on('connect', function () {
        socket.on('message', function (msg) {
          if ('tobi 2' == msg) {
            socket.disconnect();
            next();
          }
        });
      });
    },

    'test acks sent from server': function (next) {
      var socket = create();

      socket.on('connect', function () {
        socket.send('ooo', function () {
          socket.disconnect();
          next();
        });
      });
    },

    'test connecting to namespaces': function (next) {
      var socket = create().socket
        , namespaces = 2;

      function finish () {
        socket.of('').disconnect();
        next();
      }

      socket.of('/woot').on('message', function (msg) {
        msg.should().equal('connected to woot');
        --namespaces || finish();
      });

      socket.of('/chat').on('message', function (msg) {
        msg.should().equal('connected to chat');
        --namespaces || finish();
      });
    },

    'test disconnecting from namespaces': function (next) {
      var socket = create().socket
        , namespaces = 2
        , disconnections = 0;

      function finish () {
        socket.of('').disconnect();
        next();
      };

      socket.of('/a').on('connect', function () {
        socket.of('/a').disconnect();
      });

      socket.of('/a').on('disconnect', function () {
        --namespaces || finish();
      });

      socket.of('/b').on('connect', function () {
        socket.of('/b').disconnect();
      });

      socket.of('/b').on('disconnect', function () {
        --namespaces || finish();
      });
    },

    'test sending json from server': function (next) {
      var socket = create();

      socket.on('message', function (msg) {
        msg.should().eql(3141592);
        socket.disconnect();
        next();
      });
    },

    'test sending json from client': function (next) {
      var socket = create();

      socket.json.send([1, 2, 3]);
      socket.on('message', function (msg) {
        msg.should().equal('echo');
        socket.disconnect();
        next();
      });
    },

    'test emitting an event from server': function (next) {
      var socket = create();

      socket.on('woot', function () {
        socket.disconnect();
        next();
      });
    },

    'test emitting an event to server': function (next) {
      var socket = create();

      socket.emit('woot');
      socket.on('echo', function () {
        socket.disconnect();
        next();
      })
    },

    'test emitting an event from server and sending back data': function (next) {
      var socket = create();

      socket.on('woot', function (a, fn) {
        a.should().eql(1);
        fn('test');

        socket.on('done', function () {
          socket.disconnect();
          next();
        });
      });
    },

    'test emitting an event to server and sending back data': function (next) {
      var socket = create();

      socket.emit('tobi', 1, 2, function (a) {
        a.should().eql({ hello: 'world' });
        socket.disconnect();
        next();
      });
    }

  };

})(
    'undefined' == typeof module ? module = {} : module
  , 'undefined' == typeof io ? require('socket.io-client') : io
  , 'undefined' == typeof should ? require('should-browser') : should<commit_msg>Added `on("error")` checks to each test case, none of these test should emit an error event<commit_after>
/*!
 * socket.io-node
 * Copyright(c) 2011 LearnBoost <<EMAIL>>
 * MIT Licensed
 */

(function (module, io, should) {

  if ('object' == typeof global) {
    return module.exports = { '': function () {} };
  }

  module.exports = {

    'test connecting the socket and disconnecting': function (next) {
      var socket = create();

      socket.on('error', function (msg) {
        throw new Error(msg || 'Received an error');
      });

      socket.on('connect', function () {
        socket.disconnect();
        next();
      });
    },

    'test receiving messages': function (next) {
      var socket = create()
        , connected = false
        , messages = 0;

      socket.on('error', function (msg) {
        throw new Error(msg || 'Received an error');
      });

      socket.on('connect', function () {
        connected = true;
      });

      socket.on('message', function (i) {
        String(++messages).should().equal(i);
      });

      socket.on('disconnect', function (reason) {
        connected.should().be_true;
        messages.should().equal(3);
        reason.should().eql('booted');
        next();
      });
    },

    'test sending messages': function (next) {
      var socket = create();

      socket.on('error', function (msg) {
        throw new Error(msg || 'Received an error');
      });

      socket.on('connect', function () {
        socket.send('echo');

        socket.on('message', function (msg) {
          msg.should().equal('echo');
          socket.disconnect();
          next();
        });
      });
    },

    'test acks sent from client': function (next) {
      var socket = create();

      socket.on('error', function (msg) {
        throw new Error(msg || 'Received an error');
      });

      socket.on('connect', function () {
        socket.on('message', function (msg) {
          if ('tobi 2' == msg) {
            socket.disconnect();
            next();
          }
        });
      });
    },

    'test acks sent from server': function (next) {
      var socket = create();

      socket.on('error', function (msg) {
        throw new Error(msg || 'Received an error');
      });

      socket.on('connect', function () {
        socket.send('ooo', function () {
          socket.disconnect();
          next();
        });
      });
    },

    'test connecting to namespaces': function (next) {
      var socket = create().socket
        , namespaces = 2;

      function finish () {
        socket.of('').disconnect();
        next();
      }

      socket.of('/woot').on('error', function (msg) {
        throw new Error(msg || 'Received an error');
      });

      socket.of('/chat').on('error', function (msg) {
        throw new Error(msg || 'Received an error');
      });

      socket.of('/woot').on('message', function (msg) {
        msg.should().equal('connected to woot');
        --namespaces || finish();
      });

      socket.of('/chat').on('message', function (msg) {
        msg.should().equal('connected to chat');
        --namespaces || finish();
      });
    },

    'test disconnecting from namespaces': function (next) {
      var socket = create().socket
        , namespaces = 2
        , disconnections = 0;

      function finish () {
        socket.of('').disconnect();
        next();
      };

      socket.of('/a').on('error', function (msg) {
        throw new Error(msg || 'Received an error');
      });

      socket.of('/a').on('connect', function () {
        socket.of('/a').disconnect();
      });

      socket.of('/a').on('disconnect', function () {
        --namespaces || finish();
      });

      socket.of('/b').on('error', function (msg) {
        throw new Error(msg || 'Received an error');
      });

      socket.of('/b').on('connect', function () {
        socket.of('/b').disconnect();
      });

      socket.of('/b').on('disconnect', function () {
        --namespaces || finish();
      });
    },

    'test sending json from server': function (next) {
      var socket = create();

      socket.on('error', function (msg) {
        throw new Error(msg || 'Received an error');
      });

      socket.on('message', function (msg) {
        msg.should().eql(3141592);
        socket.disconnect();
        next();
      });
    },

    'test sending json from client': function (next) {
      var socket = create();

      socket.on('error', function (msg) {
        throw new Error(msg || 'Received an error');
      });

      socket.json.send([1, 2, 3]);
      socket.on('message', function (msg) {
        msg.should().equal('echo');
        socket.disconnect();
        next();
      });
    },

    'test emitting an event from server': function (next) {
      var socket = create();

      socket.on('error', function (msg) {
        throw new Error(msg || 'Received an error');
      });

      socket.on('woot', function () {
        socket.disconnect();
        next();
      });
    },

    'test emitting an event to server': function (next) {
      var socket = create();

      socket.on('error', function (msg) {
        throw new Error(msg || 'Received an error');
      });

      socket.emit('woot');
      socket.on('echo', function () {
        socket.disconnect();
        next();
      })
    },

    'test emitting an event from server and sending back data': function (next) {
      var socket = create();

      socket.on('error', function (msg) {
        throw new Error(msg || 'Received an error');
      });

      socket.on('woot', function (a, fn) {
        a.should().eql(1);
        fn('test');

        socket.on('done', function () {
          socket.disconnect();
          next();
        });
      });
    },

    'test emitting an event to server and sending back data': function (next) {
      var socket = create();

      socket.on('error', function (msg) {
        throw new Error(msg || 'Received an error');
      });

      socket.emit('tobi', 1, 2, function (a) {
        a.should().eql({ hello: 'world' });
        socket.disconnect();
        next();
      });
    }

  };

})(
    'undefined' == typeof module ? module = {} : module
  , 'undefined' == typeof io ? require('socket.io-client') : io
  , 'undefined' == typeof should ? require('should-browser') : should
{'fraction_non_alphanumeric': 0.17791299609481429, 'fraction_numerical': 0.004177640541276905, 'mean_word_length': 1.9818575683725967, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5245008', 'n_tokens_mistral': 3190, 'n_tokens_neox': 3043, 'n_words': 767}