diff --git a/lib/cli.js b/lib/cli.js index f616e8c..c2519ae 100755 --- a/lib/cli.js +++ b/lib/cli.js @@ -6,7 +6,11 @@ const path = require('path'); const fs = require('fs-extra'); const { settings } = require('./settings'); -const { getTestSuitePaths, distributeTestsByWeight, getMaxPathLenghtFrom } = require('./test-suites'); +const { + getTestSuitePaths, + distributeTestsByWeight, + getMaxPathLenghtFrom +} = require('./test-suites'); const { formatTime, generateWeightsFile, @@ -15,25 +19,29 @@ const { const { executeThread } = require('./thread'); const { resultsPath } = require('./shared-config'); -function cleanResultsPath() { - if(!fs.existsSync(resultsPath)) { - fs.mkdirSync(resultsPath, { recursive: true }) +function cleanResultsPath() { + if (!fs.existsSync(resultsPath)) { + fs.mkdirSync(resultsPath, { recursive: true }); } else { fs.readdir(resultsPath, (err, files) => { - if (err) console.log(err); - for (const file of files) { - fs.unlink(path.join(resultsPath, file), err => { if (err) console.log(err); }); - } - }); - } + if (err) console.log(err); + for (const file of files) { + fs.unlink(path.join(resultsPath, file), (err) => { + if (err) console.log(err); + }); + } + }); } +} async function start() { cleanResultsPath(); const testSuitePaths = await getTestSuitePaths(); const threads = distributeTestsByWeight(testSuitePaths); const start = new Date(); - await Promise.all(threads.map(executeThread)); + const failedResults = ( + await Promise.allSettled(threads.map(executeThread)) + ).filter(({ status }) => status === 'rejected'); const end = new Date(); const timeTaken = end.getTime() - start.getTime(); @@ -117,6 +125,13 @@ async function start() { process.exit(1); } + if (failedResults.length > 0) { + process.stderr.write( + `\x1b[31m${failedResults.length} thread(s) exited with errors\n` + ); + process.exit(1); + } + const timeSaved = totalDuration - timeTaken; console.log( `Total run time: ${totalDuration / 1000}s, executed in: ${ diff --git a/lib/thread.js b/lib/thread.js index 70db2bd..7cbdb49 100644 --- a/lib/thread.js +++ b/lib/thread.js @@ -109,6 +109,13 @@ async function executeThread(thread, index) { process.exit(exitCode); } } + + if (exitCode !== 0) { + console.error(`Thread ${index} failed with exit code: ${exitCode}`); + + reject(exitCode); + } + resolve(timeMap); }); });