All files / test/test-utils get-captured-text.js

87.5% Statements 7/8
75% Branches 3/4
75% Functions 3/4
87.5% Lines 7/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1914x   14x 70x   14x       70x   2063x       2063x      
const stripAnsiFrom = require('strip-ansi');
 
module.exports.getCapturedText = callsToLog =>
  formatCapturedText(callsToLog, false);
 
module.exports.getCapturedTextWithColor = callsToLog =>
  formatCapturedText(callsToLog, true);
 
function formatCapturedText(callsToLog, preserveColors) {
  return callsToLog.map(args => {
    // the validator only ever uses the first arg in consolg.log
    const output = preserveColors ? args[0] : stripAnsiFrom(args[0]);
 
    // the tests expect `console.log()` to be interpreted as a newline
    // but the mock captures the info as `undefined`
    return output === undefined ? '\n' : output;
  });
}