diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000000000..4ee01478dc02fb --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.json text eol=lf diff --git a/test/test-style.js b/test/test-style.js index 4074d23874929b..27f1770e327895 100644 --- a/test/test-style.js +++ b/test/test-style.js @@ -2,6 +2,25 @@ const fs = require('fs'); const path = require('path'); +function escapeInvisibles(str) { + const invisibles = [ + ['\b', '\\b'], + ['\f', '\\f'], + ['\n', '\\n'], + ['\r', '\\r'], + ['\v', '\\v'], + ['\t', '\\t'], + ['\0', '\\0'], + ]; + let finalString = str; + + invisibles.forEach(([invisible, replacement]) => { + finalString = finalString.replace(invisible, replacement); + }); + + return finalString; +} + function jsonDiff(actual, expected) { var actualLines = actual.split(/\n/); var expectedLines = expected.split(/\n/); @@ -10,8 +29,8 @@ function jsonDiff(actual, expected) { if (actualLines[i] !== expectedLines[i]) { return [ '#' + (i + 1) + '\x1b[0m', - ' Actual: ' + actualLines[i], - ' Expected: ' + expectedLines[i] + ' Actual: ' + escapeInvisibles(actualLines[i]), + ' Expected: ' + escapeInvisibles(expectedLines[i]), ].join('\n'); } }