youtube integration tests -> unit
This commit is contained in:
parent
473e17b037
commit
1bd64eed52
|
@ -15,28 +15,18 @@ async function downloadThumbnail(youtubeid, downloadDir, overlayImg) {
|
|||
console.log(` -- downloading YouTube ${youtubeid} thumb...`)
|
||||
const fStream = createWriteStream(dlLoc)
|
||||
|
||||
|
||||
const done = new Promise(function(resolve, reject) {
|
||||
fStream.on('finish', () => {
|
||||
var args = [
|
||||
"-resize",
|
||||
"700x400",
|
||||
dlLoc,
|
||||
"+repage",
|
||||
"+page",
|
||||
overlayImg,
|
||||
"-flatten",
|
||||
dlLoc
|
||||
"-resize", "700x400", dlLoc,
|
||||
"+repage", "+page", overlayImg, "-flatten", dlLoc
|
||||
]
|
||||
//console.log(`convert ${args}`)
|
||||
im.convert(args, function(err) {
|
||||
if(err) reject(err)
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
fStream.on('error', () => {
|
||||
unlinkSync(dlLoc)
|
||||
reject()
|
||||
})
|
||||
|
||||
youtubedl(`https://www.youtube.com/watch?v=${youtubeid}`, {
|
||||
getThumb: true,
|
||||
|
@ -46,8 +36,13 @@ async function downloadThumbnail(youtubeid, downloadDir, overlayImg) {
|
|||
got.stream(url).pipe(fStream)
|
||||
})
|
||||
.catch(err => {
|
||||
unlinkSync(dlLoc)
|
||||
reject(err)
|
||||
// What the fuck. destroy() does not release: https://github.com/nodejs/node/issues/31776
|
||||
fStream.end()
|
||||
fStream.destroy()
|
||||
fStream.on('close', () => {
|
||||
if(existsSync(dlLoc)) unlinkSync(dlLoc)
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
|
||||
const stubimg = "https://brainbaking.com//img/avatar.jpg"
|
||||
|
||||
function youtubedl(url, options) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
if(url.indexOf("exception") >= 0) {
|
||||
console.log("STUB exception wanted, here you go ==>")
|
||||
reject("BOOM")
|
||||
}
|
||||
|
||||
resolve(stubimg)
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = youtubedl
|
|
@ -6,6 +6,7 @@ const { getFiles } = require('../../src/file-utils');
|
|||
|
||||
const dumpdir = `${__dirname}/youtubeposts-stub`
|
||||
|
||||
jest.mock('youtube-dl-exec')
|
||||
jest.disableAutomock()
|
||||
jest.unmock('got')
|
||||
|
||||
|
@ -43,7 +44,7 @@ title: "wizardry 8 review"
|
|||
|
||||
here's a post
|
||||
|
||||
{{< youtube lol >}}
|
||||
{{< youtube exception >}}
|
||||
|
||||
tsjek it out nog ene
|
||||
|
||||
|
|
Loading…
Reference in New Issue