Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Add option "--bail" to cli #1390

Merged
merged 3 commits into from
Jan 29, 2024
Merged
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
19 changes: 18 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 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')
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,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) {
Expand Down