From ffb9c86a7fcf67a5a58d0490147ac4d432849dbf Mon Sep 17 00:00:00 2001 From: snobu Date: Tue, 1 Oct 2019 10:00:07 +0300 Subject: [PATCH] Added browser test --- .github/workflows/build.yaml | 1 + destreamer.ts | 37 +++++++++++++++++++++++++++++++----- package.json | 3 ++- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 568cf38..dfcde9c 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -24,5 +24,6 @@ jobs: run: | npm install tsc --listEmittedFiles + npm test env: CI: true diff --git a/destreamer.ts b/destreamer.ts index bb64f86..1b2bca9 100644 --- a/destreamer.ts +++ b/destreamer.ts @@ -3,6 +3,7 @@ import puppeteer from 'puppeteer'; import { terminal as term } from 'terminal-kit'; import fs from 'fs'; import path from 'path'; +import { AssertionError } from 'assert'; // Type in your username here (the one you use to @@ -15,7 +16,7 @@ const outputDirectory: string = 'videos'; function sanityChecks() { try { const ytdlVer = execSync('youtube-dl --version'); - term.green(`\nUsing youtube-dl version ${ytdlVer}`); + term.green(`Using youtube-dl version ${ytdlVer}\n`); } catch (e) { console.error('You need youtube-dl in $PATH for this to work. Make sure it is a relatively recent one, baked after 2019.'); @@ -25,7 +26,7 @@ function sanityChecks() { try { const ffmpegVer = execSync('ffmpeg -version') .toString().split('\n')[0]; - term.green(`\nUsing ffmpeg version ${ffmpegVer}`); + term.green(`Using ffmpeg version ${ffmpegVer}\n`); } catch (e) { console.error('FFmpeg is missing. You need a fairly recent release of FFmpeg in $PATH.'); @@ -38,12 +39,30 @@ function sanityChecks() { } if (args[0] == null || args[0].length < 10) { - console.error('Pass in video URL as first argument: \n' + + console.error('Pass in video URL as first argument:\n' + 'Example: npm start https://www.microsoftstream.com/video/6f1a382b-e20c-44c0-98fc-5608286e48bc\n'); process.exit(-1); } } +async function runBrowserTest() { + console.log('[BROWSER TEST] Launching headless Chrome...'); + const browser = await puppeteer.launch({ + // Switch to false if you need to login interactively + headless: true, + args: ['--disable-dev-shm-usage'] + }); + const page = await browser.newPage(); + await page.goto("https://github.com/", { waitUntil: 'networkidle2' }); + let pageTitle = await page.title(); + await browser.close(); + if (!pageTitle.includes('GitHub')) + { + process.exit(44); + } + console.log('[BROWSER TEST] PASS'); +} + async function rentVideoForLater() { console.log('Launching headless Chrome to perform the OpenID Connect dance...'); const browser = await puppeteer.launch({ @@ -126,5 +145,13 @@ async function exfiltrateCookie(page: puppeteer.Page) { return `Authorization=${authzCookie.value}; Signature=${sigCookie.value}`; } -sanityChecks(); -rentVideoForLater(); \ No newline at end of file +// We should probably use Mocha or something +if (args[0] === 'test') +{ + runBrowserTest(); +} + +else { + sanityChecks(); + rentVideoForLater(); +} \ No newline at end of file diff --git a/package.json b/package.json index 81a01f3..a7eca66 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "", "main": "destreamer.js", "scripts": { - "start": "echo Transpiling TypeScript to JavaScript... && tsc && node ./destreamer.js" + "start": "echo Transpiling TypeScript to JavaScript... && tsc && node ./destreamer.js", + "test": "node ./destreamer.js test" }, "keywords": [], "author": "",