<commit_before>var Karma  = require('../../client/karma');
var MockSocket = require('./mocks').Socket;


describe('Karma', function() {
  var socket, k, spyStart, windowNavigator, windowLocation, spyWindowOpener;

  var setTransportTo = function(transportName) {
    socket._setTransportNameTo(transportName);
    socket.emit('connect');
  };


  beforeEach(function() {
    socket = new MockSocket();
    windowNavigator = {};
    windowLocation = {search: ''};
    spyWindowOpener = jasmine.createSpy('window.open').andReturn({});
    k = new Karma(socket, {}, spyWindowOpener, windowNavigator, windowLocation);
    spyStart = spyOn(k, 'start');
  });


  it('should start execution when all files loaded and pass config', function() {
    var config = {
      useIframe: true
    };

    socket.emit('execute', config);
    expect(spyStart).not.toHaveBeenCalled();

    k.loaded();
    expect(spyStart).toHaveBeenCalledWith(config);
  });


  it('should open a new window when useIFrame is false', function() {
    var config = {
      useIframe: false
    };

    socket.emit('execute', config);
    expect(spyStart).not.toHaveBeenCalled();

    k.loaded();
    expect(spyStart).toHaveBeenCalledWith(config);
    expect(spyWindowOpener).toHaveBeenCalledWith('about:blank');
  });


  it('should not start execution if any error during loading files', function() {
    k.error('syntax error', '/some/file.js', 11);
    k.loaded();

    expect(spyStart).not.toHaveBeenCalled();
  });


  it('should remove reference to start even after syntax error', function() {
    k.error('syntax error', '/some/file.js', 11);
    k.loaded();
    expect(k.start).toBeFalsy();

    k.start = function() {};
    k.loaded();
    expect(k.start).toBeFalsy();
  });


  it('should not set up context if there was an error', function() {
    var mockWindow = {};

    k.error('page reload');
    k.setupContext(mockWindow);

    expect(mockWindow.__karma__).toBeUndefined();
    expect(mockWindow.onbeforeunload).toBeUndefined();
    expect(mockWindow.onerror).toBeUndefined();
  });


  it('should report navigator name', function() {<commit_msg>test(client): fix the unit tests<commit_after>var Karma  = require('../../client/karma');
var MockSocket = require('./mocks').Socket;


describe('Karma', function() {
  var socket, k, spyStart, windowNavigator, windowLocation, spyWindowOpener;

  var setTransportTo = function(transportName) {
    socket._setTransportNameTo(transportName);
    socket.emit('connect');
  };


  beforeEach(function() {
    socket = new MockSocket();
    windowNavigator = {};
    windowLocation = {search: ''};
    spyWindowOpener = jasmine.createSpy('window.open').andReturn({});
    k = new Karma(socket, {}, spyWindowOpener, windowNavigator, windowLocation);
    spyStart = spyOn(k, 'start');
  });


  it('should start execution when all files loaded and pass config', function() {
    var config = {
      useIframe: true
    };

    socket.emit('execute', config);
    expect(spyStart).not.toHaveBeenCalled();

    k.loaded();
    expect(spyStart).toHaveBeenCalledWith(config);
  });


  it('should open a new window when useIFrame is false', function() {
    var config = {
      useIframe: false
    };

    socket.emit('execute', config);
    expect(spyStart).not.toHaveBeenCalled();

    k.loaded();
    expect(spyStart).toHaveBeenCalledWith(config);
    expect(spyWindowOpener).toHaveBeenCalledWith('about:blank');
  });


  it('should not start execution if any error during loading files', function() {
    k.error('syntax error', '/some/file.js', 11);
    k.loaded();

    expect(spyStart).not.toHaveBeenCalled();
  });


  it('should remove reference to start even after syntax error', function() {
    var ADAPTER_START_FN = function() {};

    k.start = ADAPTER_START_FN;
    k.error('syntax error', '/some/file.js', 11);
    k.loaded();
    expect(k.start).not.toBe(ADAPTER_START_FN);

    k.start = ADAPTER_START_FN;
    k.loaded();
    expect(k.start).not.toBe(ADAPTER_START_FN);
  });


  it('should not set up context if there was an error', function() {
    var mockWindow = {};

    k.error('page reload');
    k.setupContext(mockWindow);

    expect(mockWindow.__karma__).toBeUndefined();
    expect(mockWindow.onbeforeunload).toBeUndefined();
    expect(mockWindow.onerror).toBeUndefined();
  });


  it('should report navigator name', function() {
{'fraction_non_alphanumeric': 0.1531798495555049, 'fraction_numerical': 0.0018235696375655346, 'mean_word_length': 3.8325991189427313, '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': '7118211', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1333, 'n_words': 287}