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

Added a new hideRequestBody flag #261

Merged
merged 1 commit into from
Aug 23, 2020
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

-----------------------------------------------------------------------

## [1.19.0] - 2020-08-23

### Added

- Added a new `hideRequestBody` flag to allow you _hide_ a specific request body from the final report

### Changed

- Changed the `hideResponse` flag to `hideResponseBody` to make it more descriptive

-----------------------------------------------------------------------

## [1.18.0] - 2020-08-19

### Fixed
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ To use `htmlextra` as a library, install the package as a dependency into a `nod
npm install -S newman-reporter-htmlextra
```

To install `nodejs`, `newman` and the `htmlextra` packages together, use this command (adding your own collection file) to run it using the `Docker` image:
To install `node`, `newman` and the `htmlextra` packages together, use this command to pull the `Docker` image:

```console
docker run -t -v $(pwd):/etc/newman dannydainton/htmlextra run collection.json -r htmlextra
docker pull dannydainton/htmlextra
```

---
Expand All @@ -80,7 +80,8 @@ newman run collection.json -r htmlextra
| `--reporter-htmlextra-title` | This optional flag can be used to give your report a different main `Title` in the centre of the report. If this is not set, the report will show "Newman Run Dashboard". | `newman run collection.json -r htmlextra --reporter-htmlextra-title "My Newman Report"`|
| `--reporter-htmlextra-titleSize` | An optional flag to reduce the size of the main report title. The sizes range from `1` to `6`, the higher the number, the smaller the title will be. The default size is `2`. | `newman run collection.json -r htmlextra --reporter-htmlextra-titleSize 4`|
| `--reporter-htmlextra-logs` | This optional flag shows any console log statements in the collection, on the final report. This is `false` by default. | `newman run collection.json -r htmlextra --reporter-htmlextra-logs`|
| `--reporter-htmlextra-hideResponse` | An optional flag which allows you to exclude certain `Response Bodies` from the final report. Enter the name of the request that you wish to hide. | `newman run collection.json -r htmlextra --reporter-htmlextra-hideResponse "Auth Request"`|
| `--reporter-htmlextra-hideRequestBody` | An optional flag which allows you to exclude certain `Request Bodies` from the final report. Enter the name of the request that you wish to hide. | `newman run collection.json -r htmlextra --reporter-htmlextra-hideRequestBody "Login"`|
| `--reporter-htmlextra-hideResponseBody` | An optional flag which allows you to exclude certain `Response Bodies` from the final report. Enter the name of the request that you wish to hide. | `newman run collection.json -r htmlextra --reporter-htmlextra-hideResponse "Auth Request"`|
| `--reporter-htmlextra-showEnvironmentData` | An optional flag which allows you to show all the `Environment` variables used during the run, in the final report | `newman run collection.json -r htmlextra --reporter-htmlextra-showEnvironmentData`|
| `--reporter-htmlextra-skipEnvironmentVars` | An optional flag which allows you to exclude certain `Environment` variables from the final report | `newman run collection.json -r htmlextra --reporter-htmlextra-skipEnvironmentVars "API_KEY"`|
| `--reporter-htmlextra-showGlobalData` | An optional flag which allows you to show all the `Global` variables used during the run, in the final report | `newman run collection.json -r htmlextra --reporter-htmlextra-showGlobalData`|
Expand All @@ -93,8 +94,6 @@ newman run collection.json -r htmlextra
| `--reporter-htmlextra-showFolderDescription` | An optional flag which allows you to show all the folder descriptions, in the final report | `newman run collection.json -r htmlextra --reporter-htmlextra-showFolderDescription`|
| `--reporter-htmlextra-timezone` | An optional flag which allows you to set the timezone on the final report's timestamp | `newman run collection.json -r htmlextra --reporter-htmlextra-timezone "Australia/Sydney"`|

Custom templates can be passed to the `htmlextra` reporter via the `--reporter-htmlextra-template <path>` flag. The [default template](./lib/dashboard-template.hbs) is used in all other cases.

---

#### With Newman as a Library
Expand All @@ -118,7 +117,7 @@ To enable the functionality of a given feature, uncomment any of the options wit
const newman = require('newman');

