<commit_before>var httpServer = require('http').createServer
var WebSocket = require('ws')

var BrowserConnection = require('../browser-connection')
var ServerConnection = require('../server-connection')

var http
afterEach(function () {
  http.close()
})

function wait (prev) {
  return new Promise(function (resolve) {
    setTimeout(function () {
      resolve(prev)
    }, 50)
  })
}

it('works in real protocol', function () {
  window.WebSocket = WebSocket
  http = httpServer()
  var wss = new WebSocket.Server({ server: http })
  http.listen(8081)

  var client = new BrowserConnection('ws://0.0.0.0:8081')
  var clientReceived = []
  client.on('message', function (msg) {
    clientReceived.push(msg)
  })

  var server
  var serverReceived = []
  return new Promise(function (resolve) {
    wss.on('connection', function (ws) {
      server = new ServerConnection(ws)
      server.on('message', function (msg) {
        serverReceived.push(msg)
      })<commit_msg>Clean up real WebSocket test<commit_after>var WebSocket = require('ws')

var BrowserConnection = require('../browser-connection')
var ServerConnection = require('../server-connection')

var wss
afterEach(function () {
  wss.close()
})

function wait (prev) {
  return new Promise(function (resolve) {
    setTimeout(function () {
      resolve(prev)
    }, 50)
  })
}

it('works in real protocol', function () {
  window.WebSocket = WebSocket
  wss = new WebSocket.Server({ port: 8081 })

  var client = new BrowserConnection('ws://0.0.0.0:8081')
  var clientReceived = []
  client.on('message', function (msg) {
    clientReceived.push(msg)
  })

  var server
  var serverReceived = []
  return new Promise(function (resolve) {
    wss.on('connection', function (ws) {
      server = new ServerConnection(ws)
      server.on('message', function (msg) {
        serverReceived.push(msg)
      })
{'fraction_non_alphanumeric': 0.14430785676109031, 'fraction_numerical': 0.014965259219668627, 'mean_word_length': 3.656716417910448, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '1970629', 'n_tokens_mistral': 584, 'n_tokens_neox': 564, 'n_words': 137}