<commit_before>/* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^ws$", "args": "none" }] */

'use strict';

const assert = require('assert');
const crypto = require('crypto');
const https = require('https');
const http = require('http');
const fs = require('fs');

const server = require('./testserver');
const WebSocket = require('..');

const WebSocketServer = WebSocket.Server;
let port = 20000;

class CustomAgent extends http.Agent {
  createConnection () {}
}

describe('WebSocket', function () {
  describe('#ctor', function () {
    it('should return a new instance if called without new', function (done) {
      const ws = WebSocket('ws://localhost');

      assert.ok(ws instanceof WebSocket);
      ws.on('error', () => done());
    });

    it('throws an error when using an invalid url', function () {
      assert.throws(
        () => new WebSocket('echo.websocket.org'),
        /^Error: invalid url$/
      );
    });
  });

  describe('options', function () {
    it('should accept an `agent` option', function (done) {
      const agent = new CustomAgent();

      agent.createConnection = () => {
        done();
      };

      const ws = new WebSocket('ws://localhost', { agent });
    });

    // GH-227
    it('should accept the `options` object as the 3rd argument', function () {
      const ws = new WebSocket('ws://localhost', [], {
        agent: new CustomAgent()
      });
    });

    it('throws an error when using an invalid `protocolVersion`', function () {
      const options = { agent: new CustomAgent(), protocolVersion: 1000 };

      assert.throws(
        () => new WebSocket('ws://localhost', options),
        /^Error: unsupported protocol version$/
      );
    });

    it('should accept the localAddress option', function (done) {
      //
      // Skip this test on macOS as by default all loopback addresses other
      // than 127.0.0.1 are disabled.
      //
      if (process.platform === 'darwin') return done();<commit_msg>[test] Fix failing tests on node 4<commit_after>/* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^ws$", "args": "none" }] */

'use strict';

const assert = require('assert');
const crypto = require('crypto');
const https = require('https');
const http = require('http');
const fs = require('fs');

const server = require('./testserver');
const WebSocket = require('..');

const WebSocketServer = WebSocket.Server;
let port = 20000;

class CustomAgent extends http.Agent {
  addRequest () {}
}

describe('WebSocket', function () {
  describe('#ctor', function () {
    it('should return a new instance if called without new', function (done) {
      const ws = WebSocket('ws://localhost');

      assert.ok(ws instanceof WebSocket);
      ws.on('error', () => done());
    });

    it('throws an error when using an invalid url', function () {
      assert.throws(
        () => new WebSocket('echo.websocket.org'),
        /^Error: invalid url$/
      );
    });
  });

  describe('options', function () {
    it('should accept an `agent` option', function (done) {
      const agent = new CustomAgent();

      agent.addRequest = () => {
        done();
      };

      const ws = new WebSocket('ws://localhost', { agent });
    });

    // GH-227
    it('should accept the `options` object as the 3rd argument', function () {
      const ws = new WebSocket('ws://localhost', [], {
        agent: new CustomAgent()
      });
    });

    it('throws an error when using an invalid `protocolVersion`', function () {
      const options = { agent: new CustomAgent(), protocolVersion: 1000 };

      assert.throws(
        () => new WebSocket('ws://localhost', options),
        /^Error: unsupported protocol version$/
      );
    });

    it('should accept the localAddress option', function (done) {
      //
      // Skip this test on macOS as by default all loopback addresses other
      // than 127.0.0.1 are disabled.
      //
      if (process.platform === 'darwin') return done();
{'fraction_non_alphanumeric': 0.16503636819663908, 'fraction_numerical': 0.009781790820165538, 'mean_word_length': 2.8457087753134043, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 11, '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': '1036136', 'n_tokens_mistral': 1156, 'n_tokens_neox': 1087, 'n_words': 345}