Code coverage report for lib/formatters/cli.js

Statements: 100% (11 / 11)      Branches: 100% (2 / 2)      Functions: 100% (3 / 3)      Lines: 100% (11 / 11)      Ignored: none     

All files » lib/formatters/ » cli.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 401                           1 3   3   3               3 3 1   3       3     1  
var colors = require('colors'),
  util = require('util');
 
/**
 * Format health check results into an array of texts.
 *
 * @param {Object} results: an array of result objects containing:
 * - name: resource name
 * - status: success, warning, fail, or error
 * - uri: the resource that was checked
 * - desc: result description, e.g. failure explanation
 * - duration: check response time in milliseconds
 * @return {Array} an array of result strings
 */
function format(results) {
  var texts = [];
 
  results.forEach(function (result) {
 
    texts.push(util.format(
      '%s - %s%s - %dms',
      result.getStatus()[result.getStatusColor()],
      result.getName() ? result.getName() + ' - ' : '',
      result.getUri().cyan,
      result.getDuration()
    ));
    
    var messages = [].concat(result.getSuccesses(), result.getFailures(), result.getErrors());
    messages.forEach(function (message) {
      texts.push(util.format(' * %s', message));
    });
    texts.push('');
 
  });
 
  return texts;
}
 
exports.format = format;