Description
RunSummary's request tracker computes run.transfers.responseTotal (shown in the CLI reporter as total data received: ... (approx)) using:
https://github.com/postmanlabs/newman/blob/develop/lib/run/summary.js#L315
size && (summary.run.transfers.responseTotal += (size.body || 0 + size.headers || 0));
Because + binds tighter than || in JavaScript, this parses as:
size.body || (0 + size.headers) || 0
not the intended:
(size.body || 0) + (size.headers || 0)
Impact
Whenever a response has a non-zero body size (i.e. almost always), size.headers is silently dropped from the running total — only size.body is counted. The "total data received" figure printed at the end of every collection run is therefore consistently undercounted by the size of all response headers across the run.
Repro
const size = { body: 270, headers: 793 };
console.log(size.body || 0 + size.headers || 0); // 270 (headers silently dropped)
console.log((size.body || 0) + (size.headers || 0)); // 1063 (correct)
This is also confirmed by the existing test suite's own TODO in test/unit/run-summary.test.js:
// @todo add test for computation of timings, transfer sizes and average response time
i.e. this computation currently has zero test coverage, which is how the bug went unnoticed.
Fix
Add explicit parens so + happens before ||:
size && (summary.run.transfers.responseTotal += ((size.body || 0) + (size.headers || 0)));
PR: Adityaj0#2
Description
RunSummary's request tracker computesrun.transfers.responseTotal(shown in the CLI reporter astotal data received: ... (approx)) using:https://github.com/postmanlabs/newman/blob/develop/lib/run/summary.js#L315
Because
+binds tighter than||in JavaScript, this parses as:not the intended:
Impact
Whenever a response has a non-zero body size (i.e. almost always),
size.headersis silently dropped from the running total — onlysize.bodyis counted. The "total data received" figure printed at the end of every collection run is therefore consistently undercounted by the size of all response headers across the run.Repro
This is also confirmed by the existing test suite's own TODO in
test/unit/run-summary.test.js:// @todo add test for computation of timings, transfer sizes and average response timei.e. this computation currently has zero test coverage, which is how the bug went unnoticed.
Fix
Add explicit parens so
+happens before||:PR: Adityaj0#2