Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 26 additions & 11 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();

Expand Down Expand Up @@ -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: ${
Expand Down
7 changes: 7 additions & 0 deletions lib/thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Expand Down