From b1815667d65d0012ab62d6ca499be9ef988e10fa Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Mon, 23 May 2022 07:34:19 +0100 Subject: [PATCH] Add os based tests --- ...de audio and video with HW (PC and Mac).js | 50 +++++---- ...Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js | 101 ++++++++++++------ tests/helpers/run.js | 74 +++++++------ 3 files changed, 142 insertions(+), 83 deletions(-) diff --git a/tests/Community/Tdarr_Plugin_ER01_Transcode audio and video with HW (PC and Mac).js b/tests/Community/Tdarr_Plugin_ER01_Transcode audio and video with HW (PC and Mac).js index c725079..e31024c 100644 --- a/tests/Community/Tdarr_Plugin_ER01_Transcode audio and video with HW (PC and Mac).js +++ b/tests/Community/Tdarr_Plugin_ER01_Transcode audio and video with HW (PC and Mac).js @@ -11,17 +11,20 @@ const tests = [ otherArguments: {}, }, output: { - container: '.mkv', - processFile: true, - preset: ', -sn -map 0:v -c:v copy -b:v 758k -minrate 530k -maxrate 985k -bufsize 1517k -map 0:a -c:a copy ', - handBrakeMode: false, - FFmpegMode: true, - reQueueAfter: true, - infoLog: 'Converting video, NOT resizing. 720p, h264 --> 720p, hevc. bitrate = 1517 --> 758, multiplier 0.5. \n' - + 'Not converting audio. \n' - + '2 channels - \n' - + '6 channels - und aac \n' - + '8 channels - ', + win32: { + container: '.mkv', + processFile: true, + preset: ', -sn -map 0:v -c:v hevc_qsv -load_plugin hevc_hw -b:v 758k -minrate 530k -maxrate 985k -bufsize 1517k -map 0:a -c:a copy ', + handBrakeMode: false, + FFmpegMode: true, + reQueueAfter: true, + infoLog: 'Converting video, NOT resizing. 720p, h264 --> 720p, hevc. bitrate = 1517 --> 758, multiplier 0.5. \n' + + 'Not converting audio. \n' + + '2 channels - \n' + + '6 channels - und aac \n' + + '8 channels - ', + }, + linux: undefined, }, }, { @@ -70,17 +73,20 @@ const tests = [ otherArguments: {}, }, output: { - container: '.mkv', - processFile: true, - preset: ', -sn -map 0:v -c:v copy -b:v 3933k -minrate 2753k -maxrate 5112k -bufsize 7866k -map 0:a -c:a copy ', - handBrakeMode: false, - FFmpegMode: true, - reQueueAfter: true, - infoLog: 'Converting video, NOT resizing. 1080p, h264 --> 1080p, hevc. bitrate = 7866 --> 3933, multiplier 0.5. \n' - + 'Not converting audio. \n' - + '2 channels - eng flac \n' - + '6 channels - \n' - + '8 channels - ', + win32: { + container: '.mkv', + processFile: true, + preset: ', -sn -map 0:v -c:v hevc_qsv -load_plugin hevc_hw -b:v 3933k -minrate 2753k -maxrate 5112k -bufsize 7866k -map 0:a -c:a copy ', + handBrakeMode: false, + FFmpegMode: true, + reQueueAfter: true, + infoLog: 'Converting video, NOT resizing. 1080p, h264 --> 1080p, hevc. bitrate = 7866 --> 3933, multiplier 0.5. \n' + + 'Not converting audio. \n' + + '2 channels - eng flac \n' + + '6 channels - \n' + + '8 channels - ', + }, + linux: undefined, }, }, { diff --git a/tests/Community/Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js b/tests/Community/Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js index 336f2f0..9f3498d 100644 --- a/tests/Community/Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js +++ b/tests/Community/Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js @@ -11,21 +11,40 @@ const tests = [ otherArguments: {}, }, output: { - processFile: true, - preset: '-fflags +genpts -hwaccel qsv -c:v h264_qsv -map 0 -c:v hevc_qsv -b:v 759k -minrate 569k -maxrate 949k -bufsize 1517k -preset slow \n' - + ' -c:a copy -c:s copy -max_muxing_queue_size 9999 ', - handBrakeMode: false, - FFmpegMode: true, - reQueueAfter: true, - infoLog: '☑ It looks like the current bitrate is 1517k. \n' - + '\n' - + 'Container for output selected as mkv. \n' - + 'Encode variable bitrate settings: \n' - + 'Target = 759k \n' - + 'Minimum = 569k \n' - + 'Maximum = 949k \n' - + 'File Transcoding... \n', - container: '.mkv', + linux: { + processFile: true, + preset: '-fflags +genpts -hwaccel qsv -c:v h264_qsv -map 0 -c:v hevc_qsv -b:v 759k -minrate 569k -maxrate 949k -bufsize 1517k -preset slow \n' + + ' -c:a copy -c:s copy -max_muxing_queue_size 9999 ', + handBrakeMode: false, + FFmpegMode: true, + reQueueAfter: true, + infoLog: '☑ It looks like the current bitrate is 1517k. \n' + + '\n' + + 'Container for output selected as mkv. \n' + + 'Encode variable bitrate settings: \n' + + 'Target = 759k \n' + + 'Minimum = 569k \n' + + 'Maximum = 949k \n' + + 'File Transcoding... \n', + container: '.mkv', + }, + win32: { + processFile: true, + preset: '-fflags +genpts -hwaccel qsv -c:v h264_qsv -map 0 -c:v hevc_qsv -load_plugin hevc_hw -b:v 759k -minrate 569k -maxrate 949k -bufsize 1517k -preset slow \n' + + ' -c:a copy -c:s copy -max_muxing_queue_size 9999 ', + handBrakeMode: false, + FFmpegMode: true, + reQueueAfter: true, + infoLog: '☑ It looks like the current bitrate is 1517k. \n' + + '\n' + + 'Container for output selected as mkv. \n' + + 'Encode variable bitrate settings: \n' + + 'Target = 759k \n' + + 'Minimum = 569k \n' + + 'Maximum = 949k \n' + + 'File Transcoding... \n', + container: '.mkv', + }, }, }, { @@ -40,22 +59,42 @@ const tests = [ otherArguments: {}, }, output: { - processFile: true, - preset: '-fflags +genpts -hwaccel qsv -map 0 -c:v hevc_qsv -b:v 759k -minrate 569k -maxrate 949k -bufsize 1517k -preset fast \n' - + ' -c:a copy -c:s copy -max_muxing_queue_size 9999 -profile:v main10 -pix_fmt p010le ', - handBrakeMode: false, - FFmpegMode: true, - reQueueAfter: true, - infoLog: '☑ It looks like the current bitrate is 1517k. \n' - + '10 bit encode enabled. Setting Main10 Profile & 10 bit pixel format \n' - + '\n' - + 'Container for output selected as mp4. \n' - + 'Encode variable bitrate settings: \n' - + 'Target = 759k \n' - + 'Minimum = 569k \n' - + 'Maximum = 949k \n' - + 'File Transcoding... \n', - container: '.mp4', + linux: { + processFile: true, + preset: '-fflags +genpts -hwaccel qsv -map 0 -c:v hevc_qsv -b:v 759k -minrate 569k -maxrate 949k -bufsize 1517k -preset fast \n' + + ' -c:a copy -c:s copy -max_muxing_queue_size 9999 -profile:v main10 -pix_fmt p010le ', + handBrakeMode: false, + FFmpegMode: true, + reQueueAfter: true, + infoLog: '☑ It looks like the current bitrate is 1517k. \n' + + '10 bit encode enabled. Setting Main10 Profile & 10 bit pixel format \n' + + '\n' + + 'Container for output selected as mp4. \n' + + 'Encode variable bitrate settings: \n' + + 'Target = 759k \n' + + 'Minimum = 569k \n' + + 'Maximum = 949k \n' + + 'File Transcoding... \n', + container: '.mp4', + }, + win32: { + processFile: true, + preset: '-fflags +genpts -hwaccel qsv -map 0 -c:v hevc_qsv -load_plugin hevc_hw -b:v 759k -minrate 569k -maxrate 949k -bufsize 1517k -preset fast \n' + + ' -c:a copy -c:s copy -max_muxing_queue_size 9999 -profile:v main10 -pix_fmt p010le ', + handBrakeMode: false, + FFmpegMode: true, + reQueueAfter: true, + infoLog: '☑ It looks like the current bitrate is 1517k. \n' + + '10 bit encode enabled. Setting Main10 Profile & 10 bit pixel format \n' + + '\n' + + 'Container for output selected as mp4. \n' + + 'Encode variable bitrate settings: \n' + + 'Target = 759k \n' + + 'Minimum = 569k \n' + + 'Maximum = 949k \n' + + 'File Transcoding... \n', + container: '.mp4', + }, }, }, { diff --git a/tests/helpers/run.js b/tests/helpers/run.js index 58b6e05..70a61bb 100644 --- a/tests/helpers/run.js +++ b/tests/helpers/run.js @@ -2,6 +2,7 @@ const path = require('path'); const chai = require('chai'); const _ = require('lodash'); const importFresh = require('import-fresh'); +const os = require('os'); const scriptName = path.basename(process.mainModule.filename); @@ -12,37 +13,50 @@ const run = async (tests) => { console.log(`${scriptName}: test ${i}`); const test = tests[i]; - let testOutput; - let errorEncountered = false; - // eslint-disable-next-line import/no-dynamic-require - const { plugin } = importFresh(`../../Community/${scriptName}`); - - try { - // eslint-disable-next-line no-await-in-loop - testOutput = await plugin( - _.cloneDeep(test.input.file), - _.cloneDeep(test.input.librarySettings), - _.cloneDeep(test.input.inputs), - _.cloneDeep(test.input.otherArguments), - ); - } catch (err1) { - errorEncountered = err1; - } - - if (test.outputModify) { - testOutput = test.outputModify(test.output); - } - - if (test.error && test.error.shouldThrow) { - if (errorEncountered !== false) { - // eslint-disable-next-line no-console - console.log(errorEncountered); - chai.assert.deepEqual(errorEncountered.message, test.output); - } else { - throw new Error('Expected plugin error but none was thrown!'); - } + let expectedOutput; + if (test.output[os.platform()]) { + expectedOutput = test.output[os.platform()]; } else { - chai.assert.deepEqual(testOutput, test.output); + expectedOutput = test.output; + } + + if (expectedOutput === undefined) { + // skip test due to OS + // eslint-disable-next-line no-console + console.log(`Test not meant to run on ${os.platform()}, skipping`); + } else { + let testOutput; + let errorEncountered = false; + // eslint-disable-next-line import/no-dynamic-require + const { plugin } = importFresh(`../../Community/${scriptName}`); + + try { + // eslint-disable-next-line no-await-in-loop + testOutput = await plugin( + _.cloneDeep(test.input.file), + _.cloneDeep(test.input.librarySettings), + _.cloneDeep(test.input.inputs), + _.cloneDeep(test.input.otherArguments), + ); + } catch (err1) { + errorEncountered = err1; + } + + if (test.outputModify) { + testOutput = test.outputModify(testOutput); + } + + if (test.error && test.error.shouldThrow) { + if (errorEncountered !== false) { + // eslint-disable-next-line no-console + console.log(errorEncountered); + chai.assert.deepEqual(errorEncountered.message, expectedOutput); + } else { + throw new Error('Expected plugin error but none was thrown!'); + } + } else { + chai.assert.deepEqual(testOutput, expectedOutput); + } } } } catch (err) {