I need some help with the following code:
const ffmpeg = require('fluent-ffmpeg'),
{PassThrough} = require('stream');
ffmpeg.setFfmpegPath('/opt/bin/ffmpeg');
ffmpeg.setFfprobePath('/opt/bin/ffprobe');
exports.wavCompilation = async (wavObjList, s3OutputFullPath) => {
let command = ffmpeg();
return new Promise(async (resolve, reject) => {
const pt = new PassThrough()
command
.complexFilter(complexFilterList)
.audioFrequency(44100)
.audioChannels(2)
.outputOptions('-map [audio]')
.toFormat("wav")
.output(pt, {end: true})
.on('error', function (err, stdout, stderr) {
console.log("stdout:\n" + stdout);
console.log("stderr:\n" + stderr);
if (err) {
console.log(err.message);
return reject("Error");
}
})
.on('start', (commandLog) => printLog(commandLog))
.on(`end`, () => console.info("end ffmpeg"))
.run()
resolve(***);
});
}
Does anyone know how can I stub/mock/spy/fake "ffmpeg" ?
I use Sinon for unit tests and I'm trying to use proxyquire to mock "fluent-ffmpeg"
const sinon = require('sinon'),
proxyquire = require('proxyquire').noCallThru();
let ffmpegStub = {
setFfmpegPath: () => {},
setFfprobePath: () => {}
}
const ffmpegService = proxyquire('../services/ffmpeg-service/index', {
'fluent-ffmpeg': ffmpegStub
});
for the methods setFfmpegPath and setFfprobePath it works but for the line:
let command = ffmpeg();
it says "ffmpeg is not a function"
I tried to add a default function such as:
let ffmpegStub = {
default: () => {},
setFfmpegPath: () => {},
setFfprobePath: () => {}
}
but it also doesn't work and I have no idea now what I could do.
Please I need some fresh ideas, my goal is to catch the argument for "complexFilter" and assert it.