<commit_before>/*jshint jasmine: true, node: true */
'use strict';

const path = require('path');
const mock = require('mock-require');
const logger = require('winston');
const selenium = require('selenium-standalone');

describe('cli e2e', () => {

  let returnSeleniumServer;
  let webpackDevServerCalled;
  let webpackDevServerClosed;
  let webpackCompiler;
  let spawnCmd;
  let spawnConfig;
  let spawnSyncCmd;
  let spawnSyncFlags;
  let spawnSyncConfig;
  let spawnExitCb;

  beforeEach(() => {
    returnSeleniumServer = true;
    webpackDevServerCalled = false;
    webpackDevServerClosed = false;
    webpackCompiler = null;
    spawnCmd = null;
    spawnConfig = null;
    spawnSyncCmd = null;
    spawnSyncFlags = null;
    spawnSyncConfig = null;
    spawnExitCb = null;

    mock('webpack-dev-server', function (compiler) {
      webpackDevServerCalled = true;
      webpackCompiler = compiler;
      return {
        listen: () => {},

        close: () => {
          webpackDevServerClosed = true;
        }
      };
    });

    mock('cross-spawn', {
      spawn: (cmd, config) => {
        spawnCmd = cmd;
        spawnConfig = config;
        return {
          on: (evt, cb) => {
            if (evt === 'exit') {
              spawnExitCb = cb;
            }
          }
        };
      },

      sync: (syncCmd, syncFlags, syncConfig) => {
        spawnSyncCmd = syncCmd;
        spawnSyncFlags = syncFlags;
        spawnSyncConfig = syncConfig;
      }
    });
  });

  afterEach(() => {
    mock.stop('webpack-dev-server');
    mock.stop('cross-spawn');
  });

  it('should spawn and close webpack dev server', () => {
    spyOn(logger, 'info');
    require('../cli/e2e')({});
    webpackCompiler.options.plugins.forEach((plugin) => {
      if (plugin.name === 'WebpackPluginDoneE2E') {
        plugin.apply({
          plugin: (evt, cb) => {
            cb();
            spawnExitCb();
            expect(logger.info).toHaveBeenCalledWith('Webpack server is ready.');
            expect(webpackDevServerCalled).toEqual(true);
            expect(webpackDevServerClosed).toEqual(true);
          }
        });
      }
    });
  });

  it('should not spawn webpack dev server if noServe is true', () => {
    require('../cli/e2e')({ noServe: true });
    expect(webpackDevServerCalled).toEqual(false);
  });

  it('should spawn protractor', () => {
    spyOn(logger, 'info');
    require('../cli/e2e')({ noServe: true });

    expect(spawnCmd).toContain('protractor');
    expect(spawnConfig[0]).toContain('protractor.conf.js');
  });

  it('should install, start, and close selenium if seleniumAddress is given', () => {
    const configPath = path.resolve(
      __dirname,
      '..',
      'config',
      'protractor',
      'protractor.conf.js'
    );

    let cbInstall;
    let cbStart;
    let killed = false;

    spyOn(selenium, 'install').and.callFake((config, cb) => {
      cbInstall = cb;
    });
    spyOn(selenium, 'start').and.callFake((cb) => {
      cbStart = cb;
    });
    spyOn(logger, 'info');

    mock(configPath, {
      config: {
        seleniumAddress: 'asdf'
      }
    });

    require('../cli/e2e')({ noServe: true });
    cbInstall();
    cbStart(null, {
      kill: () => {
        killed = true;
      }
    });
    spawnExitCb();
    expect(selenium.install).toHaveBeenCalled();
    expect(selenium.start).toHaveBeenCalled();
    expect(logger.info).toHaveBeenCalledWith('Selenium server is ready.');
    expect(logger.info).toHaveBeenCalledWith('Cleaning up running servers');
    expect(killed).toEqual(true);
    mock.stop(configPath);
  });

  it('should only kill the seleniumServer and webpackServer if they exist', () => {
    spyOn(logger, 'info');
    require('../cli/e2e')({ noServe: true });
    spawnExitCb();
    expect(logger.info).toHaveBeenCalledTimes(2);
  });

  it('should listen for SIGINT and kill the servers', () => {

    spyOn(process, 'exit');
    spyOn(process, 'on').and.callFake((evt, cb) => {
      if (evt === 'SIGINT') {
        cb();
      }
    });
    require('../cli/e2e')({ noServe: true });
    expect(process.exit).toHaveBeenCalledWith(1);
  });

});<commit_msg>Adjusted tests to ignore process.exit<commit_after>/*jshint jasmine: true, node: true */
'use strict';

