<commit_before>var nicely = require('..');

var sinon = require('sinon');
var expect = require('expect.js');

var greek = [
  'alpha',
  'beta',
  'gamma',
  'delta',
  'epsilon',
  'zeta',
  'eta',
  'theta'
];

describe('sequentially', function() {
  var error = new Error('the failure');
  var queue, spy;

  var start = function(done) {
    queue = nicely.sequentially(spy = sinon.spy(done));
  };

  var checkHappy = function(done, object) {
    return function() {
      expect(spy.called).to.be.ok();
      expect(spy.calledOnce).to.be.ok();
      expect(spy.args[0]).to.have.length(2);
      expect(spy.args[0][0]).to.not.be.an(Error);
      expect(spy.args[0][0]).to.not.be.ok();
      expect(spy.args[0][1]).to.eql(object || greek);
      done();
    };
  };

  var checkLonely = function(done) {
    return function() {
      expect(spy.called).to.not.be.ok();
      done();
    };
  };

  var checkSad = function(done) {
    return function() {
      expect(spy.called).to.be.ok();
      expect(spy.calledOnce).to.be.ok();
      expect(spy.args[0].length).to.be.within(1, 2);
      expect(spy.args[0][0]).to.equal(error);
      if (spy.args[0].length === 2)
        expect(spy.args[0][1]).to.not.be.ok();
      done();
    };
  };

  var stubby = function(result, callback) {
    if (result)
      callback(null, result);
    else
      callback(error);
  };

  it('should call back with correct results', function(done) {
    start(checkHappy(done));
    for (var i = 0; i < greek.length; i++)
      queue(stubby, greek[i]);
  });

  it('should pass the error', function(done) {
    start(checkSad(done));
    for (var i = 0; i < greek.length; i++)
      queue(stubby, null);
  });

  it('should ignore the data on error', function(done) {
    start(checkSad(done));
    for (var i = 1; i < greek.length; i++)
      queue(stubby, greek[i]);
    queue(stubby, null);
  });

  it('should allow updates after tick', function(done) {
    debugger;
    start(checkHappy(done, [true, 'nicely']));<commit_msg>Remove left over debugger;<commit_after>var nicely = require('..');

var sinon = require('sinon');
var expect = require('expect.js');

var greek = [
  'alpha',
  'beta',
  'gamma',
  'delta',
  'epsilon',
  'zeta',
  'eta',
  'theta'
];

describe('sequentially', function() {
  var error = new Error('the failure');
  var queue, spy;

  var start = function(done) {
    queue = nicely.sequentially(spy = sinon.spy(done));
  };

  var checkHappy = function(done, object) {
    return function() {
      expect(spy.called).to.be.ok();
      expect(spy.calledOnce).to.be.ok();
      expect(spy.args[0]).to.have.length(2);
      expect(spy.args[0][0]).to.not.be.an(Error);
      expect(spy.args[0][0]).to.not.be.ok();
      expect(spy.args[0][1]).to.eql(object || greek);
      done();
    };
  };

  var checkLonely = function(done) {
    return function() {
      expect(spy.called).to.not.be.ok();
      done();
    };
  };

  var checkSad = function(done) {
    return function() {
      expect(spy.called).to.be.ok();
      expect(spy.calledOnce).to.be.ok();
      expect(spy.args[0].length).to.be.within(1, 2);
      expect(spy.args[0][0]).to.equal(error);
      if (spy.args[0].length === 2)
        expect(spy.args[0][1]).to.not.be.ok();
      done();
    };
  };

  var stubby = function(result, callback) {
    if (result)
      callback(null, result);
    else
      callback(error);
  };

  it('should call back with correct results', function(done) {
    start(checkHappy(done));
    for (var i = 0; i < greek.length; i++)
      queue(stubby, greek[i]);
  });

  it('should pass the error', function(done) {
    start(checkSad(done));
    for (var i = 0; i < greek.length; i++)
      queue(stubby, null);
  });

  it('should ignore the data on error', function(done) {
    start(checkSad(done));
    for (var i = 1; i < greek.length; i++)
      queue(stubby, greek[i]);
    queue(stubby, null);
  });

  it('should allow updates after tick', function(done) {
    start(checkHappy(done, [true, 'nicely']));
{'fraction_non_alphanumeric': 0.19756763464879623, 'fraction_numerical': 0.009928021841648052, 'mean_word_length': 2.9240506329113924, 'pattern_counts': {'":': 0, '<': 9, '<?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': '3059088', 'n_tokens_mistral': 1501, 'n_tokens_neox': 1463, 'n_words': 285}