From 2dc25ebf8c5ecc0f2afa84b8aa390a9f618fa577 Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Sun, 22 May 2022 12:09:53 +0100 Subject: [PATCH] useCloneDeep --- package-lock.json | 3 +-- package.json | 3 ++- ...hc_HaveAGitGat_HandBrake_H264_VeryFast1080p30.js | 11 ++++++----- ...n_a9hc_HaveAGitGat_HandBrake_H264_Fast1080p30.js | 11 ++++++----- .../Tdarr_Plugin_a9he_New_file_size_check.js | 5 +++-- tests/helpers/run.js | 13 +++++-------- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0980d37..76257f9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1178,8 +1178,7 @@ "lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", - "dev": true + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" }, "loupe": { "version": "2.3.4", diff --git a/package.json b/package.json index bde78ca..868cd9e 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "Tdar Plugins Repo", "main": "", "dependencies": { - "chalk": "^4.1.2" + "chalk": "^4.1.2", + "lodash": "^4.17.21" }, "devDependencies": { "chai": "^4.3.6", diff --git a/tests/Community/Tdarr_Plugin_a8hc_HaveAGitGat_HandBrake_H264_VeryFast1080p30.js b/tests/Community/Tdarr_Plugin_a8hc_HaveAGitGat_HandBrake_H264_VeryFast1080p30.js index 4b12e24..805c984 100644 --- a/tests/Community/Tdarr_Plugin_a8hc_HaveAGitGat_HandBrake_H264_VeryFast1080p30.js +++ b/tests/Community/Tdarr_Plugin_a8hc_HaveAGitGat_HandBrake_H264_VeryFast1080p30.js @@ -1,10 +1,11 @@ /* eslint max-len: 0 */ +const _ = require('lodash'); const run = require('../helpers/run'); const tests = [ { input: { - file: require('../sampleData/media/sampleH264_1.json'), + file: _.cloneDeep(require('../sampleData/media/sampleH264_1.json')), librarySettings: {}, inputs: {}, otherArguments: {}, @@ -21,7 +22,7 @@ const tests = [ }, { input: { - file: require('../sampleData/media/sampleH265_1.json'), + file: _.cloneDeep(require('../sampleData/media/sampleH265_1.json')), librarySettings: {}, inputs: {}, otherArguments: {}, @@ -38,11 +39,11 @@ const tests = [ }, { input: { - file: () => { - const file = require('../sampleData/media/sampleH264_1.json'); + file: (() => { + const file = _.cloneDeep(require('../sampleData/media/sampleH264_1.json')); file.meta.Title = undefined; return file; - }, + })(), librarySettings: {}, inputs: {}, otherArguments: {}, diff --git a/tests/Community/Tdarr_Plugin_a9hc_HaveAGitGat_HandBrake_H264_Fast1080p30.js b/tests/Community/Tdarr_Plugin_a9hc_HaveAGitGat_HandBrake_H264_Fast1080p30.js index 0ec4e7f..47cc98c 100644 --- a/tests/Community/Tdarr_Plugin_a9hc_HaveAGitGat_HandBrake_H264_Fast1080p30.js +++ b/tests/Community/Tdarr_Plugin_a9hc_HaveAGitGat_HandBrake_H264_Fast1080p30.js @@ -1,10 +1,11 @@ /* eslint max-len: 0 */ +const _ = require('lodash'); const run = require('../helpers/run'); const tests = [ { input: { - file: require('../sampleData/media/sampleH264_1.json'), + file: _.cloneDeep(require('../sampleData/media/sampleH264_1.json')), librarySettings: {}, inputs: {}, otherArguments: {}, @@ -21,7 +22,7 @@ const tests = [ }, { input: { - file: require('../sampleData/media/sampleH265_1.json'), + file: _.cloneDeep(require('../sampleData/media/sampleH265_1.json')), librarySettings: {}, inputs: {}, otherArguments: {}, @@ -38,11 +39,11 @@ const tests = [ }, { input: { - file: () => { - const file = require('../sampleData/media/sampleH264_1.json'); + file: (() => { + const file = _.cloneDeep(require('../sampleData/media/sampleH264_1.json')); file.meta.Title = undefined; return file; - }, + })(), librarySettings: {}, inputs: {}, otherArguments: {}, diff --git a/tests/Community/Tdarr_Plugin_a9he_New_file_size_check.js b/tests/Community/Tdarr_Plugin_a9he_New_file_size_check.js index e8db045..7e1de0d 100644 --- a/tests/Community/Tdarr_Plugin_a9he_New_file_size_check.js +++ b/tests/Community/Tdarr_Plugin_a9he_New_file_size_check.js @@ -1,4 +1,5 @@ /* eslint max-len: 0 */ +const _ = require('lodash'); const run = require('../helpers/run'); const tests = [ @@ -30,7 +31,7 @@ const tests = [ }, otherArguments: { originalLibraryFile: (() => { - const file = JSON.parse(JSON.stringify(require('../sampleData/media/sampleH264_1.json'))); + const file = _.cloneDeep(require('../sampleData/media/sampleH264_1.json')); file.file_size = 3; return file; })(), @@ -51,7 +52,7 @@ const tests = [ }, otherArguments: { originalLibraryFile: (() => { - const file = JSON.parse(JSON.stringify(require('../sampleData/media/sampleH264_1.json'))); + const file = _.cloneDeep(require('../sampleData/media/sampleH264_1.json')); file.file_size = 0.1; return file; })(), diff --git a/tests/helpers/run.js b/tests/helpers/run.js index e91112e..c4d0525 100644 --- a/tests/helpers/run.js +++ b/tests/helpers/run.js @@ -1,5 +1,6 @@ const path = require('path'); const chai = require('chai'); +const _ = require('lodash'); const scriptName = path.basename(process.mainModule.filename); // eslint-disable-next-line import/no-dynamic-require @@ -11,20 +12,16 @@ const run = async (tests) => { // eslint-disable-next-line no-console console.log(`${scriptName}: test ${i}`); const test = tests[i]; - let { file } = test.input; - if (typeof test.input.file === 'function') { - file = test.input.file(); - } let testOutput; let errorEncountered = false; try { // eslint-disable-next-line no-await-in-loop testOutput = await plugin( - file, - test.input.librarySettings, - test.input.inputs, - test.input.otherArguments, + _.cloneDeep(test.input.file), + _.cloneDeep(test.input.librarySettings), + _.cloneDeep(test.input.inputs), + _.cloneDeep(test.input.otherArguments), ); } catch (err1) { // eslint-disable-next-line no-console