Skip to content

Commit

Permalink
Aggregated assertion information, cleaned up styling on tables
Browse files Browse the repository at this point in the history
  • Loading branch information
kunagpal committed Aug 20, 2016
1 parent 824c8db commit b685341
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ max_length = 120
trim_trailing_whitespace = true
insert_final_newline = true

[*.{json, yml, html}]
[*.{json, yml, html, hbs}]
indent_size = 2
33 changes: 31 additions & 2 deletions lib/reporters/html/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,47 @@
var fs = require('fs'), // @todo: remove once HTML report contents have been verified
var fs = require('fs'),
_ = require('lodash'),
path = require('path'),
handlebars = require('handlebars'),

FILE_READ_OPTIONS = { encoding: 'utf8' },
DEFAULT_TEMPLATE = 'template-default.hbs',
ASSERTION_STATE = { false: 'passed', true: 'failed' },

PostmanHTMLReporter;

PostmanHTMLReporter = function (newman, options) {
// @todo load reporter template here so that we can give early warning if it fails
// @todo throw error here or simply don't catch them and it will show up as warning on newman
var compiler = handlebars.compile(fs.readFileSync(path.join(__dirname, DEFAULT_TEMPLATE), FILE_READ_OPTIONS));

newman.on('beforeDone', function () {
var aggregations = [],
traversedRequests = {},
executions = _.get(this, 'summary.run.executions'),
assertions = _.transform(executions, function (result, currentExecution) {
if (!_.has(traversedRequests, currentExecution.id)) {
// mark the current request instance as traversed
_.set(traversedRequests, currentExecution.id, 1);

// set sample request and response details for the current request
aggregations.push(_.pick(currentExecution, ['item', 'request', 'response']));
}

var assertionStatus = _.countBy(currentExecution.assertions, function (assertion) {
return ASSERTION_STATE[_.get(assertion, 'error', false)];
});

result[currentExecution.id] = result[currentExecution.id] || { passed: 0, failed: 0 };
result[currentExecution.id].passed += assertionStatus.passed || 0;
result[currentExecution.id].failed += assertionStatus.failed || 0;
}, {});

_.forEach(aggregations, function (currentAggregation) {
_.set(currentAggregation, 'assertions', assertions[currentAggregation.item.id]);
});

// console.log(JSON.stringify(aggregations, null, 2));

_.set(this.summary.run, 'aggregations', aggregations);
this.exports.push({
name: 'html-reporter',
default: 'newman-run-report.html',
Expand Down
31 changes: 21 additions & 10 deletions lib/reporters/html/template-default.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</head>
<body class="container">
<div class="conatiner">
<table class="summary table" width="100%">
<table class="summary table table-hover table-striped table-condensed" width="100%">
{{#with collection}}
<thead>
<tr class="title row"><td class="th" colspan="3">
Expand All @@ -50,11 +50,8 @@
</tbody>
</table>




{{#each run.executions}}
<table class="executions execution-{{@index}} table">
{{#each run.aggregations}}
<table class="executions execution-{{@index}} table table-hover table-striped table-condensed">
<thead>
<tr class="title row"><td class="th" colspan="3">
<h3>{{item.name}}</h3>
Expand All @@ -64,9 +61,8 @@
</thead>

<tbody>
<tr class="heading">
<td class="th"><h3>Response</h3></td>
<td class="th">&nbsp;</td>
<tr class="heading" width="100%">
<td class="th" colspan="3"><h3>Response</h3></td>
</tr>
{{#with response}}
<tr class="property row"><th class="th">Code</th><td>{{code}}</td></tr>
Expand All @@ -75,7 +71,7 @@
<tr class="property row">
<th class="th">Headers</th>
<td>
<table class="headers table">
<table class="headers table table-hover table-striped table-condensed">
<thead><tr class="title row"><th class="th">Key</th><th class="th">Value</th></tr></thead>

<tbody>
Expand All @@ -93,6 +89,21 @@
<tr class="property row"><th class="th">Time</th><td>{{responseTime}} ms</td></tr>

{{/with}}

{{#if assertions}}
<tr class="property row">
<th class="th">Assertions</th>
<td>
<table class="headers table table-hover table-striped table-condensed">
<thead><tr class="title row"><th class="th">Passed</th><th class="th">Failed</th></tr></thead>

<tbody>
<tr class="property row"><td>{{assertions.passed}}</td><td>{{assertions.failed}}</td></tr>
</tbody>
</table>
</td>
</tr>
{{/if}}
</tbody>

</table>
Expand Down

0 comments on commit b685341

Please sign in to comment.