mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-15 18:25:54 -07:00
Run tests in parallel
This commit is contained in:
parent
0ecf11e42c
commit
b52587222b
1 changed files with 50 additions and 26 deletions
|
|
@ -6,45 +6,69 @@ const childProcess = require('child_process');
|
||||||
|
|
||||||
const filenames = fs.readdirSync(`${process.cwd()}/Community`).reverse();
|
const filenames = fs.readdirSync(`${process.cwd()}/Community`).reverse();
|
||||||
|
|
||||||
|
const errorsEncountered = [];
|
||||||
const run = async () => {
|
const run = async () => {
|
||||||
|
const pluginsToRun = [];
|
||||||
for (let i = 0; i < filenames.length; i += 1) {
|
for (let i = 0; i < filenames.length; i += 1) {
|
||||||
const pluginPath = `${process.cwd()}/Community/${filenames[i]}`;
|
const filename = filenames[i];
|
||||||
|
const pluginPath = `${process.cwd()}/Community/${filename}`;
|
||||||
const text = fs.readFileSync(pluginPath);
|
const text = fs.readFileSync(pluginPath);
|
||||||
const pluginTestpath = `${__dirname}/Community/${filenames[i]}`;
|
const pluginTestpath = `${__dirname}/Community/${filename}`;
|
||||||
|
|
||||||
let shouldRunTest = true;
|
|
||||||
if (!text.includes('// tdarrSkipTest') && !fs.existsSync(pluginTestpath)) {
|
if (!text.includes('// tdarrSkipTest') && !fs.existsSync(pluginTestpath)) {
|
||||||
console.log(chalk.red(`${filenames[i]} does not have a test but should do.`));
|
console.log(chalk.red(`${filename} does not have a test but should do.`));
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
} else if (!text.includes('// tdarrSkipTest') && fs.existsSync(pluginTestpath)) {
|
} else if (!text.includes('// tdarrSkipTest') && fs.existsSync(pluginTestpath)) {
|
||||||
console.log(chalk.white(`${filenames[i]} running test`));
|
pluginsToRun.push({
|
||||||
|
filename,
|
||||||
|
pluginTestpath,
|
||||||
|
});
|
||||||
} else if (text.includes('// tdarrSkipTest') && fs.existsSync(pluginTestpath)) {
|
} else if (text.includes('// tdarrSkipTest') && fs.existsSync(pluginTestpath)) {
|
||||||
console.log(chalk.red(`${filenames[i]} should have // tdarrSkipTest removed`));
|
console.log(chalk.red(`${filename} should have // tdarrSkipTest removed`));
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
} else if (text.includes('// tdarrSkipTest') && !fs.existsSync(pluginTestpath)) {
|
} else if (text.includes('// tdarrSkipTest') && !fs.existsSync(pluginTestpath)) {
|
||||||
console.log(chalk.yellow(`${filenames[i]} skipping tests`));
|
console.log(chalk.yellow(`${filename} skipping tests`));
|
||||||
shouldRunTest = false;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (shouldRunTest) {
|
let pluginsFinished = 0;
|
||||||
// eslint-disable-next-line no-await-in-loop
|
for (let i = 0; i < pluginsToRun.length; i += 1) {
|
||||||
await new Promise((resolve) => {
|
const { filename } = pluginsToRun[i];
|
||||||
childProcess.exec(`node "${pluginTestpath}"`, (err, stdout, stderr) => {
|
const { pluginTestpath } = pluginsToRun[i];
|
||||||
if (err) {
|
console.log(chalk.white(`${filename} running test`));
|
||||||
console.log(err);
|
|
||||||
}
|
const output = {};
|
||||||
console.log(stdout);
|
childProcess.exec(`node "${pluginTestpath}"`, (err, stdout, stderr) => {
|
||||||
console.log(chalk.red(stderr));
|
if (err) {
|
||||||
}).on('exit', async (code) => {
|
output.err = err;
|
||||||
if (code !== 0) {
|
}
|
||||||
await new Promise((resolve2) => setTimeout(resolve2, 1000));
|
output.stdout = stdout;
|
||||||
process.exit(1);
|
output.stderr = stderr;
|
||||||
} else {
|
}).on('exit', async (code) => {
|
||||||
resolve();
|
if (code !== 0) {
|
||||||
}
|
await new Promise((resolve2) => setTimeout(resolve2, 1000));
|
||||||
|
errorsEncountered.push({
|
||||||
|
id: filenames[i],
|
||||||
|
...output,
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
}
|
pluginsFinished += 1;
|
||||||
|
|
||||||
|
if (pluginsFinished === pluginsToRun.length) {
|
||||||
|
if (errorsEncountered.length > 0) {
|
||||||
|
errorsEncountered.forEach((plugin) => {
|
||||||
|
console.log(plugin.id);
|
||||||
|
console.log(chalk.red(plugin.err));
|
||||||
|
console.log(plugin.stdout);
|
||||||
|
console.log(chalk.red(plugin.stderr));
|
||||||
|
});
|
||||||
|
process.exit(1);
|
||||||
|
} else {
|
||||||
|
console.log(chalk.green('No errors encountered!'));
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue