<commit_before>require("util").inherits(module, require("./../../core/integration_test"));
ClientTest = module.exports = function() { 
  var http = require("http")
    , player = require("./../lib/player")
    , WebSocket = require("node-websocket-client/lib/websocket").WebSocket

    , join_message = function(name) { return { action: "join", data: { name: ((name) ? name :  "anonymous") } } }
    , move_message = function(from, to) { return { action: "pos", data: { f: from, t: to } } };

  return {
    // async tests do not work yet, but can be verified via the log files
    can_fetch_index: function() {
      var client_http = http.createClient(8124)
        , request = client_http.request("GET", "/");

      var assertion = gourdian.curriedRequestOn(request, function(response) {
        assert.equal(response.statusCode, 200);
      });

      request.end();

      return assertion;

    }, can_connect_via_websocket: function() {
      var client_sock = new WebSocket("ws://127.0.0.1:8124/socket.io/websocket", "borf");

      client_sock.addListener('data', function(buf) {
        assert.notEqual(buf.length, 0);
      });

    }, can_join_a_game: function() {
      var client_sock = new WebSocket("ws://127.0.0.1:8124/socket.io/websocket", "borf")
        , message_sent = false
        , message = { action: "join", data: { name: "anonymous" } }
        , receipt = { hold: 1};

      client_sock.onopen = function() { socket_send(client_sock, "j", message) };

      client_sock.onmessage = function(m) {
        var obj = message_parse(m);
        if (obj.hold) {
          assert.deepEqual(obj, receipt);
        }
      }

    }, two_clients_make_a_game: function() {
      var client_sock = new WebSocket("ws://127.0.0.1:8124/socket.io/websocket", "borf")
        , client_sock2 = new WebSocket("ws://127.0.0.1:8124/socket.io/websocket", "borf");

      client_sock.onopen = function() { socket_send(client_sock, "j", join_message()) };
      client_sock2.onopen = function() { socket_send(client_sock2, "j", join_message()) };

    }, player_assigned_white_can_move: function() {
      var client_sock = new WebSocket("ws://127.0.0.1:8124/socket.io/websocket", "borf")
        , client_sock2 = new WebSocket("ws://127.0.0.1:8124/socket.io/websocket", "borf");

      // join
      client_sock.onopen = function() { socket_send(client_sock, "j", join_message()) };<commit_msg>fixed some async tests<commit_after>require("util").inherits(module, require("./../../core/integration_test"));
ClientTest = module.exports = function() { 
  var http = require("http")
    , player = require("./../lib/player")
    , WebSocket = require("node-websocket-client/lib/websocket").WebSocket

    , join_message = function(name) { return { action: "join", data: { name: ((name) ? name :  "anonymous") } } }
    , move_message = function(from, to) { return { action: "pos", data: { f: from, t: to } } };

  return {
    can_fetch_index: function() {
      var client_http = http.createClient(8124)
        , request = client_http.request("GET", "/");

      var assertion = gourdian.curriedRequestOn(request, function(response) {
        assert.equal(response.statusCode, 200);
      });

      request.end();

      return assertion;

    }, can_connect_via_websocket: function() {
      var client = new WebSocket("ws://127.0.0.1:8124/socket.io/websocket", "borf");

      return gourdian.curriedWebsocketAddListener(client, function(buffer) {
        assert.notEqual(buffer.length, 0);
      });

    // async tests beyond this point do not work yet, but can be verified via the log files
    }, first_player_to_join_gets_a_hold_message: function() {
      var client = new WebSocket("ws://127.0.0.1:8124/socket.io/websocket", "borf")
        , message = { action: "join", data: { name: "anonymous" } }
        , receipt = { hold: 1};

      client.onopen = function() { socket_send(client_sock, "j", message) };

      return gourdian.curriedWebsocketOnMessage(client, function(message) {
        var obj = message_parse(message);
        if (obj.hold) {
          assert.equal(true,false);
          assert.deepEqual(obj, receipt);
        }
      });

    }, two_clients_make_a_game: function() {
      var client_sock = new WebSocket("ws://127.0.0.1:8124/socket.io/websocket", "borf")
        , client_sock2 = new WebSocket("ws://127.0.0.1:8124/socket.io/websocket", "borf");

      client_sock.onopen = function() { socket_send(client_sock, "j", join_message()) };
      client_sock2.onopen = function() { socket_send(client_sock2, "j", join_message()) };

    }, player_assigned_white_can_move: function() {
      var client_sock = new WebSocket("ws://127.0.0.1:8124/socket.io/websocket", "borf")
        , client_sock2 = new WebSocket("ws://127.0.0.1:8124/socket.io/websocket", "borf");

      // join
      client_sock.onopen = function() { socket_send(client_sock, "j", join_message()) };
{'fraction_non_alphanumeric': 0.16537678207739306, 'fraction_numerical': 0.029735234215885947, 'mean_word_length': 3.16893039049236, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 12, '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': '3366027', 'n_tokens_mistral': 1705, 'n_tokens_neox': 1582, 'n_words': 297}