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...`)
|
console.log(` -- downloading YouTube ${youtubeid} thumb...`)
|
||||||
const fStream = createWriteStream(dlLoc)
|
const fStream = createWriteStream(dlLoc)
|
||||||
|
|
||||||
|
|
||||||
const done = new Promise(function(resolve, reject) {
|
const done = new Promise(function(resolve, reject) {
|
||||||
fStream.on('finish', () => {
|
fStream.on('finish', () => {
|
||||||
var args = [
|
var args = [
|
||||||
"-resize",
|
"-resize", "700x400", dlLoc,
|
||||||
"700x400",
|
"+repage", "+page", overlayImg, "-flatten", dlLoc
|
||||||
dlLoc,
|
|
||||||
"+repage",
|
|
||||||
"+page",
|
|
||||||
overlayImg,
|
|
||||||
"-flatten",
|
|
||||||
dlLoc
|
|
||||||
]
|
]
|
||||||
//console.log(`convert ${args}`)
|
|
||||||
im.convert(args, function(err) {
|
im.convert(args, function(err) {
|
||||||
if(err) reject(err)
|
if(err) reject(err)
|
||||||
resolve()
|
resolve()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
fStream.on('error', () => {
|
|
||||||
unlinkSync(dlLoc)
|
|
||||||
reject()
|
|
||||||
})
|
|
||||||
|
|
||||||
youtubedl(`https://www.youtube.com/watch?v=${youtubeid}`, {
|
youtubedl(`https://www.youtube.com/watch?v=${youtubeid}`, {
|
||||||
getThumb: true,
|
getThumb: true,
|
||||||
|
@ -46,8 +36,13 @@ async function downloadThumbnail(youtubeid, downloadDir, overlayImg) {
|
||||||
got.stream(url).pipe(fStream)
|
got.stream(url).pipe(fStream)
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
unlinkSync(dlLoc)
|
// What the fuck. destroy() does not release: https://github.com/nodejs/node/issues/31776
|
||||||
reject(err)
|
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`
|
const dumpdir = `${__dirname}/youtubeposts-stub`
|
||||||
|
|
||||||
|
jest.mock('youtube-dl-exec')
|
||||||
jest.disableAutomock()
|
jest.disableAutomock()
|
||||||
jest.unmock('got')
|
jest.unmock('got')
|
||||||
|
|
||||||
|
@ -43,7 +44,7 @@ title: "wizardry 8 review"
|
||||||
|
|
||||||
here's a post
|
here's a post
|
||||||
|
|
||||||
{{< youtube lol >}}
|
{{< youtube exception >}}
|
||||||
|
|
||||||
tsjek it out nog ene
|
tsjek it out nog ene
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue