Permalink
Browse files

added tests

  • Loading branch information...
1 parent 68199c0 commit 1377915463ab2f46ae593aec4c82da8b523473bc @fent fent committed Sep 16, 2011
Showing with 73 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +1 −0 .npmignore
  3. +45 −0 test/download.js
  4. +26 −0 test/info.js
View
@@ -1 +1,2 @@
*.mp4
+*.webm
View
@@ -1 +1,2 @@
*.mp4
+*.webm
View
@@ -0,0 +1,45 @@
+var vows = require('vows')
+ ytdl = require('./../lib/youtube-dl'),
+ fs = require('fs'),
+ path = require('path'),
+ assert = require('assert'),
+ 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);
+ dl.on('end', function(data) {
+ cb(null, data);
+ });
+ },
+
+ 'data returned': function(err, data) {
+ assert.include(data, 'filename');
+ assert.isString(data.filename);
+ assert.include(data, 'size');
+ assert.isString(data.size);
+ assert.include(data, 'timeTakenms');
+ assert.isNumber(data.timeTakenms);
+ assert.include(data, 'timeTaken');
+ assert.isString(data.timeTaken);
+ assert.include(data, 'averageSpeedBytes');
+ assert.isNumber(data.averageSpeedBytes);
+ assert.include(data, 'averageSpeed');
+ assert.isString(data.averageSpeed);
+ },
+
+ 'file was downloaded': function(err, data) {
+ // check existance
+ var filepath = __dirname + '/' + data.filename;
+ assert.isTrue(path.existsSync(filepath));
+
+ // delete file after each test
+ fs.unlinkSync(filepath);
+ }
+ }
+}).export(module);
View
@@ -0,0 +1,26 @@
+var vows = require('vows')
+ ytdl = require('./../lib/youtube-dl'),
+ assert = require('assert'),
+ video = 'http://www.youtube.com/watch?v=90AiXO1pAiA';
+
+
+vows.describe('info').addBatch({
+ 'from a video': {
+ 'topic': function() {
+ ytdl.info(video, this.callback);
+ },
+
+ 'info returned': function(err, info) {
+ assert.include(info, 'title');
+ assert.isString(info.title);
+ assert.include(info, 'url');
+ assert.isString(info.url);
+ assert.include(info, 'thumbnail');
+ assert.isString(info.thumbnail);
+ assert.include(info, 'description');
+ assert.isString(info.description);
+ assert.include(info, 'filename');
+ assert.isString(info.filename);
+ }
+ }
+}).export(module);

0 comments on commit 1377915

Please sign in to comment.