Skip to content

Commit 90b05f4

Browse files
committed
Fix lint
1 parent 60e89ae commit 90b05f4

File tree

6 files changed

+152
-138
lines changed

6 files changed

+152
-138
lines changed

examples/run-collections-in-directory.js

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ fs.readdir('./examples', function (err, files) {
1919
newman.run({
2020
// we load collection using require. for better validation and handling
2121
// JSON.parse could be used
22+
// eslint-disable-next-line n/no-path-concat
2223
collection: require(`${__dirname}/${file}`)
2324
}, function (err) {
2425
// finally, when the collection executes, print the status

lib/reporters/cli/index.js

+51-47
Original file line numberDiff line numberDiff line change
@@ -443,38 +443,40 @@ _.assignIn(PostmanCLIReporter, {
443443
});
444444

445445
// add specific rows to show in summary
446-
stats && _.forEach([{
447-
source: 'iterations',
448-
label: 'iterations'
449-
}, {
450-
source: 'requests',
451-
label: 'requests'
452-
}, {
453-
source: 'testScripts',
454-
label: 'test-scripts'
455-
}, {
456-
source: 'prerequestScripts',
457-
label: 'prerequest-scripts'
458-
}, {
459-
source: 'assertions',
460-
label: 'assertions'
461-
}], function (row) {
462-
var metric = stats[row.source],
463-
label = row.label;
464-
465-
// colour the label based on the failure or pending count of the metric
466-
label = metric.failed ? colors.red(label) : (metric.pending ? label : colors.green(label));
467-
468-
// push the statistics
469-
summaryTable.push([
470-
label,
471-
metric.total,
472-
(metric.failed ? colors.red(metric.failed) : metric.failed)
473-
// @todo - add information of pending scripts
474-
// (metric.failed ? colors.red(metric.failed) : metric.failed) +
475-
// (metric.pending ? format(' (%d pending)', metric.pending) : E)
476-
]);
477-
});
446+
if (stats) {
447+
_.forEach([{
448+
source: 'iterations',
449+
label: 'iterations'
450+
}, {
451+
source: 'requests',
452+
label: 'requests'
453+
}, {
454+
source: 'testScripts',
455+
label: 'test-scripts'
456+
}, {
457+
source: 'prerequestScripts',
458+
label: 'prerequest-scripts'
459+
}, {
460+
source: 'assertions',
461+
label: 'assertions'
462+
}], function (row) {
463+
var metric = stats[row.source],
464+
label = row.label;
465+
466+
// colour the label based on the failure or pending count of the metric
467+
label = metric.failed ? colors.red(label) : (metric.pending ? label : colors.green(label));
468+
469+
// push the statistics
470+
summaryTable.push([
471+
label,
472+
metric.total,
473+
(metric.failed ? colors.red(metric.failed) : metric.failed)
474+
// @todo - add information of pending scripts
475+
// (metric.failed ? colors.red(metric.failed) : metric.failed) +
476+
// (metric.pending ? format(' (%d pending)', metric.pending) : E)
477+
]);
478+
});
479+
}
478480

479481
// add the total execution time to summary
480482
timings && summaryTable.push([{
@@ -491,21 +493,23 @@ _.assignIn(PostmanCLIReporter, {
491493
}]);
492494

493495
// add rows containing average time of different request phases
494-
timings && _.forEach({
495-
response: 'average response time:',
496-
dns: 'average DNS lookup time:',
497-
firstByte: 'average first byte time:'
498-
}, (value, key) => {
499-
timings[`${key}Average`] && summaryTable.push([{
500-
colSpan: 3,
501-
content: format(`${value} %s [min: %s, max: %s, s.d.: %s]`,
502-
util.prettyms(timings[`${key}Average`]),
503-
util.prettyms(timings[`${key}Min`]),
504-
util.prettyms(timings[`${key}Max`]),
505-
util.prettyms(timings[`${key}Sd`])),
506-
hAlign: 'left'
507-
}]);
508-
});
496+
if (timings) {
497+
_.forEach({
498+
response: 'average response time:',
499+
dns: 'average DNS lookup time:',
500+
firstByte: 'average first byte time:'
501+
}, (value, key) => {
502+
timings[`${key}Average`] && summaryTable.push([{
503+
colSpan: 3,
504+
content: format(`${value} %s [min: %s, max: %s, s.d.: %s]`,
505+
util.prettyms(timings[`${key}Average`]),
506+
util.prettyms(timings[`${key}Min`]),
507+
util.prettyms(timings[`${key}Max`]),
508+
util.prettyms(timings[`${key}Sd`])),
509+
hAlign: 'left'
510+
}]);
511+
});
512+
}
509513

510514
return summaryTable;
511515
},

lib/run/index.js

+52-49
Original file line numberDiff line numberDiff line change
@@ -360,64 +360,67 @@ module.exports = function (options, callback) {
360360

361361
// initialise all the reporters
362362
!emitter.reporters && (emitter.reporters = {});
363-
_.isArray(reporters) && _.forEach(reporters, function (reporterName) {
364-
// disallow duplicate reporter initialisation
365-
if (_.has(emitter.reporters, reporterName)) { return; }
366363

367-
var Reporter;
364+
if (_.isArray(reporters)) {
365+
_.forEach(reporters, function (reporterName) {
366+
// disallow duplicate reporter initialisation
367+
if (_.has(emitter.reporters, reporterName)) { return; }
368368

369-
try {
370-
// check if the reporter is an external reporter
371-
Reporter = require((function (name) { // ensure scoped packages are loaded
372-
var prefix = '',
373-
scope = (name.charAt(0) === '@') && name.substr(0, name.indexOf('/') + 1);
369+
var Reporter;
374370

375-
if (scope) {
376-
prefix = scope;
377-
name = name.substr(scope.length);
378-
}
371+
try {
372+
// check if the reporter is an external reporter
373+
Reporter = require((function (name) { // ensure scoped packages are loaded
374+
var prefix = '',
375+
scope = (name.charAt(0) === '@') && name.substr(0, name.indexOf('/') + 1);
379376

380-
return prefix + 'newman-reporter-' + name;
381-
}(reporterName)));
382-
}
383-
// @todo - maybe have a debug mode and log error there
384-
catch (error) {
385-
if (!defaultReporters[reporterName]) {
386-
// @todo: route this via print module to respect silent flags
387-
console.warn(`newman: could not find "${reporterName}" reporter`);
388-
console.warn(' ensure that the reporter is installed in the same directory as newman');
389-
390-
// print install instruction in case a known reporter is missing
391-
if (knownReporterErrorMessages[reporterName]) {
392-
console.warn(knownReporterErrorMessages[reporterName]);
393-
}
394-
else {
395-
console.warn(' please install reporter using npm\n');
377+
if (scope) {
378+
prefix = scope;
379+
name = name.substr(scope.length);
380+
}
381+
382+
return prefix + 'newman-reporter-' + name;
383+
}(reporterName)));
384+
}
385+
// @todo - maybe have a debug mode and log error there
386+
catch (error) {
387+
if (!defaultReporters[reporterName]) {
388+
// @todo: route this via print module to respect silent flags
389+
console.warn(`newman: could not find "${reporterName}" reporter`);
390+
console.warn(' ensure that the reporter is installed in the same directory as newman');
391+
392+
// print install instruction in case a known reporter is missing
393+
if (knownReporterErrorMessages[reporterName]) {
394+
console.warn(knownReporterErrorMessages[reporterName]);
395+
}
396+
else {
397+
console.warn(' please install reporter using npm\n');
398+
}
396399
}
397400
}
398-
}
399401

400-
// load local reporter if its not an external reporter
401-
!Reporter && (Reporter = defaultReporters[reporterName]);
402+
// load local reporter if its not an external reporter
403+
!Reporter && (Reporter = defaultReporters[reporterName]);
402404

403-
try {
404-
// we could have checked _.isFunction(Reporter), here, but we do not do that so that the nature of
405-
// reporter error can be bubbled up
406-
Reporter && (emitter.reporters[reporterName] = new Reporter(emitter,
407-
_.get(options, ['reporter', reporterName], {}), options));
408-
}
409-
catch (error) {
410-
// if the reporter errored out during initialisation, we should not stop the run simply log
411-
// the error stack trace for debugging
412-
console.warn(`newman: could not load "${reporterName}" reporter`);
413-
414-
if (!defaultReporters[reporterName]) {
415-
// @todo: route this via print module to respect silent flags
416-
console.warn(` this seems to be a problem in the "${reporterName}" reporter.\n`);
405+
try {
406+
// we could have checked _.isFunction(Reporter), here, but we do
407+
// not do that so that the nature of reporter error can be bubbled up
408+
Reporter && (emitter.reporters[reporterName] = new Reporter(emitter,
409+
_.get(options, ['reporter', reporterName], {}), options));
417410
}
418-
console.warn(error);
419-
}
420-
});
411+
catch (error) {
412+
// if the reporter errored out during initialisation, we should not stop the run simply log
413+
// the error stack trace for debugging
414+
console.warn(`newman: could not load "${reporterName}" reporter`);
415+
416+
if (!defaultReporters[reporterName]) {
417+
// @todo: route this via print module to respect silent flags
418+
console.warn(` this seems to be a problem in the "${reporterName}" reporter.\n`);
419+
}
420+
console.warn(error);
421+
}
422+
});
423+
}
421424

422425
// raise warning when more than one dominant reporters are used
423426
(function (reporters) {

lib/run/options.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,17 @@ module.exports = function (options, callback) {
383383
config.get(options, { loaders: configLoaders, command: 'run' }, function (err, result) {
384384
if (err) { return callback(err); }
385385

386-
!_.isEmpty(options.globalVar) && _.forEach(options.globalVar, function (variable) {
387-
variable && (result.globals.set(variable.key, variable.value));
388-
});
386+
if (!_.isEmpty(options.globalVar)) {
387+
_.forEach(options.globalVar, function (variable) {
388+
variable && (result.globals.set(variable.key, variable.value));
389+
});
390+
}
389391

390-
!_.isEmpty(options.envVar) && _.forEach(options.envVar, function (variable) {
391-
variable && (result.environment.set(variable.key, variable.value));
392-
});
392+
if (!_.isEmpty(options.envVar)) {
393+
_.forEach(options.envVar, function (variable) {
394+
variable && (result.environment.set(variable.key, variable.value));
395+
});
396+
}
393397

394398
callback(null, result);
395399
});

lib/run/summary.js

+37-35
Original file line numberDiff line numberDiff line change
@@ -319,43 +319,45 @@ _.assign(RunSummary, {
319319
timings = timings && timings.timings;
320320
timingPhases = timings && sdk.Response.timingPhases(timings);
321321

322-
(timingPhases || time) && _.forEach([
323-
'dns',
324-
'firstByte',
325-
'response'
326-
], (value) => {
327-
var currentValue = (value === 'response') ? time : (timingPhases && timingPhases[value]),
328-
previousAverage = summary.run.timings[`${value}Average`],
329-
previousVariance = summary.run.timings[`${value}Sd`] ** 2,
330-
delta1 = currentValue - previousAverage,
331-
delta2,
332-
currentVariance;
333-
334-
if (!currentValue) { return; }
335-
336-
// compute average time for the given phase of request
337-
summary.run.timings[`${value}Average`] =
338-
(previousAverage * (requestCount - 1) + currentValue) / requestCount;
339-
340-
// compute minimum time for the given phase of request
341-
if (!summary.run.timings[`${value}Min`]) {
342-
summary.run.timings[`${value}Min`] = currentValue;
343-
}
344-
else {
345-
summary.run.timings[`${value}Min`] =
346-
Math.min(summary.run.timings[`${value}Min`], currentValue);
347-
}
322+
if (timingPhases || time) {
323+
_.forEach([
324+
'dns',
325+
'firstByte',
326+
'response'
327+
], (value) => {
328+
var currentValue = (value === 'response') ? time : (timingPhases && timingPhases[value]),
329+
previousAverage = summary.run.timings[`${value}Average`],
330+
previousVariance = summary.run.timings[`${value}Sd`] ** 2,
331+
delta1 = currentValue - previousAverage,
332+
delta2,
333+
currentVariance;
334+
335+
if (!currentValue) { return; }
336+
337+
// compute average time for the given phase of request
338+
summary.run.timings[`${value}Average`] =
339+
(previousAverage * (requestCount - 1) + currentValue) / requestCount;
340+
341+
// compute minimum time for the given phase of request
342+
if (!summary.run.timings[`${value}Min`]) {
343+
summary.run.timings[`${value}Min`] = currentValue;
344+
}
345+
else {
346+
summary.run.timings[`${value}Min`] =
347+
Math.min(summary.run.timings[`${value}Min`], currentValue);
348+
}
348349

349-
// compute maximum time the given phase of request
350-
summary.run.timings[`${value}Max`] = Math.max(summary.run.timings[`${value}Max`], currentValue);
350+
// compute maximum time the given phase of request
351+
summary.run.timings[`${value}Max`] = Math.max(summary.run.timings[`${value}Max`], currentValue);
351352

352-
// compute standard deviation for the given phase of request
353-
// refer Welford's online algorithm from
354-
// https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
355-
delta2 = currentValue - summary.run.timings[`${value}Average`];
356-
currentVariance = (previousVariance * (requestCount - 1) + (delta1 * delta2)) / requestCount;
357-
summary.run.timings[`${value}Sd`] = Math.sqrt(currentVariance);
358-
});
353+
// compute standard deviation for the given phase of request
354+
// refer Welford's online algorithm from
355+
// https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
356+
delta2 = currentValue - summary.run.timings[`${value}Average`];
357+
currentVariance = (previousVariance * (requestCount - 1) + (delta1 * delta2)) / requestCount;
358+
summary.run.timings[`${value}Sd`] = Math.sqrt(currentVariance);
359+
});
360+
}
359361
});
360362
},
361363

lib/util.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ util = {
9595
* @returns {Object} - {event1: time1, event2: time2, ...} (time in string with appropriate unit)
9696
*/
9797
beautifyTime: function (obj) {
98-
return _.forEach(obj, (value, key) => {
98+
_.forEach(obj, (value, key) => {
9999
// convert only non-zero values
100100
value && (obj[key] = this.prettyms(value));
101101
});

0 commit comments

Comments
 (0)