newman.run({
collection: './pathToFile/collection.json',
collection: './pathToFile/collection.json', // Collection URL from a public link or the Postman API can also be used
reporters: ['htmlextra'],
iterationCount: 1,
reporter: {
Expand All @@ -134,7 +133,8 @@ newman.run({
// titleSize: 4,
// omitHeaders: true,
// skipHeaders: "Authorization",
// hideResponse: ["Auth Request"],
// hideRequestBody: ["Login"],
// hideResponseBody: ["Auth Request"],
// showEnvironmentData: true,
// skipEnvironmentVars: ["API_KEY"],
// showGlobalData: true,
Expand Down
26 changes: 24 additions & 2 deletions lib/dashboard-template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,10 @@ table.dataTable td, table.dataTable tr {
</div>
{{/unless}}
{{/unless}}
{{/with}}
{{#unless @root.skipSensitiveData}}
{{#isNotIn item.name @root.hideRequestBody}}
{{#with request}}
{{#if body.raw}}
<div class="row">
<div class="col-sm-12 mb-3">
Expand All @@ -945,6 +948,12 @@ table.dataTable td, table.dataTable tr {
</div>
</div>
{{/if}}
{{/with}}
{{/isNotIn}}
{{/unless}}
{{#unless @root.skipSensitiveData}}
{{#isNotIn item.name @root.hideRequestBody}}
{{#with request}}
{{#if body.formdata.members}}
<div class="row">
<div class="col-sm-12 mb-3">
Expand All @@ -964,6 +973,12 @@ table.dataTable td, table.dataTable tr {
</div>
</div>
{{/if}}
{{/with}}
{{/isNotIn}}
{{/unless}}
{{#unless @root.skipSensitiveData}}
{{#isNotIn item.name @root.hideRequestBody}}
{{#with request}}
{{#if body.urlencoded.members}}
<div class="row">
<div class="col-sm-12 mb-3">
Expand All @@ -983,6 +998,12 @@ table.dataTable td, table.dataTable tr {
</div>
</div>
{{/if}}
{{/with}}
{{/isNotIn}}
{{/unless}}
{{#unless @root.skipSensitiveData}}
{{#isNotIn item.name @root.hideRequestBody}}
{{#with request}}
{{#if body.graphql}}
<div class="row">
<div class="col-sm-12 mb-3">
Expand All @@ -1008,8 +1029,9 @@ table.dataTable td, table.dataTable tr {
</div>
</div>
{{/if}}
{{/unless}}
{{/with}}
{{/isNotIn}}
{{/unless}}
{{#unless @root.omitHeaders}}
{{#unless @root.skipSensitiveData}}
<div class="row">
Expand Down Expand Up @@ -1043,7 +1065,7 @@ table.dataTable td, table.dataTable tr {
{{/unless}}
{{/unless}}
{{#unless @root.skipSensitiveData}}
{{#isNotIn item.name @root.hideResponse}}
{{#isNotIn item.name @root.hideResponseBody}}
<div class="row">
<div class="col-sm-12 mb-3">
<div class="card-deck">
Expand Down
8 changes: 6 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ PostmanHTMLExtraReporter = function (newman, options, collectionRunOptions) {
else if (list.length !== undefined) {
list = list.toLowerCase()
}
let convertedElem = elem.toLowerCase()

if (elem !== undefined) {
var convertedElem = elem.toLowerCase()
}

if (_.includes(list, convertedElem)) {
return options.inverse(this);
Expand Down Expand Up @@ -327,7 +330,8 @@ PostmanHTMLExtraReporter = function (newman, options, collectionRunOptions) {
skipHeaders: options.skipHeaders || [],
skipEnvironmentVars: options.skipEnvironmentVars || [],
skipGlobalVars: options.skipGlobalVars || [],
hideResponse: options.hideResponse || [],
hideRequestBody: options.hideRequestBody || [],
hideResponseBody: options.hideResponseBody || [],
showEnvironmentData: options.showEnvironmentData || false,
showGlobalData: options.showGlobalData || false,
skipSensitiveData: options.skipSensitiveData || false,
Expand Down
64 changes: 43 additions & 21 deletions lib/only-failures-dashboard.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,35 @@ table.dataTable td, table.dataTable tr {
</div>
{{/unless}}
{{/unless}}
{{/with}}
{{#unless @root.skipSensitiveData}}
{{#isNotIn item.name @root.hideRequestBody}}
{{#with request}}
{{#if body.raw}}
<div class="row">
<div class="col-sm-12 mb-3">
<div class="card-deck">
<div class="card border-info" style="width: 50rem;">
<div class="card-body">
<h5 class="card-title text-uppercase text-white text-center bg-info">Request Body</h5>
<div class="dyn-height">
<pre><code id="copyReqText-{{@key}}" class="prettyPrint">{{body.raw}}</code></pre>
</div>
<div class="card-footer">
<button class="btn btn-outline-secondary btn-sm copyButton" type="button" data-clipboard-action="copy" data-clipboard-target="#copyReqText-{{@key}}">Copy to Clipboard</button>
</div>
</div>
</div>
</div>
</div>
</div>
{{/if}}
{{/with}}
{{/isNotIn}}
{{/unless}}
{{#unless @root.skipSensitiveData}}
{{#isNotIn item.name @root.hideRequestBody}}
{{#with request}}
{{#if body.formdata.members}}
<div class="row">
<div class="col-sm-12 mb-3">
Expand All @@ -936,25 +964,12 @@ table.dataTable td, table.dataTable tr {
</div>
</div>
{{/if}}
{{#if body.raw}}
<div class="row">
<div class="col-sm-12 mb-3">
<div class="card-deck">
<div class="card border-info" style="width: 50rem;">
<div class="card-body">
<h5 class="card-title text-uppercase text-white text-center bg-info">Request Body</h5>
<div class="dyn-height">
<pre><code class="prettyPrint">{{body.raw}}</code></pre>
</div>
<div id="copyReqText-{{@key}}" class="card-footer">
<button class="btn btn-outline-secondary btn-sm copyButton" type="button" data-clipboard-action="copy" data-clipboard-target="#copyReqText-{{@key}}">Copy to Clipboard</button>
</div>
</div>
</div>
</div>
</div>
</div>
{{/if}}
{{/with}}
{{/isNotIn}}
{{/unless}}
{{#unless @root.skipSensitiveData}}
{{#isNotIn item.name @root.hideRequestBody}}
{{#with request}}
{{#if body.urlencoded.members}}
<div class="row">
<div class="col-sm-12 mb-3">
Expand All @@ -974,6 +989,12 @@ table.dataTable td, table.dataTable tr {
</div>
</div>
{{/if}}
{{/with}}
{{/isNotIn}}
{{/unless}}
{{#unless @root.skipSensitiveData}}
{{#isNotIn item.name @root.hideRequestBody}}
{{#with request}}
{{#if body.graphql}}
<div class="row">
<div class="col-sm-12 mb-3">
Expand All @@ -999,8 +1020,9 @@ table.dataTable td, table.dataTable tr {
</div>
</div>
{{/if}}
{{/unless}}
{{/with}}
{{/isNotIn}}
{{/unless}}
{{#unless @root.omitHeaders}}
{{#unless @root.skipSensitiveData}}
<div class="row">
Expand Down Expand Up @@ -1034,7 +1056,7 @@ table.dataTable td, table.dataTable tr {
{{/unless}}
{{/unless}}
{{#unless @root.skipSensitiveData}}
{{#isNotIn item.name @root.hideResponse}}
{{#isNotIn item.name @root.hideResponseBody}}
<div class="row">
<div class="col-sm-12 mb-3">
<div class="card-deck">
Expand Down
39 changes: 20 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "newman-reporter-htmlextra",
"version": "1.18.0",
"version": "1.19.0",
"description": "A newman reporter with added handlebars helpers and separated request iterations",
"main": "index.js",
"preferGlobal": true,
Expand Down Expand Up @@ -33,7 +33,7 @@
"lodash": "^4.17.20",
"moment-timezone": "^0.5.31",
"pretty-ms": "^6.0.1",
"snyk": "^1.380.0"
"snyk": "^1.381.2"
},
"author": "Danny Dainton",
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion test/integration/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ describe('Newman and htmlextra run from the CLI', function () {
});
it('should correctly generate the html report when a request name is not specified', function (done) {
// eslint-disable-next-line max-len
exec(`${newman} run test/requests/simple-get-request.json -r htmlextra --reporter-htmlextra-export ${outFile} --reporter-htmlextra-hideResponse`,
exec(`${newman} run test/requests/simple-get-request.json -r htmlextra --reporter-htmlextra-export ${outFile} --reporter-htmlextra-hideResponseBody`,
function (code) {
expect(code, 'should have exit code of 0').to.equal(0);
fs.stat(outFile, done);
Expand Down