<commit_before>var browserEnv = typeof window === 'object';

if (browserEnv) {
  mocha.setup('bdd');
  mocha.setup({
    globals: [
      'setTimeout', 'setInterval', 'clearTimeout', 'clearInterval',
      'XMLHttpRequest'
    ]
  });
} else {
  var sinon = require('sinon');
  var chai = require('chai');
  var sinonDoublist = require('../build/build');
}

var should = chai.should();
chai.Assertion.includeStack = true;

describe('sinon-doublist', function() {
  'use strict';

  beforeEach(function(done) {
    sinonDoublist(sinon, this);
    done();
  });

  afterEach(function(done) {
    this.sandbox.restore();
    done();
  });

  describe('mixin', function() {
    it('should respect auto-sandbox opt-out', function(testDone) {
      var test = {};
      sinonDoublist(sinon, test, true);
      should.not.exist(test.sandbox);
      testDone();
    });
  });

  describe('#_createSandbox()', function() {
    it('should mix in new sandbox', function(testDone) {
      should.exist(this.spy);
      should.exist(this.stub);
      should.exist(this.mock);
      should.exist(this.clock);
      if (browserEnv) {
        should.exist(this.server);
        should.exist(this.requests);
      }
      testDone();
    });

    it('should init fake server', function(testDone) {
      if (!browserEnv) { testDone(); return; }
      var payload = {foo: 'bar'};
      var url = '/res';
      jQuery.ajax({
        url: url,
        success: function(response) {
          response.should.deep.equal(payload);
          testDone();
        }
      });
      this.server.respond([
          200,
          {'Content-Type': 'application/json'},
          JSON.stringify(payload)
        ]
      );
      this.requests.length.should.equal(1);
      this.request[0].url.should.equal(url);
    });
  });

  describe('#restoreSandbox()', function() {
    it('should restore sandbox', function(testDone) {
      var realCalled = false;
      var obj = {fn: function() { realCalled = true; }};
      this.stubMany(obj, 'fn');
      obj.fn();
      realCalled.should.equal(false);
      this.restoreSandbox();<commit_msg>Fix typo/race-condition in requests test<commit_after>var browserEnv = typeof window === 'object';

if (browserEnv) {
  mocha.setup('bdd');
  mocha.setup({
    globals: [
      'setTimeout', 'setInterval', 'clearTimeout', 'clearInterval',
      'XMLHttpRequest'
    ]
  });
} else {
  var sinon = require('sinon');
  var chai = require('chai');
  var sinonDoublist = require('../build/build');
}

var should = chai.should();
chai.Assertion.includeStack = true;

describe('sinon-doublist', function() {
  'use strict';

  beforeEach(function(done) {
    sinonDoublist(sinon, this);
    done();
  });

  afterEach(function(done) {
    this.sandbox.restore();
    done();
  });

  describe('mixin', function() {
    it('should respect auto-sandbox opt-out', function(testDone) {
      var test = {};
      sinonDoublist(sinon, test, true);
      should.not.exist(test.sandbox);
      testDone();
    });
  });

  describe('#_createSandbox()', function() {
    it('should mix in new sandbox', function(testDone) {
      should.exist(this.spy);
      should.exist(this.stub);
      should.exist(this.mock);
      should.exist(this.clock);
      if (browserEnv) {
        should.exist(this.server);
        should.exist(this.requests);
      }
      testDone();
    });

    it('should init fake server', function(testDone) {
      if (!browserEnv) { testDone(); return; }
      var payload = {foo: 'bar'};
      var url = '/res';
      var self = this;
      jQuery.ajax({
        url: url,
        success: function(response) {
          response.should.deep.equal(payload);
          self.requests.length.should.equal(1);
          self.requests[0].url.should.equal(url);
          testDone();
        }
      });
      this.server.respond([
          200,
          {'Content-Type': 'application/json'},
          JSON.stringify(payload)
        ]
      );
    });
  });

  describe('#restoreSandbox()', function() {
    it('should restore sandbox', function(testDone) {
      var realCalled = false;
      var obj = {fn: function() { realCalled = true; }};
      this.stubMany(obj, 'fn');
      obj.fn();
      realCalled.should.equal(false);
      this.restoreSandbox();
{'fraction_non_alphanumeric': 0.16725064237327728, 'fraction_numerical': 0.00233590282644242, 'mean_word_length': 2.607413647851727, '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': '1719576', 'n_tokens_mistral': 1384, 'n_tokens_neox': 1360, 'n_words': 250}