mirror of
https://github.com/usebruno/bruno.git
synced 2024-12-23 23:29:47 +01:00
[feat] Add option "--bail" to cli (#1390)
* add bail option to cli * change --bail so that is also bails on request errors (e.g., ECONNREFUSED) * update cli help regarding the ---bail option --------- Co-authored-by: Martin Hoecker <martin.hoecker@sap.com>
This commit is contained in:
parent
c0b5136359
commit
abeccbb182
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user