All files helpers.js

100% Statements 16/16
100% Branches 6/6
100% Functions 7/7
100% Lines 16/16
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 40 41 42 43 44 45 463x   3x       311x       10x   10x 6x   4x     10x 14x     10x       164x     498x     179x   308x 295x   13x                
var EOL = require('os').EOL;
 
const helpers = {
  replaceCharsNotSupportedByBamboo: function replaceCharsNotSupportedByBamboo(
    s,
  ) {
    return s.replace(/\./g, '_');
  },
 
  formatErrorMessages: function formatErrorMessages(errorMessages) {
    var lines = [];
 
    if (errorMessages.length === 1) {
      lines.push('1 failure:');
    } else {
      lines.push(errorMessages.length + ' failures:');
    }
 
    errorMessages.forEach(function(message) {
      lines.push('* ' + message);
    });
 
    return lines.join(EOL);
  },
 
  replaceVariables: function replaceVariables(template, variables) {
    return template
      .split(/\{|\}/)
      .filter(function(segment) {
        return segment;
      })
      .map(function(segment) {
        return segment.split('|').reduce(function(result, maybeVariable) {
          // Allow variables to fallback
          if (maybeVariable in variables) {
            return result ? result : variables[maybeVariable];
          }
          return maybeVariable;
        }, '');
      })
      .join('');
  },
};
 
export { helpers };