<commit_before>'use strict';

//====================================================================

var eventToPromise = require('./');

//--------------------------------------------------------------------

var expect = require('chai').expect;

//--------------------------------------------------------------------

var EventEmitter = require('events').EventEmitter;

//====================================================================

// TODO:
// - Forcing the parameters to be forwarded in an array for
//   consistency and predictability.
// - Maybe handling multiple events.

describe('event-to-promise', function () {
  var emitter;

  beforeEach(function () {
    emitter = new EventEmitter();
  });

  //------------------------------------------------------------------

  it('waits for an event', function () {
    var emitted = false;

    emitter.on('foo', function () {
      emitted = true;
    });

    var promise = eventToPromise(emitter, 'foo');

    // Delay the event emission of two ticks to make sure the promise
    // has a chance to run before the event.
    process.nextTick(function () {
      process.nextTick(function () {
        emitter.emit('foo');
      });
    });

    return promise.then(function () {
      expect(emitted).to.be.true;
    });
  });

  //------------------------------------------------------------------

  it('fowards event parameter', function () {
    var parameter = {};

    var promise = eventToPromise(emitter, 'foo');
    emitter.emit('foo', parameter);

    return promise.then(function (value) {
      expect(value).to.equal(parameter);
    });
  });
<commit_msg>Fix a unspecified behavior in the tests.<commit_after>'use strict';

//====================================================================

var eventToPromise = require('./');

//--------------------------------------------------------------------

var expect = require('chai').expect;

//--------------------------------------------------------------------

var EventEmitter = require('events').EventEmitter;

//====================================================================

// TODO:
// - Forcing the parameters to be forwarded in an array for
//   consistency and predictability.
// - Maybe handling multiple events.

describe('event-to-promise', function () {
  var emitter;

  beforeEach(function () {
    emitter = new EventEmitter();
  });

  //------------------------------------------------------------------

  it('waits for an event', function () {
    var emitted = false;

    var promise = eventToPromise(emitter, 'foo');

    // Delay the event emission of two ticks to make sure the promise
    // has a chance to run before the event.
    process.nextTick(function () {
      process.nextTick(function () {
        emitter.emit('foo');
        emitted = true;
      });
    });

    return promise.then(function () {
      expect(emitted).to.be.true;
    });
  });

  //------------------------------------------------------------------

  it('fowards event parameter', function () {
    var parameter = {};

    var promise = eventToPromise(emitter, 'foo');
    emitter.emit('foo', parameter);

    return promise.then(function (value) {
      expect(value).to.equal(parameter);
    });
  });

{'fraction_non_alphanumeric': 0.3620159803318992, 'fraction_numerical': 0.0, 'mean_word_length': 1.719298245614035, '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': '1720635', 'n_tokens_mistral': 779, 'n_tokens_neox': 730, 'n_words': 194}