<commit_before>var expect = require('expect.js');

describe('CrossStorageClient', function() {
  // Increase timeouts
  this.timeout(10000);

  var url = location.origin + '/test/hub.html';
  var storage = new CrossStorageClient(url);

  var setGet = function(key, value, ttl) {
    return function() {
      return storage.set(key, value, ttl).then(function() {
        return storage.get(key);
      });
    };
  };

  beforeEach(function(done) {
    // Delete keys before each test
    storage.onConnect().then(function() {
      return storage.del('key1', 'key2');
    })
    .then(done)
    .catch(done);
  });

  describe('Constructor', function() {
    it('parses the passed url and stores its origin', function() {
      expect(storage._origin).to.be(location.origin);
    });

    it('sets its connected status to false', function() {
      var storage = new CrossStorageClient(url);
      expect(storage._connected).to.be(false);
    });

    it('initializes _requests as an empty object', function() {
      var storage = new CrossStorageClient(url);
      expect(storage._requests).to.eql({});
    });

    it('creates a hidden iframe', function() {
      var frame = document.getElementsByTagName('iframe')[0];
      expect(frame.style.display).to.be('none');
      expect(frame.style.position).to.be('absolute');
      expect(frame.style.top).to.be('-999px');
      expect(frame.style.left).to.be('-999px');
    });

    it('sets the iframe src to the hub url', function() {
      var frame = document.getElementsByTagName('iframe')[0];
      expect(frame.src).to.be(url);
    });

    it('stores the frame context window in _hub', function() {
      expect(storage._hub.constructor.name).to.be('Window');
    });
  });

  describe('onConnect', function() {
    it('returns a promise that is resolved when connected', function(done) {
      storage.onConnect().then(done);
    });

    it('is not fulfilled if a connection is not established', function(done) {
      var storage = new CrossStorageClient('http://localhost:9999');
      var invoked = false;

      storage.onConnect().then(function() {<commit_msg>Checking constructor of ._hub is not cross browser compatible<commit_after>var expect = require('expect.js');

describe('CrossStorageClient', function() {
  // Increase timeouts
  this.timeout(10000);

  var url = location.origin + '/test/hub.html';
  var storage = new CrossStorageClient(url);

  var setGet = function(key, value, ttl) {
    return function() {
      return storage.set(key, value, ttl).then(function() {
        return storage.get(key);
      });
    };
  };

  beforeEach(function(done) {
    // Delete keys before each test
    storage.onConnect().then(function() {
      return storage.del('key1', 'key2');
    })
    .then(done)
    .catch(done);
  });

  describe('Constructor', function() {
    it('parses the passed url and stores its origin', function() {
      expect(storage._origin).to.be(location.origin);
    });

    it('sets its connected status to false', function() {
      var storage = new CrossStorageClient(url);
      expect(storage._connected).to.be(false);
    });

    it('initializes _requests as an empty object', function() {
      var storage = new CrossStorageClient(url);
      expect(storage._requests).to.eql({});
    });

    it('creates a hidden iframe', function() {
      var frame = document.getElementsByTagName('iframe')[0];
      expect(frame.style.display).to.be('none');
      expect(frame.style.position).to.be('absolute');
      expect(frame.style.top).to.be('-999px');
      expect(frame.style.left).to.be('-999px');
    });

    it('sets the iframe src to the hub url', function() {
      var frame = document.getElementsByTagName('iframe')[0];
      expect(frame.src).to.be(url);
    });

    it('stores the frame context window in _hub', function() {
      // constructor.name isn't cross browser, and the window function name
      // varies between browsers (WindowConstructor, Window, etc)
      expect(storage._hub).to.not.be(null);
    });
  });

  describe('onConnect', function() {
    it('returns a promise that is resolved when connected', function(done) {
      storage.onConnect().then(done);
    });

    it('is not fulfilled if a connection is not established', function(done) {
      var storage = new CrossStorageClient('http://localhost:9999');
      var invoked = false;

      storage.onConnect().then(function() {
{'fraction_non_alphanumeric': 0.15608764400271063, 'fraction_numerical': 0.008583690987124463, 'mean_word_length': 3.2782608695652176, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1818160', 'n_tokens_mistral': 1338, 'n_tokens_neox': 1275, 'n_words': 305}