From 51e0ea2c2d17e5fffdc62c1d576ff047541b619b Mon Sep 17 00:00:00 2001 From: Anoop M D Date: Sun, 30 Apr 2023 12:08:23 +0530 Subject: [PATCH] feat(#155): exit process with non zero code when tests or assertions fail --- packages/bruno-cli/src/commands/run.js | 28 ++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/packages/bruno-cli/src/commands/run.js b/packages/bruno-cli/src/commands/run.js index 80900bbd3..325ced567 100644 --- a/packages/bruno-cli/src/commands/run.js +++ b/packages/bruno-cli/src/commands/run.js @@ -35,6 +35,15 @@ const printRunSummary = (assertionResults, testResults) => { console.log("\n" + chalk.bold(assertSummary)); console.log(chalk.bold(testSummary)); + + return { + totalAssertions, + passedAssertions, + failedAssertions, + totalTests, + passedTests, + failedTests + } }; const getBruFilesRecursively = (dir) => { @@ -45,6 +54,10 @@ const getBruFilesRecursively = (dir) => { const traverse = (currentPath) => { const filesInCurrentDir = fs.readdirSync(currentPath); + + if (currentPath.includes('node_modules')) { + return; + } for (const file of filesInCurrentDir) { const filePath = path.join(currentPath, file); @@ -170,8 +183,14 @@ const handler = async function (argv) { testResults } = result; - printRunSummary(assertionResults, testResults); + const summary = printRunSummary(assertionResults, testResults); console.log(chalk.dim(chalk.grey('Done.'))); + + if(summary.failedAssertions > 0 || summary.failedTests > 0) { + process.exit(1); + } + } else { + process.exit(1); } } @@ -226,12 +245,17 @@ const handler = async function (argv) { } } - printRunSummary(assertionResults, testResults); + const summary = printRunSummary(assertionResults, testResults); console.log(chalk.dim(chalk.grey('Ran all requests.'))); + + if(summary.failedAssertions > 0 || summary.failedTests > 0) { + process.exit(1); + } } } catch (err) { console.log("Something went wrong"); console.error(chalk.red(err.message)); + process.exit(1); } };