<commit_before>'use strict';
var proxyquire = require('proxyquire').noPreserveCache();
var sinon = require('sinon');
var expect = require('expectations');
var Promise = require('bluebird');

describe('fetch-retry', function() {

  var fetchRetry;
  var fetch;

  var deferred1;
  var deferred2;
  var deferred3;
  var deferred4;

  var thenCallback;
  var catchCallback;

  var _setTimeout;

  beforeEach(function() {
    _setTimeout = setTimeout;

    setTimeout = function(callback) {
      callback();
    };
    setTimeout = sinon.spy(setTimeout);
  });

  afterEach(function() {
    setTimeout = _setTimeout;
  });

  beforeEach(function() {
    deferred1 = defer();
    deferred2 = defer();
    deferred3 = defer();
    deferred4 = defer();

    fetch = sinon.stub();
    fetch.onCall(0).returns(deferred1.promise);
    fetch.onCall(1).returns(deferred2.promise);
    fetch.onCall(2).returns(deferred3.promise);
    fetch.onCall(3).returns(deferred4.promise);

    var stubs = {
      'isomorphic-fetch': fetch
    };

    fetchRetry = proxyquire('./', stubs);
  });


  describe('#url', function() {

    var expectedUrl = 'http://some-url.com';

    beforeEach(function() {
      fetchRetry(expectedUrl);
    });

    it('passes #url to fetch', function() {
      expect(fetch.getCall(0).args[0]).toBe(expectedUrl);
    });

  });

  describe('#options', function() {

    var expectedOptions = {
      retries: 3,
      whatever: 'something'
    };

    beforeEach(function() {
      fetchRetry('http://someUrl', expectedOptions);
    });

    it('passes #url to fetch', function() {
      expect(fetch.getCall(0).args[1]).toBe(expectedOptions);
    });

  });

  describe('when #options.retries=3 (default)', function() {

    beforeEach(function() {
      thenCallback = sinon.spy();
      catchCallback = sinon.spy();

      fetchRetry('http://someurl')
        .then(thenCallback)
        .catch(catchCallback);
    });

    describe('when first call is a success', function() {

      beforeEach(function() {
        deferred1.resolve();
      });

      describe('when resolved', function() {<commit_msg>fixes copy-paste issue in test description<commit_after>'use strict';
var proxyquire = require('proxyquire').noPreserveCache();
var sinon = require('sinon');
var expect = require('expectations');
var Promise = require('bluebird');

describe('fetch-retry', function() {

  var fetchRetry;
  var fetch;

  var deferred1;
  var deferred2;
  var deferred3;
  var deferred4;

  var thenCallback;
  var catchCallback;

  var _setTimeout;

  beforeEach(function() {
    _setTimeout = setTimeout;

    setTimeout = function(callback) {
      callback();
    };
    setTimeout = sinon.spy(setTimeout);
  });

  afterEach(function() {
    setTimeout = _setTimeout;
  });

  beforeEach(function() {
    deferred1 = defer();
    deferred2 = defer();
    deferred3 = defer();
    deferred4 = defer();

    fetch = sinon.stub();
    fetch.onCall(0).returns(deferred1.promise);
    fetch.onCall(1).returns(deferred2.promise);
    fetch.onCall(2).returns(deferred3.promise);
    fetch.onCall(3).returns(deferred4.promise);

    var stubs = {
      'isomorphic-fetch': fetch
    };

    fetchRetry = proxyquire('./', stubs);
  });


  describe('#url', function() {

    var expectedUrl = 'http://some-url.com';

    beforeEach(function() {
      fetchRetry(expectedUrl);
    });

    it('passes #url to fetch', function() {
      expect(fetch.getCall(0).args[0]).toBe(expectedUrl);
    });

  });

  describe('#options', function() {

    var expectedOptions = {
      retries: 3,
      whatever: 'something'
    };

    beforeEach(function() {
      fetchRetry('http://someUrl', expectedOptions);
    });

    it('passes options to fetch', function() {
      expect(fetch.getCall(0).args[1]).toBe(expectedOptions);
    });

  });

  describe('when #options.retries=3 (default)', function() {

    beforeEach(function() {
      thenCallback = sinon.spy();
      catchCallback = sinon.spy();

      fetchRetry('http://someurl')
        .then(thenCallback)
        .catch(catchCallback);
    });

    describe('when first call is a success', function() {

      beforeEach(function() {
        deferred1.resolve();
      });

      describe('when resolved', function() {
{'fraction_non_alphanumeric': 0.15878220140515223, 'fraction_numerical': 0.010772833723653397, 'mean_word_length': 3.1506316812439263, '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': '3557049', 'n_tokens_mistral': 1367, 'n_tokens_neox': 1311, 'n_words': 247}