diff --git a/packages/bruno-cli/src/commands/run.js b/packages/bruno-cli/src/commands/run.js index 56cb0b035..db726bbdd 100644 --- a/packages/bruno-cli/src/commands/run.js +++ b/packages/bruno-cli/src/commands/run.js @@ -200,6 +200,10 @@ const builder = async (yargs) => { type: 'boolean', description: 'Allow insecure server connections' }) + .option('bail', { + type: 'boolean', + description: 'Stop execution after a failure of a request, test, or assertion' + }) .example('$0 run request.bru', 'Run a request') .example('$0 run request.bru --env local', 'Run a request with the environment set to local') .example('$0 run folder', 'Run all requests in a folder') @@ -220,7 +224,7 @@ const builder = async (yargs) => { const handler = async function (argv) { try { - let { filename, cacert, env, envVar, insecure, r: recursive, output: outputPath, format } = argv; + let { filename, cacert, env, envVar, insecure, r: recursive, output: outputPath, format, bail } = argv; const collectionPath = process.cwd(); // todo @@ -292,6 +296,9 @@ const handler = async function (argv) { } const options = getOptions(); + if (bail) { + options['bail'] = true; + } if (insecure) { options['insecure'] = true; } @@ -395,6 +402,16 @@ const handler = async function (argv) { suitename: bruFilepath.replace('.bru', '') }); + // bail if option is set and there is a failure + if (bail) { + const requestFailure = result?.error; + const testFailure = result?.testResults?.find((iter) => iter.status === 'fail'); + const assertionFailure = result?.assertionResults?.find((iter) => iter.status === 'fail'); + if (requestFailure || testFailure || assertionFailure) { + break; + } + } + // determine next request const nextRequestName = result?.nextRequestName; if (nextRequestName !== undefined) {