<commit_before>var vows       = require('vows');
var ytdl       = require('..');
var fs         = require('fs');
var path       = require('path');
var existsSync = require('fs').existsSync;
var assert     = require('assert');
var video      = 'http://www.youtube.com/watch?v=90AiXO1pAiA';


vows.describe('download').addBatch({
  'a video': {
    'topic': function() {
        var dl = ytdl.download(video, __dirname),
            cb = this.callback;

        dl.on('error', cb);

        var progress;
        dl.on('progress', function(data) {
          progress = data;
        });

        dl.on('end', function(data) {
          cb(null, progress, data);
        });
      },

    'data returned': function(err, progress, data) {
      if (err) throw err;

      assert.isObject(progress);
      assert.isString(progress.percent);
      assert.isString(progress.speed);
      assert.isString(progress.eta);

      assert.isObject(data);
      assert.equal(data.id, '90AiXO1pAiA');
      assert.equal(data.filename, 'lol-90AiXO1pAiA.flv');
      assert.equal(data.size, '1.26MiB');
      assert.isNumber(data.timeTakenms);
      assert.isString(data.timeTaken);
      assert.isNumber(data.averageSpeedBytes);
      assert.isString(data.averageSpeed);
    },

    'file was downloaded': function(err, progress, data) {
      if (err) throw err;

      process.nextTick(function() {
        // Delete file after each test.
        fs.unlink(filepath);
      });

      // Check existance.
      var filepath = path.join(__dirname, data.filename);
      assert.isTrue(existsSync(filepath));
    }
  }
}).export(module);<commit_msg>make sure to delete downloaded file<commit_after>var vows       = require('vows');
var ytdl       = require('..');
var fs         = require('fs');
var path       = require('path');
var assert     = require('assert');
var video      = 'http://www.youtube.com/watch?v=90AiXO1pAiA';


vows.describe('download').addBatch({
  'a video': {
    'topic': function() {
        var dl = ytdl.download(video, __dirname),
            cb = this.callback;

        dl.on('error', cb);

        var progress;
        dl.on('progress', function(data) {
          progress = data;
        });

        dl.on('end', function(data) {
          cb(null, progress, data);
        });
      },

    'data returned': function(err, progress, data) {
      if (err) throw err;

      assert.isObject(progress);
      assert.isString(progress.percent);
      assert.isString(progress.speed);
      assert.isString(progress.eta);

      assert.isObject(data);
      assert.equal(data.id, '90AiXO1pAiA');
      assert.isTrue(/lol-90AiXO1pAiA/.test(data.filename));
      assert.equal(data.size, '1.26MiB');
      assert.isNumber(data.timeTakenms);
      assert.isString(data.timeTaken);
      assert.isNumber(data.averageSpeedBytes);
      assert.isString(data.averageSpeed);
    },

    'file was downloaded': function(err, progress, data) {
      if (err) throw err;

      // Check existance.
      var filepath = path.join(__dirname, data.filename);
      var exists = fs.existsSync(filepath);
      if (exists) {
        // Delete file after each test.
        fs.unlinkSync(filepath);
      } else {
        assert.isTrue(exists);
      }
    }
  }
}).export(module);
{'fraction_non_alphanumeric': 0.15288373512358866, 'fraction_numerical': 0.00732377174244736, 'mean_word_length': 2.432460732984293, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6565203', 'n_tokens_mistral': 1075, 'n_tokens_neox': 1036, 'n_words': 193}