mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-28 23:24:05 +00:00
* feat: add options to skip request and response bodies in reporter output - Introduced `--reporter-skip-request-body` and `--reporter-skip-response-body` flags to omit respective bodies from the reporter output. - Updated examples in the CLI documentation to reflect new options. - Refactored result sanitization to handle new flags. * feat: add shorthand option to skip both request and response bodies in reporter output - Introduced `--reporter-skip-body` as a shorthand for omitting both request and response bodies from the reporter output. - Updated CLI documentation examples to include the new shorthand option. - Adjusted result sanitization to accommodate the new option. * refactor: simplify documentation and tests for reporter-skip-body option - Updated the description of the `--reporter-skip-body` option to remove redundancy. - Removed outdated shorthand references from the test suite for clarity. - Cleaned up examples in the CLI documentation to focus on the current functionality. * fix: handle optional chaining for request and response properties in result sanitization - Updated the `sanitizeResultsForReporter` function to use optional chaining when accessing request and response headers and data. - This change prevents potential errors when these properties are undefined. * test: enhance reporter-skip-body tests for JSON and HTML outputs - Added comprehensive tests for the `--reporter-skip-request-body` and `--reporter-skip-response-body` options in both JSON and HTML report formats. - Verified that the appropriate request and response bodies are included or excluded based on the specified flags. - Improved test coverage for scenarios where both flags are used simultaneously. * fix: remove optional chaining for request and response headers in result sanitization - Updated the `sanitizeResultsForReporter` function to directly assign empty objects to request and response headers, ensuring consistent behavior regardless of their initial state. - This change simplifies the code and maintains functionality for skipping headers.
46 lines
1.1 KiB
JavaScript
46 lines
1.1 KiB
JavaScript
const deleteHeaderIfExists = (headers, header) => {
|
|
Object.keys(headers).forEach((key) => {
|
|
if (key.toLowerCase() === header.toLowerCase()) {
|
|
delete headers[key];
|
|
}
|
|
});
|
|
};
|
|
|
|
const sanitizeResultsForReporter = (results, { skipAllHeaders = false, skipHeaders = [], skipRequestBody = false, skipResponseBody = false } = {}) => {
|
|
if (skipAllHeaders) {
|
|
results.forEach((result) => {
|
|
result.request.headers = {};
|
|
result.response.headers = {};
|
|
});
|
|
}
|
|
|
|
if (skipHeaders?.length) {
|
|
results.forEach((result) => {
|
|
if (result.request?.headers) {
|
|
skipHeaders.forEach((header) => {
|
|
deleteHeaderIfExists(result.request.headers, header);
|
|
});
|
|
}
|
|
if (result.response?.headers) {
|
|
skipHeaders.forEach((header) => {
|
|
deleteHeaderIfExists(result.response.headers, header);
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
if (skipRequestBody) {
|
|
results.forEach((result) => {
|
|
delete result.request?.data;
|
|
});
|
|
}
|
|
|
|
if (skipResponseBody) {
|
|
results.forEach((result) => {
|
|
delete result.response?.data;
|
|
});
|
|
}
|
|
};
|
|
|
|
module.exports = { sanitizeResultsForReporter };
|