1
0
mirror of https://github.com/snobu/destreamer.git synced 2026-01-19 06:22:18 +00:00
Files
destreamer-mirror/test/test.ts
kylon 9faa0c4846 Added ffmpeg progress bar via fluent-ffmpeg and progress libs (#57)
* Add fluent-ffmpeg back and cross-platform progress bar

* Repo clean up

Move ts files to src, build and output js files to build folder

* Do not print messages when exit code is 0

this is triggered by signal events

Co-authored-by: kylon <kylonux@gmail.com>
2020-04-11 16:12:46 +03:00

68 lines
2.6 KiB
TypeScript

import { parseVideoUrls } from '../src/utils';
import puppeteer from 'puppeteer';
import assert from 'assert';
import tmp from 'tmp';
import fs from 'fs';
let browser: any;
let page: any;
before(async () => {
browser = await puppeteer.launch({
headless: true,
args: ['--disable-dev-shm-usage']
});
page = await browser.newPage();
});
describe('Puppeteer', () => {
it('should grab GitHub page title', async () => {
await page.goto("https://github.com/", { waitUntil: 'networkidle2' });
let pageTitle = await page.title();
assert.equal(true, pageTitle.includes('GitHub'));
}).timeout(15000); // yeah, this may take a while...
});
after(async () => {
await browser.close();
});
describe('Destreamer', () => {
it('should parse and sanitize URL list from file', () => {
const testIn: string[] = [
"https://web.microsoftstream.com/video/xxxxxxxx-zzzz-hhhh-rrrr-dddddddddddd",
"https://web.microsoftstream.com/video/xxxxxxxx-zzzz-hhhh-rrrr-dddddddddddd?",
"https://web.microsoftstream.com/video/xxxxxxxx-zzzz-hhhh-rrrr-dddddddddddd&",
"",
"https://web.microsoftstream.com/video/xxxxxxxx-zzzz-hhhh-rrrr-dddddddddddd?a=b&c",
"https://web.microsoftstream.com/video/xxxxxxxx-zzzz-hhhh-rrrr-dddddddddddd?a",
"https://web.microsoftstream.com/video/xxxxxxxx-zzzz-hhhh-rrrr-dddddddddd",
"https://web.microsoftstream.com/video/xxxxxx-zzzz-hhhh-rrrr-dddddddddddd",
""
];
const expectedOut: string[] = [
"https://web.microsoftstream.com/video/xxxxxxxx-zzzz-hhhh-rrrr-dddddddddddd",
"https://web.microsoftstream.com/video/xxxxxxxx-zzzz-hhhh-rrrr-dddddddddddd",
"https://web.microsoftstream.com/video/xxxxxxxx-zzzz-hhhh-rrrr-dddddddddddd?a=b&c",
"https://web.microsoftstream.com/video/xxxxxxxx-zzzz-hhhh-rrrr-dddddddddddd?a"
];
const tmpFile = tmp.fileSync({ postfix: '.txt' });
let testOut: string[];
fs.writeFileSync(tmpFile.fd, testIn.join('\r\n'));
testOut = parseVideoUrls([tmpFile.name])!;
if (testOut.length !== expectedOut.length)
assert.strictEqual(testOut, expectedOut, "URL list not sanitized");
for (let i=0, l=testOut.length; i<l; ++i) {
if (testOut[i] !== expectedOut[i])
assert.strictEqual(testOut[i], expectedOut[i], "URL not sanitized");
}
assert.ok("sanitizeUrls ok");
});
});