<commit_before>var fs     = require('fs');
var path   = require('path');
var rewire = require('rewire');
var chai   = require('chai');
var expect = chai.expect;

// setup promise
chai.use(require('chai-as-promised'));

// mock console.log from getAudio
var getAudio = rewire('../src/getAudio');
getAudio.__set__({
  console: {
    log: function () {}
  }
});

function removeAudio () {
  fs.readdirSync(__dirname).forEach(function (file) {
    if (/.mp3$/.test(file)) {
      fs.unlinkSync(__dirname + '/' + file);
    }
  });
}

describe('Get Audio', function() {
  before(removeAudio);
  after(removeAudio);

  it('test', function () {
    var word = 'test';
    return expect(getAudio(word, __dirname)).to.eventually.equal(
      path.resolve(__dirname, 'test.mp3')
    );
  });

  it('Hello', function () {
    var word = 'Hello';
    return expect(getAudio(word, __dirname)).to.eventually.equal(
      path.resolve(__dirname, 'hello.mp3')
    );
  });

  it('hello (Audio is already exist, so it should return immediately)', function () {
    this.timeout(100);
    var word = 'hello';
    return expect(getAudio(word, __dirname)).to.eventually.equal(
      path.resolve(__dirname, 'hello.mp3')
    );
  });

  it('testing (from webster)', function () {
    var word = 'testing';
    return expect(getAudio(word, __dirname, 'webster')).to.eventually.be.rejected;
  });

  it('test-drive', function () {
    var word = 'test-drive';
    return expect(getAudio(word, __dirname, 'collins')).to.be.rejectedWith(Error);
  });

  it('testing (from google)', function () {
    var word = 'testing';
    return expect(getAudio(word, __dirname, 'google')).to.eventually.equal(
      path.resolve(__dirname, 'testing.mp3')
    );
  });

  it('Hello_World (from google)', function () {
    var word = 'Hello_World';
    return expect(getAudio(word, __dirname, 'google')).to.eventually.equal(
      path.resolve(__dirname, 'hello_world.mp3')
    );
  });

  it('hello world (Audio is already exist, so it should return immediately)', function () {
    this.timeout(100);
    var word = 'hello world';
    return expect(getAudio(word, __dirname)).to.eventually.equal(
      path.resolve(__dirname, 'hello_world.mp3')
    );<commit_msg>[test] add test case with download failure<commit_after>var fs     = require('fs');
var path   = require('path');
var rewire = require('rewire');
var chai   = require('chai');
var expect = chai.expect;

// setup promise
chai.use(require('chai-as-promised'));

// mock console.log from getAudio
var getAudio = rewire('../src/getAudio');
getAudio.__set__({
  console: {
    log: function () {}
  }
});

function removeAudio () {
  fs.readdirSync(__dirname).forEach(function (file) {
    if (/.mp3$/.test(file)) {
      fs.unlinkSync(__dirname + '/' + file);
    }
  });
}

describe('Get Audio', function() {
  before(removeAudio);
  after(removeAudio);

  it('test', function () {
    var word = 'test';
    return expect(getAudio(word, __dirname)).to.eventually.equal(
      path.resolve(__dirname, 'test.mp3')
    );
  });

  it('Hello', function () {
    var word = 'Hello';
    return expect(getAudio(word, __dirname)).to.eventually.equal(
      path.resolve(__dirname, 'hello.mp3')
    );
  });

  it('hello (Audio is already exist, so it should return immediately)', function () {
    this.timeout(100);
    var word = 'hello';
    return expect(getAudio(word, __dirname)).to.eventually.equal(
      path.resolve(__dirname, 'hello.mp3')
    );
  });

  it('testing (from webster)', function () {
    var word = 'testing';
    return expect(getAudio(word, __dirname, 'webster')).to.eventually.be.rejected;
  });

  it('test-drive', function () {
    var word = 'test-drive';
    return expect(getAudio(word, __dirname, 'collins')).to.be.rejectedWith(Error);
  });

  it('basilosaurus (download failure)', function () {
    var word = 'basilosaurus';
    return expect(getAudio(word, __dirname, 'yahoo')).to.be.rejectedWith(Error);
  });

  it('testing (from google)', function () {
    var word = 'testing';
    return expect(getAudio(word, __dirname, 'google')).to.eventually.equal(
      path.resolve(__dirname, 'testing.mp3')
    );
  });

  it('Hello_World (from google)', function () {
    var word = 'Hello_World';
    return expect(getAudio(word, __dirname, 'google')).to.eventually.equal(
      path.resolve(__dirname, 'hello_world.mp3')
    );
  });

  it('hello world (Audio is already exist, so it should return immediately)', function () {
    this.timeout(100);
    var word = 'hello world';
    return expect(getAudio(word, __dirname)).to.eventually.equal(
      path.resolve(__dirname, 'hello_world.mp3')
    );
{'fraction_non_alphanumeric': 0.17396907216494845, 'fraction_numerical': 0.005584192439862543, 'mean_word_length': 3.6200396825396823, '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': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6296558', 'n_tokens_mistral': 1512, 'n_tokens_neox': 1489, 'n_words': 317}