<commit_before>var justWait = require('promise-to-test').justWait;
var waitFor = require('promise-to-test').waitFor;
var chai = require('chai');
var doTheStuff = require('../index');
var sinon = require('sinon');
var Q = require('q');

describe("Initial Async", function(){
  beforeEach(function() {
    if(!console.log.restore) sinon.spy(console, "log")
  });

  afterEach(function(){
    if(console.log.restore) console.log.restore();
  });

  var ajax = function(url, callback){
    var res = justWait(100).then(function(){
      res.data = "bleep bloop!";
      return {data: res.data};
    })
    return res.nodeify(callback);
  }

  it("calls the ajax", function(){
    var called = false
    var ajax = function(url, callback){
      called = true
      var output = Q({data:"yay!"}).nodeify(callback);
      output.data = "yay!";
      return output;
    }

    doTheStuff(ajax)
    chai.assert.ok(called, "ajax not called")
  })

  it("calls the ajax and then logs the result", function(done){
    doTheStuff(ajax);

    waitFor(function(){
      chai.assert.ok(console.log.calledWith("bleep bloop!"), "result was not logged");
    }, 500)
    .then(function(){done()}, done);
  })

  it("uses the callback instead of looping", function(done){
    sinon.spy(global, "setTimeout");
    sinon.spy(global, "setInterval");

    doTheStuff(ajax);
    chai.assert.equal(global.setTimeout.callCount, 1, "setTimeout still in use");
    chai.assert.equal(global.setTimeout.callCount, 1, "setInterval still in use");

    waitFor(function(){
      chai.assert.ok(console.log.calledWith("bleep bloop!"), "result was not logged");
    }, 500)
    .then(function(){done()}, done);
  })
});<commit_msg>fix early tests for promises<commit_after>var justWait = require('promise-to-test').justWait;
var waitFor = require('promise-to-test').waitFor;
var chai = require('chai');
var doTheStuff = require('../index');
var sinon = require('sinon');
var Q = require('q');

describe("Initial Async", function(){
  beforeEach(function() {
    if(!console.log.restore) sinon.spy(console, "log")
  });

  afterEach(function(){
    if(console.log.restore) console.log.restore();
  });

  var ajax = function(url, callback){
    var res = justWait(100).then(function(){
      res.data = "bleep bloop!";
      return {data: res.data};
    })
    return res.nodeify(callback);
  }

  it("calls the ajax", function(done){
    var called = false
    var ajax = function(url, callback){
      called = true
      return Q({data:"yay!"}).nodeify(callback);
    }

    doTheStuff(ajax)
    waitFor(function(){
      chai.assert.ok(called, "ajax not called")
    }, 300)
    .then(function(){done()}, done);
  })

  it("calls the ajax and then logs the result", function(done){
    doTheStuff(ajax);

    waitFor(function(){
      chai.assert.ok(console.log.calledWith("bleep bloop!"), "result was not logged");
    }, 500)
    .then(function(){done()}, done);
  })

  it("uses the callback instead of looping", function(done){
    sinon.spy(global, "setTimeout");
    sinon.spy(global, "setInterval");

    doTheStuff(ajax);
    chai.assert.ok(global.setTimeout.callCount < 2, "setTimeout still in use");
    chai.assert.ok(global.setTimeout.callCount < 2, "setInterval still in use");

    waitFor(function(){
      chai.assert.ok(console.log.calledWith("bleep bloop!"), "result was not logged");
    }, 500)
    .then(function(){done()}, done);
  })
});
{'fraction_non_alphanumeric': 0.17497812773403323, 'fraction_numerical': 0.007290755322251386, 'mean_word_length': 3.7050754458161865, 'pattern_counts': {'":': 0, '<': 5, '<?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': '7012591', 'n_tokens_mistral': 1168, 'n_tokens_neox': 1120, 'n_words': 247}