mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-11 00:10:29 -07:00
Add os based tests
This commit is contained in:
parent
ad646d04b5
commit
b1815667d6
3 changed files with 142 additions and 83 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue