This repository was archived by the owner on Nov 28, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathtest.js
More file actions
112 lines (96 loc) · 2.66 KB
/
test.js
File metadata and controls
112 lines (96 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
Name: youtube-feeds
Description: Test script for youtube-feeds.js
Source: https://github.com/fvdm/nodejs-youtube
Feedback: https://github.com/fvdm/nodejs-youtube/issues
License: Public Domain / Unlicense (see UNLICENSE file)
*/
var util = require ('util');
// Setup
var app = require ('./');
app.httpProtocol = process.env.YOUTUBE_PROTOCOL || 'http';
app.timeout = process.env.YOUTUBE_TIMEOUT || 5000;
app.developerKey = process.env.YOUTUBE_KEY || null;
// handle exits
var errors = 0;
process.on ('exit', function () {
if (errors === 0) {
console.log ('\n\033[1mDONE, no errors.\033[0m\n');
process.exit (0);
} else {
console.log ('\n\033[1mFAIL, '+ errors +' error'+ (errors > 1 ? 's' : '') +' occurred!\033[0m\n');
process.exit (1);
}
});
// prevent errors from killing the process
process.on ('uncaughtException', function (err) {
console.log ();
console.error (err.stack);
console.trace ();
console.log ();
errors++;
});
// Queue to prevent flooding
var queue = [];
var next = 0;
function doNext () {
next++;
if (queue[next]) {
queue[next] ();
}
}
// doTest( passErr, 'methods', [
// ['feeds', typeof feeds === 'object']
// ])
function doTest (err, label, tests) {
if (err instanceof Error) {
console.error (label +': \033[1m\033[31mERROR\033[0m\n');
console.error (util.inspect (err, {depth: 10, colors: true}));
console.log ();
console.error (err.stack);
console.log ();
errors++;
} else {
var testErrors = [];
tests.forEach (function (test) {
if (test[1] !== true) {
testErrors.push (test[0]);
errors++;
}
});
if (testErrors.length === 0) {
console.log (label +': \033[1m\033[32mok\033[0m');
} else {
console.error (label +': \033[1m\033[31mfailed\033[0m ('+ testErrors.join (', ') +')');
}
}
doNext ();
}
queue.push (function () {
app.feeds.videos ({q: 'ShouldNotExists_'+ Date.now()}, function (err, data) {
doTest (null, 'Error: not found', [
['type', err && err instanceof Error],
['message', err && err.message === 'not found'],
['data', data && data.totalItems === 0]
]);
});
});
queue.push (function () {
app.video (0, function (err) {
doTest (null, 'Error: invalid id', [
['type', err && err instanceof Error],
['message', err && err.message === 'invalid id']
]);
});
});
queue.push (function () {
app.feeds.videos ({q: 'cheetah'}, function (err, data) {
doTest (err, 'feeds.videos', [
['type', data instanceof Object],
['prop', typeof data.itemsPerPage === 'number']
]);
});
});
// Start the tests
console.log ('Running tests...\n');
queue[0] ();