Skip to content

Commit

Permalink
add bail option to cli
Browse files Browse the repository at this point in the history
  • Loading branch information
mjhcorporate committed Jan 15, 2024
1 parent b5fccef commit d067451
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion packages/bruno-cli/src/commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ const builder = async (yargs) => {
type: 'boolean',
description: 'Allow insecure server connections'
})
.option('bail', {
type: 'boolean',
description: 'Stop execution after first test or assertion failure'
})
.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')
Expand All @@ -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
Expand Down Expand Up @@ -292,6 +296,9 @@ const handler = async function (argv) {
}

const options = getOptions();
if (bail) {
options['bail'] = true;
}
if (insecure) {
options['insecure'] = true;
}
Expand Down Expand Up @@ -395,6 +402,15 @@ const handler = async function (argv) {
suitename: bruFilepath.replace('.bru', '')
});

// bail if option is set and there is a failure
if (bail) {
const testFailure = result?.testResults?.find((iter) => iter.status === 'fail');
const assertionFailure = result?.assertionResults?.find((iter) => iter.status === 'fail');
if (testFailure || assertionFailure) {
break;
}
}

// determine next request
const nextRequestName = result?.nextRequestName;
if (nextRequestName !== undefined) {
Expand Down

0 comments on commit d067451

Please sign in to comment.