lib/reporters/diff.js
function unifiedDiff (err) {
  let indent = '      '
  function cleanUp (line) {
    if (line[0] === '+') {
      return indent + format.colorLines('green', line)
    }
    if (line[0] === '-') {
      return indent + format.colorLines('red', line)
    }
    if (line.match(/@@/)) {
      return null
    }
    if (line.match(/\\ No newline/)) {
      return null
    }
    if (line.trim().length) {
      line = format.colorLines('white', line)
    }
    return indent + line
  }
  function notBlank (line) {
    return typeof line !== 'undefined' && line !== null
  }
  let msg = diff.createPatch('string', err.actual, err.expected)
  let lines = msg.split('\n').splice(4)
  let diffResult = lines.map(cleanUp).filter(notBlank).join('\n')
  if (!diffResult.trim().length) {
    msg = diff.createPatch(
      'string',
      stringify(Object.keys(err._actual || err.actual).sort()),
      stringify(Object.keys(err._expected || err.expected).sort())
    )
    lines = msg.split('\n').splice(4)
    diffResult = format.red('       object keys not match: \n') + lines.map(cleanUp).filter(notBlank).join('\n')
  }
  return '\n      ' +
    format.colorLines('green', '+ expected') + ' ' +
    format.colorLines('red', '- actual') +
    '\n\n' +
    diffResult
}
function unifiedDiff (err) {
  let indent = '      '
  function cleanUp (line) {
    if (line[0] === '+') {
      return indent + format.colorLines('green', line)
    }
    if (line[0] === '-') {
      return indent + format.colorLines('red', line)
    }
    if (line.match(/@@/)) {
      return null
    }
    if (line.match(/\\ No newline/)) {
      return null
    }
    if (line.trim().length) {
      line = format.colorLines('white', line)
    }
    return indent + line
  }
  function notBlank (line) {
    return typeof line !== 'undefined' && line !== null
  }
  let msg = diff.createPatch('string', err.actual, err.expected)
  let lines = msg.split('\n').splice(4)
  let diffResult = lines.map(cleanUp).filter(notBlank).join('\n')
  if (!diffResult.trim().length) {
    msg = diff.createPatch(
      'string',
      stringify(Object.keys(err._actual || err.actual).sort()),
      stringify(Object.keys(err._expected || err.expected).sort())
    )
    lines = msg.split('\n').splice(4)
    diffResult = format.red('       object keys not match: \n') + lines.map(cleanUp).filter(notBlank).join('\n')
  }
  return '\n      ' +
    format.colorLines('green', '+ expected') + ' ' +
    format.colorLines('red', '- actual') +
    '\n\n' +
    diffResult
}
function unifiedDiff ( err ) { let indent = '      ' function cleanUp ( line ) { if ( line [ 0 ] === '+' ) { return indent + format . colorLines ( 'green' , line ) } if ( line [ 0 ] === '-' ) { return indent + format . colorLines ( 'red' , line ) } if ( line . match ( / @@ / ) ) { return null } if ( line . match ( / \\ No newline / ) ) { return null } if ( line . trim ( ) . length ) { line = format . colorLines ( 'white' , line ) } return indent + line } function notBlank ( line ) { return typeof line !== 'undefined' && line !== null } let msg = diff . createPatch ( 'string' , err . actual , err . expected ) let lines = msg . split ( '\n' ) . splice ( 4 ) let diffResult = lines . map ( cleanUp ) . filter ( notBlank ) . join ( '\n' ) if ( ! diffResult . trim ( ) . length ) { msg = diff . createPatch ( 'string' , stringify ( Object . keys ( err . _actual || err . actual ) . sort ( ) ) , stringify ( Object . keys ( err . _expected || err . expected ) . sort ( ) ) ) lines = msg . split ( '\n' ) . splice ( 4 ) diffResult = format . red ( '       object keys not match: \n' ) + lines . map ( cleanUp ) . filter ( notBlank ) . join ( '\n' ) } return '\n      ' + format . colorLines ( 'green' , '+ expected' ) + ' ' + format . colorLines ( 'red' , '- actual' ) + '\n\n' + diffResult }
Returns a unified diff between two strings.
@private
@param {Error} err with actual/expected
@return {string} The diff.
Returns a unified diff between two strings .