mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-30 09:55:18 +00:00
tests: throw an error if one or more tests fail
This commit is contained in:
@@ -6,27 +6,34 @@ const NToken = require('../lib/NToken');
|
||||
const SigDecipher = require('../lib/Sig');
|
||||
const Constants = require('./constants');
|
||||
|
||||
let failed_tests = 0;
|
||||
|
||||
async function performTests() {
|
||||
const youtube = await new Innertube().catch((error) => error);
|
||||
assert(youtube instanceof Error ? false : true, `should retrieve Innertube configuration data`);
|
||||
|
||||
const search = await youtube.search('Carl Sagan - Documentary').catch((error) => error);
|
||||
assert((search instanceof Error ? false : true) && search.videos.length >= 1, `should search videos`);
|
||||
|
||||
const details = await youtube.getDetails(Constants.test_video_id).catch((error) => error);
|
||||
assert(details instanceof Error ? false : true, `should retrieve details for ${Constants.test_video_id}`);
|
||||
|
||||
const comments = await youtube.getComments(Constants.test_video_id).catch((error) => error);
|
||||
assert(comments instanceof Error ? false : true, `should retrieve comments for ${Constants.test_video_id}`);
|
||||
|
||||
const video = await downloadVideo(Constants.test_video_id_1, youtube).catch((error) => error);
|
||||
assert(video instanceof Error ? false : true, `should download video (${Constants.test_video_id_1})`);
|
||||
|
||||
if (!(youtube instanceof Error)) {
|
||||
const search = await youtube.search('Carl Sagan - Documentary').catch((error) => error);
|
||||
assert((search instanceof Error ? false : true) && search.videos.length >= 1, `should search videos`);
|
||||
|
||||
const details = await youtube.getDetails(Constants.test_video_id).catch((error) => error);
|
||||
assert(details instanceof Error ? false : true, `should retrieve details for ${Constants.test_video_id}`);
|
||||
|
||||
const comments = await youtube.getComments(Constants.test_video_id).catch((error) => error);
|
||||
assert(comments instanceof Error ? false : true, `should retrieve comments for ${Constants.test_video_id}`);
|
||||
|
||||
const video = await downloadVideo(Constants.test_video_id_1, youtube).catch((error) => error);
|
||||
assert(video instanceof Error ? false : true, `should download video (${Constants.test_video_id_1})`);
|
||||
}
|
||||
|
||||
const n_token = new NToken(Constants.n_scramble_sc).transform(Constants.original_ntoken);
|
||||
assert(n_token == Constants.expected_ntoken, `should transform n token into ${Constants.expected_ntoken}`);
|
||||
|
||||
const transformed_url = new SigDecipher(Constants.test_url, Constants.client_version, { sig_decipher_sc: Constants.sig_decipher_sc, ntoken_sc: Constants.n_scramble_sc }).decipher();
|
||||
assert(transformed_url == Constants.expected_url, `should correctly decipher signature`);
|
||||
|
||||
if (failed_tests > 0)
|
||||
throw new Error('Some tests have failed');
|
||||
}
|
||||
|
||||
function downloadVideo(id, youtube) {
|
||||
@@ -40,8 +47,9 @@ function downloadVideo(id, youtube) {
|
||||
});
|
||||
}
|
||||
|
||||
function assert(outcome, description) {
|
||||
const pass_fail = outcome ? 'pass' : 'fail';
|
||||
function assert(outcome, description) {
|
||||
const pass_fail = outcome ? 'pass' : 'fail';
|
||||
!outcome && (failed_tests += 1);
|
||||
console.info(pass_fail, ':', description);
|
||||
return outcome;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user