<commit_before>const expect = require('chai').expect;
const assert = require('assert');
const path = require('path');
const exec = require('child_process').exec;

const runner = path.join(__dirname, '/../../bin/codecept.js');
const codecept_dir = path.join(__dirname, '/../data/sandbox');
const codecept_run = `${runner} run`;
const codecept_run_config = config => `${codecept_run} --config ${codecept_dir}/${config}`;
const config_run_override = config => `${codecept_run} --config ${codecept_dir} --override '${JSON.stringify(config)}'`;

describe('CodeceptJS Runner', () => {
  before(() => {
    global.codecept_dir = path.join(__dirname, '/../data/sandbox');
  });

  it('should be executed in current dir', (done) => {
    process.chdir(codecept_dir);
    exec(codecept_run, (err, stdout, stderr) => {
      stdout.should.include('Filesystem'); // feature
      stdout.should.include('check current dir'); // test name
      assert(!err);
      done();
    });
  });


  it('should be executed with config path', (done) => {
    exec(`${codecept_run} -c ${codecept_dir}`, (err, stdout, stderr) => {
      stdout.should.include('Filesystem'); // feature
      stdout.should.include('check current dir'); // test name
      assert(!err);
      done();
    });
  });

  it('should show failures and exit with 1 on fail', (done) => {
    exec(codecept_run_config('codecept.failed.json'), (err, stdout, stderr) => {
      stdout.should.include('Not-A-Filesystem');
      stdout.should.include('file is not in dir');
      stdout.should.include('FAILURES');
      err.code.should.eql(1);
      done();
    });
  });

  it('should run bootstrap', (done) => {
    exec(codecept_run_config('codecept.bootstrap.sync.json'), (err, stdout, stderr) => {
      stdout.should.include('Filesystem'); // feature
      stdout.should.include('I am bootstrap');
      assert(!err);
      done();
    });
  });

  it('should run teardown', (done) => {
    exec(config_run_override({ teardown: 'bootstrap.sync.js' }), (err, stdout, stderr) => {
      stdout.should.include('Filesystem'); // feature
      stdout.should.include('I am bootstrap');
      assert(!err);
      done();
    });
  });

  it('should run async bootstrap', (done) => {
    exec(config_run_override({ bootstrap: 'bootstrap.async.js' }), (err, stdout, stderr) => {
      stdout.should.include('Ready: 0');
      stdout.should.include('Go: 1');
      stdout.should.include('Filesystem'); // feature
      assert(!err);
      done();
    });
  });

  it('should run hooks', (done) => {
    exec(codecept_run_config('codecept.hooks.js'), (err, stdout, stderr) => {
      stdout.should.include('Filesystem'); // feature
      stdout.should.include('I am bootstrap');
      stdout.should.include('I am function hook');
      assert(!err);
      done();
    });
  });

  it('should run hooks from suites', (done) => {
    exec(codecept_run_config('codecept.testhooks.json'), (err, stdout) => {
      const lines = stdout.match(/\S.+/g);
      console.log('lines', lines);

      expect(lines).to.include.members([
        'Helper: I\'m simple BeforeSuite hook',
        'Test: I\'m simple BeforeSuite hook',
        'Test: I\'m generator BeforeSuite hook',
        'Test: I\'m async/await BeforeSuite hook',
        'Helper: I\'m simple Before hook',
        'Test: I\'m simple Before hook',
        'Test: I\'m generator Before hook',
        'Test: I\'m async/await Before hook',
        'Test: I\'m generator After hook',
        'Test: I\'m simple After hook',
        'Test: I\'m async/await After hook',
        'Helper: I\'m simple After hook',
        'Test: I\'m generator AfterSuite hook',
        'Test: I\'m simple AfterSuite hook',
        'Test: I\'m async/await AfterSuite hook',
        'Helper: I\'m simple AfterSuite hook',
      ]);
      stdout.should.include('OK  | 1 passed');
      assert(!err);
      done();
    });
  });

  it('should run hooks from suites (in different order)', (done) => {
    exec(codecept_run_config('codecept.testhooks.different.order.json'), (err, stdout) => {
      const lines = stdout.match(/\S.+/g);
      console.log('lines', lines);

      expect(lines).to.include.members([
        'Helper: I\'m simple BeforeSuite hook',
        'Test: I\'m async/await BeforeSuite hook',
        'Helper: I\'m simple Before hook',
        'Test: I\'m async/await Before hook',
        'Test: I\'m async/await After hook',
        'Helper: I\'m simple After hook',
        'Test: I\'m async/await AfterSuite hook',
        'Helper: I\'m simple AfterSuite hook',
      ]);<commit_msg>Removed debug console.log statements I was using for testing<commit_after>const expect = require('chai').expect;
const assert = require('assert');
const path = require('path');
const exec = require('child_process').exec;

const runner = path.join(__dirname, '/../../bin/codecept.js');
const codecept_dir = path.join(__dirname, '/../data/sandbox');
const codecept_run = `${runner} run`;
const codecept_run_config = config => `${codecept_run} --config ${codecept_dir}/${config}`;
const config_run_override = config => `${codecept_run} --config ${codecept_dir} --override '${JSON.stringify(config)}'`;

describe('CodeceptJS Runner', () => {
  before(() => {
    global.codecept_dir = path.join(__dirname, '/../data/sandbox');
  });

  it('should be executed in current dir', (done) => {
    process.chdir(codecept_dir);
    exec(codecept_run, (err, stdout, stderr) => {
      stdout.should.include('Filesystem'); // feature
      stdout.should.include('check current dir'); // test name
      assert(!err);
      done();
    });
  });


  it('should be executed with config path', (done) => {
    exec(`${codecept_run} -c ${codecept_dir}`, (err, stdout, stderr) => {
      stdout.should.include('Filesystem'); // feature
      stdout.should.include('check current dir'); // test name
      assert(!err);
      done();
    });
  });

  it('should show failures and exit with 1 on fail', (done) => {
    exec(codecept_run_config('codecept.failed.json'), (err, stdout, stderr) => {
      stdout.should.include('Not-A-Filesystem');
      stdout.should.include('file is not in dir');
      stdout.should.include('FAILURES');
      err.code.should.eql(1);
      done();
    });
  });

  it('should run bootstrap', (done) => {
    exec(codecept_run_config('codecept.bootstrap.sync.json'), (err, stdout, stderr) => {
      stdout.should.include('Filesystem'); // feature
      stdout.should.include('I am bootstrap');
      assert(!err);
      done();
    });
  });

  it('should run teardown', (done) => {
    exec(config_run_override({ teardown: 'bootstrap.sync.js' }), (err, stdout, stderr) => {
      stdout.should.include('Filesystem'); // feature
      stdout.should.include('I am bootstrap');
      assert(!err);
      done();
    });
  });

  it('should run async bootstrap', (done) => {
    exec(config_run_override({ bootstrap: 'bootstrap.async.js' }), (err, stdout, stderr) => {
      stdout.should.include('Ready: 0');
      stdout.should.include('Go: 1');
      stdout.should.include('Filesystem'); // feature
      assert(!err);
      done();
    });
  });

  it('should run hooks', (done) => {
    exec(codecept_run_config('codecept.hooks.js'), (err, stdout, stderr) => {
      stdout.should.include('Filesystem'); // feature
      stdout.should.include('I am bootstrap');
      stdout.should.include('I am function hook');
      assert(!err);
      done();
    });
  });

  it('should run hooks from suites', (done) => {
    exec(codecept_run_config('codecept.testhooks.json'), (err, stdout) => {
      const lines = stdout.match(/\S.+/g);

      expect(lines).to.include.members([
        'Helper: I\'m simple BeforeSuite hook',
        'Test: I\'m simple BeforeSuite hook',
        'Test: I\'m generator BeforeSuite hook',
        'Test: I\'m async/await BeforeSuite hook',
        'Helper: I\'m simple Before hook',
        'Test: I\'m simple Before hook',
        'Test: I\'m generator Before hook',
        'Test: I\'m async/await Before hook',
        'Test: I\'m generator After hook',
        'Test: I\'m simple After hook',
        'Test: I\'m async/await After hook',
        'Helper: I\'m simple After hook',
        'Test: I\'m generator AfterSuite hook',
        'Test: I\'m simple AfterSuite hook',
        'Test: I\'m async/await AfterSuite hook',
        'Helper: I\'m simple AfterSuite hook',
      ]);
      stdout.should.include('OK  | 1 passed');
      assert(!err);
      done();
    });
  });

  it('should run hooks from suites (in different order)', (done) => {
    exec(codecept_run_config('codecept.testhooks.different.order.json'), (err, stdout) => {
      const lines = stdout.match(/\S.+/g);

      expect(lines).to.include.members([
        'Helper: I\'m simple BeforeSuite hook',
        'Test: I\'m async/await BeforeSuite hook',
        'Helper: I\'m simple Before hook',
        'Test: I\'m async/await Before hook',
        'Test: I\'m async/await After hook',
        'Helper: I\'m simple After hook',
        'Test: I\'m async/await AfterSuite hook',
        'Helper: I\'m simple AfterSuite hook',
      ]);
{'fraction_non_alphanumeric': 0.1794759346562877, 'fraction_numerical': 0.001096371011950444, 'mean_word_length': 2.966086956521739, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 47, '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': '4598972', 'n_tokens_mistral': 2876, 'n_tokens_neox': 2805, 'n_words': 680}