Merge pull request #3467 from Pragadesh-45/feat/cli-improvements

feat: add option to omit headers and skip specific headers in CLI run command output
This commit is contained in:
lohit 2024-11-21 20:56:16 +05:30 committed by GitHub
commit fb8c54dd7a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -264,6 +264,16 @@ const builder = async (yargs) => {
type: 'boolean', type: 'boolean',
description: 'Stop execution after a failure of a request, test, or assertion' description: 'Stop execution after a failure of a request, test, or assertion'
}) })
.option('reporter-skip-all-headers', {
type: 'boolean',
description: 'Omit headers from the reporter output',
default: false
})
.option('reporter-skip-headers', {
type: 'array',
description: 'Skip specific headers from the reporter output',
default: []
})
.option('client-cert-config', { .option('client-cert-config', {
type: 'string', type: 'string',
description: 'Path to the Client certificate config file used for securing the connection in the request' description: 'Path to the Client certificate config file used for securing the connection in the request'
@ -273,6 +283,11 @@ const builder = async (yargs) => {
.example('$0 run request.bru --env local', 'Run a request with the environment set to local') .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') .example('$0 run folder', 'Run all requests in a folder')
.example('$0 run folder -r', 'Run all requests in a folder recursively') .example('$0 run folder -r', 'Run all requests in a folder recursively')
.example('$0 run --reporter-skip-all-headers', 'Run all requests in a folder recursively with omitted headers from the reporter output')
.example(
'$0 run --reporter-skip-headers "Authorization"',
'Run all requests in a folder recursively with skipped headers from the reporter output'
)
.example( .example(
'$0 run request.bru --env local --env-var secret=xxx', '$0 run request.bru --env local --env-var secret=xxx',
'Run a request with the environment set to local and overwrite the variable secret with value xxx' 'Run a request with the environment set to local and overwrite the variable secret with value xxx'
@ -325,6 +340,8 @@ const handler = async function (argv) {
sandbox, sandbox,
testsOnly, testsOnly,
bail, bail,
reporterSkipAllHeaders,
reporterSkipHeaders,
clientCertConfig clientCertConfig
} = argv; } = argv;
const collectionPath = process.cwd(); const collectionPath = process.cwd();
@ -576,6 +593,35 @@ const handler = async function (argv) {
suitename: bruFilepath.replace('.bru', '') suitename: bruFilepath.replace('.bru', '')
}); });
if (reporterSkipAllHeaders) {
results.forEach((result) => {
result.request.headers = {};
result.response.headers = {};
});
}
const deleteHeaderIfExists = (headers, header) => {
if (headers && headers[header]) {
delete headers[header];
}
};
if (reporterSkipHeaders?.length) {
results.forEach((result) => {
if (result.request?.headers) {
reporterSkipHeaders.forEach((header) => {
deleteHeaderIfExists(result.request.headers, header);
});
}
if (result.response?.headers) {
reporterSkipHeaders.forEach((header) => {
deleteHeaderIfExists(result.response.headers, header);
});
}
});
}
// bail if option is set and there is a failure // bail if option is set and there is a failure
if (bail) { if (bail) {
const requestFailure = result?.error; const requestFailure = result?.error;