const path = require('path');
const mock = require('mock-require');
const logger = require('winston');
const selenium = require('selenium-standalone');

describe('cli e2e', () => {

  let returnSeleniumServer;
  let webpackDevServerCalled;
  let webpackDevServerClosed;
  let webpackCompiler;
  let spawnCmd;
  let spawnConfig;
  let spawnSyncCmd;
  let spawnSyncFlags;
  let spawnSyncConfig;
  let spawnExitCb;

  beforeEach(() => {
    returnSeleniumServer = true;
    webpackDevServerCalled = false;
    webpackDevServerClosed = false;
    webpackCompiler = null;
    spawnCmd = null;
    spawnConfig = null;
    spawnSyncCmd = null;
    spawnSyncFlags = null;
    spawnSyncConfig = null;
    spawnExitCb = null;

    spyOn(process, 'exit');

    mock('webpack-dev-server', function (compiler) {
      webpackDevServerCalled = true;
      webpackCompiler = compiler;
      return {
        listen: () => {},

        close: () => {
          webpackDevServerClosed = true;
        }
      };
    });

    mock('cross-spawn', {
      spawn: (cmd, config) => {
        spawnCmd = cmd;
        spawnConfig = config;
        return {
          on: (evt, cb) => {
            if (evt === 'exit') {
              spawnExitCb = cb;
            }
          }
        };
      },

      sync: (syncCmd, syncFlags, syncConfig) => {
        spawnSyncCmd = syncCmd;
        spawnSyncFlags = syncFlags;
        spawnSyncConfig = syncConfig;
      }
    });
  });

  afterEach(() => {
    mock.stop('webpack-dev-server');
    mock.stop('cross-spawn');
  });

  it('should spawn and close webpack dev server', () => {
    spyOn(logger, 'info');
    require('../cli/e2e')({});
    webpackCompiler.options.plugins.forEach((plugin) => {
      if (plugin.name === 'WebpackPluginDoneE2E') {
        plugin.apply({
          plugin: (evt, cb) => {
            cb();
            spawnExitCb();
            expect(logger.info).toHaveBeenCalledWith('Webpack server is ready.');
            expect(webpackDevServerCalled).toEqual(true);
            expect(webpackDevServerClosed).toEqual(true);
          }
        });
      }
    });
  });

  it('should not spawn webpack dev server if noServe is true', () => {
    require('../cli/e2e')({ noServe: true });
    expect(webpackDevServerCalled).toEqual(false);
  });

  it('should spawn protractor', () => {
    spyOn(logger, 'info');
    require('../cli/e2e')({ noServe: true });

    expect(spawnCmd).toContain('protractor');
    expect(spawnConfig[0]).toContain('protractor.conf.js');
  });

  it('should install, start, and close selenium if seleniumAddress is given', () => {
    const configPath = path.resolve(
      __dirname,
      '..',
      'config',
      'protractor',
      'protractor.conf.js'
    );

    let cbInstall;
    let cbStart;
    let killed = false;

    spyOn(selenium, 'install').and.callFake((config, cb) => {
      cbInstall = cb;
    });
    spyOn(selenium, 'start').and.callFake((cb) => {
      cbStart = cb;
    });
    spyOn(logger, 'info');

    mock(configPath, {
      config: {
        seleniumAddress: 'asdf'
      }
    });

    require('../cli/e2e')({ noServe: true });
    cbInstall();
    cbStart(null, {
      kill: () => {
        killed = true;
      }
    });
    spawnExitCb();
    expect(selenium.install).toHaveBeenCalled();
    expect(selenium.start).toHaveBeenCalled();
    expect(logger.info).toHaveBeenCalledWith('Selenium server is ready.');
    expect(logger.info).toHaveBeenCalledWith('Cleaning up running servers');
    expect(killed).toEqual(true);
    mock.stop(configPath);
  });

  it('should only kill the seleniumServer and webpackServer if they exist', () => {
    spyOn(logger, 'info');
    require('../cli/e2e')({ noServe: true });
    spawnExitCb();
    expect(logger.info).toHaveBeenCalledTimes(2);
  });

  it('should listen for SIGINT and kill the servers', () => {
    spyOn(process, 'on').and.callFake((evt, cb) => {
      if (evt === 'SIGINT') {
        cb();
      }
    });
    require('../cli/e2e')({ noServe: true });
    expect(process.exit).toHaveBeenCalledWith(1);
  });

});
{'fraction_non_alphanumeric': 0.16052190567392866, 'fraction_numerical': 0.0026334689968877186, 'mean_word_length': 2.564419795221843, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 43, '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': '3702096', 'n_tokens_mistral': 2688, 'n_tokens_neox': 2691, 'n_words': 508}