<commit_before>const scenario = require('../../lib/scenario');
const recorder = require('../../lib/recorder');
const event = require('../../lib/event');
const assert = require('assert');
const sinon = require('sinon');

let test;
let fn;
let before;
let after;
let beforeSuite;
let afterSuite;
let failed;
let started;

describe('Scenario', () => {
  beforeEach(() => {
    test = {};
    fn = sinon.spy();
    test.fn = fn;
  });
  beforeEach(() => recorder.reset());
  afterEach(() => event.cleanDispatcher());

  it('should wrap test function', () => {
    scenario.test(test).fn();
    assert.ok(fn.called);
  });

  it('should work with generator func', () => {
    let counter = 0;
    test.fn = function* () {
      yield counter++;
      yield counter++;
      yield counter++;
      counter++;
    };
    scenario.setup();
    scenario.test(test).fn(() => null);
    recorder.add('validation', () => assert.equal(counter, 3));
    return recorder.promise();
  });

  it('should work with async func', () => {
    let counter = 0;
    let error;
    test.fn = () => {
      recorder.add('test', async () => {
        await counter++;
        await counter++;
        await counter++;
        counter++;
      });
    };

    scenario.setup();
    scenario.test(test).fn(() => null);
    recorder.add('validation', () => assert.equal(counter, 4));
    return recorder.promise();
  });

  describe('events', () => {
    beforeEach(() => {
      event.dispatcher.on(event.test.before, before = sinon.spy());
      event.dispatcher.on(event.test.after, after = sinon.spy());
      event.dispatcher.on(event.test.started, started = sinon.spy());
      event.dispatcher.on(event.suite.before, beforeSuite = sinon.spy());
      event.dispatcher.on(event.suite.after, afterSuite = sinon.spy());
      scenario.suiteSetup();
      scenario.setup();
    });

    it('should fire events', () => {
      scenario.test(test).fn(() => null);
      assert.ok(started.called);
      scenario.teardown();
      scenario.suiteTeardown();
      return recorder.promise()
        .then(() => assert.ok(beforeSuite.called))
        .then(() => assert.ok(afterSuite.called))
        .then(() => assert.ok(before.called))
        .then(() => assert.ok(after.called));
    });

    it('should fire failed event on error', (done) => {<commit_msg>fixed scenario test<commit_after>const scenario = require('../../lib/scenario');
const recorder = require('../../lib/recorder');
const event = require('../../lib/event');
const assert = require('assert');
const sinon = require('sinon');

let test;
let fn;
let before;
let after;
let beforeSuite;
let afterSuite;
let failed;
let started;

describe('Scenario', () => {
  beforeEach(() => {
    test = {};
    fn = sinon.spy();
    test.fn = fn;
  });
  beforeEach(() => recorder.reset());
  afterEach(() => event.cleanDispatcher());

  it('should wrap test function', () => {
    scenario.test(test).fn();
    assert.ok(fn.called);
  });

  it('should work with generator func', () => {
    let counter = 0;
    test.fn = function* () {
      yield counter++;
      yield counter++;
      yield counter++;
      counter++;
    };
    scenario.setup();
    scenario.test(test).fn(() => null);
    recorder.add('validation', () => assert.equal(counter, 3));
    return recorder.promise();
  });

  it('should work with async func', () => {
    let counter = 0;
    let error;
    test.fn = () => {
      recorder.add('test', async () => {
        await counter++;
        await counter++;
        await counter++;
        counter++;
      });
    };

    scenario.setup();
    scenario.test(test).fn(() => null);
    recorder.add('validation', () => assert.equal(counter, 4));
    return recorder.promise();
  });

  describe('events', () => {
    beforeEach(() => {
      event.dispatcher.on(event.test.before, before = sinon.spy());
      event.dispatcher.on(event.test.after, after = sinon.spy());
      event.dispatcher.on(event.test.started, started = sinon.spy());
      event.dispatcher.on(event.suite.before, beforeSuite = sinon.spy());
      event.dispatcher.on(event.suite.after, afterSuite = sinon.spy());
      scenario.suiteSetup();
      scenario.setup();
    });

    it('should fire events', () => {
      scenario.test(test).fn(() => null);
      assert.ok(started.called);
      scenario.teardown();
      scenario.suiteTeardown();
      return recorder.promise()
        .then(() => assert.ok(beforeSuite.called))
        .then(() => assert.ok(afterSuite.called))
        .then(() => assert.ok(before.called))
        .then(() => assert.ok(after.called));
    });

    it('should fire failed event on error', () => {
{'fraction_non_alphanumeric': 0.2, 'fraction_numerical': 0.0017167381974248926, 'mean_word_length': 2.8173628173628176, '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': '329338', 'n_tokens_mistral': 1443, 'n_tokens_neox': 1428, 'n_words': 291}