From b4d78254e26024b44a7c5691019309017317e9cb Mon Sep 17 00:00:00 2001 From: Michael Brade Date: Wed, 13 May 2020 10:56:37 +0200 Subject: [PATCH 1/6] use Open Box char to show colored spaces in an inline diff --- lib/reporters/base.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/reporters/base.js b/lib/reporters/base.js index ea259445e3..fde885d414 100644 --- a/lib/reporters/base.js +++ b/lib/reporters/base.js @@ -106,6 +106,7 @@ var color = (exports.color = function(type, str) { if (!exports.useColors) { return String(str); } + str = str.replace(/ /gi, '\u2423;'); return '\u001b[' + exports.colors[type] + 'm' + str + '\u001b[0m'; }); From 926a4ed31c36cba702dcad857a84c140f15af19f Mon Sep 17 00:00:00 2001 From: Michael Brade Date: Wed, 13 May 2020 13:47:03 +0200 Subject: [PATCH 2/6] don't change the color() function the color() function is also used by the summary etc. --- lib/reporters/base.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/reporters/base.js b/lib/reporters/base.js index fde885d414..c6b5312491 100644 --- a/lib/reporters/base.js +++ b/lib/reporters/base.js @@ -106,7 +106,6 @@ var color = (exports.color = function(type, str) { if (!exports.useColors) { return String(str); } - str = str.replace(/ /gi, '\u2423;'); return '\u001b[' + exports.colors[type] + 'm' + str + '\u001b[0m'; }); @@ -391,6 +390,10 @@ function pad(str, len) { * @return {string} Diff */ function inlineDiff(actual, expected) { + // make spaces visible by replacing them with U+2423 (open box char) + actual = actual.replace(/ /gi, '\u2423'); + expected = expected.replace(/ /gi, '\u2423'); + var msg = errorDiff(actual, expected); // linenos From a01b05e44e46b382a197990918a3532cc9d6e852 Mon Sep 17 00:00:00 2001 From: Michael Brade Date: Thu, 14 May 2020 01:01:18 +0200 Subject: [PATCH 3/6] diffs: switch to using background color instead of visible spaces --- lib/reporters/base.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/reporters/base.js b/lib/reporters/base.js index c6b5312491..78858c9e4a 100644 --- a/lib/reporters/base.js +++ b/lib/reporters/base.js @@ -68,8 +68,8 @@ exports.colors = { green: 32, light: 90, 'diff gutter': 90, - 'diff added': 32, - 'diff removed': 31 + 'diff added': '30;42', + 'diff removed': '30;41' }; /** @@ -390,10 +390,6 @@ function pad(str, len) { * @return {string} Diff */ function inlineDiff(actual, expected) { - // make spaces visible by replacing them with U+2423 (open box char) - actual = actual.replace(/ /gi, '\u2423'); - expected = expected.replace(/ /gi, '\u2423'); - var msg = errorDiff(actual, expected); // linenos From 166ff9139818275aeaa8ee736f09df1271822f9f Mon Sep 17 00:00:00 2001 From: Michael Brade Date: Tue, 9 Jun 2020 23:22:31 +0200 Subject: [PATCH 4/6] only use background color for inline diffs --- lib/reporters/base.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/reporters/base.js b/lib/reporters/base.js index 78858c9e4a..251369f874 100644 --- a/lib/reporters/base.js +++ b/lib/reporters/base.js @@ -68,8 +68,10 @@ exports.colors = { green: 32, light: 90, 'diff gutter': 90, - 'diff added': '30;42', - 'diff removed': '30;41' + 'diff added': 32, + 'diff removed': 31, + 'diff added inline': '30;42', + 'diff removed inline': '30;41' }; /** @@ -189,9 +191,9 @@ var generateDiff = (exports.generateDiff = function(actual, expected) { } catch (err) { var msg = '\n ' + - color('diff added', '+ expected') + + color('diff added' + (exports.inlineDiffs ? " inline" : ""), '+ expected') + ' ' + - color('diff removed', '- actual: failed to generate Mocha diff') + + color('diff removed' + (exports.inlineDiffs ? " inline" : ""), '- actual: failed to generate Mocha diff') + '\n'; return msg; } @@ -406,9 +408,9 @@ function inlineDiff(actual, expected) { // legend msg = '\n' + - color('diff removed', 'actual') + + color('diff removed inline', 'actual') + ' ' + - color('diff added', 'expected') + + color('diff added inline', 'expected') + '\n\n' + msg + '\n'; @@ -474,10 +476,10 @@ function errorDiff(actual, expected) { .diffWordsWithSpace(actual, expected) .map(function(str) { if (str.added) { - return colorLines('diff added', str.value); + return colorLines('diff added inline', str.value); } if (str.removed) { - return colorLines('diff removed', str.value); + return colorLines('diff removed inline', str.value); } return str.value; }) From f75a2a458f33a3d488ff6c490965e37f11fd17a6 Mon Sep 17 00:00:00 2001 From: Michael Brade Date: Sun, 14 Jun 2020 23:57:39 +0200 Subject: [PATCH 5/6] format --- lib/reporters/base.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/reporters/base.js b/lib/reporters/base.js index 4302246f26..55c2d15ddc 100644 --- a/lib/reporters/base.js +++ b/lib/reporters/base.js @@ -191,9 +191,15 @@ var generateDiff = (exports.generateDiff = function(actual, expected) { } catch (err) { var msg = '\n ' + - color('diff added' + (exports.inlineDiffs ? " inline" : ""), '+ expected') + + color( + 'diff added' + (exports.inlineDiffs ? ' inline' : ''), + '+ expected' + ) + ' ' + - color('diff removed' + (exports.inlineDiffs ? " inline" : ""), '- actual: failed to generate Mocha diff') + + color( + 'diff removed' + (exports.inlineDiffs ? ' inline' : ''), + '- actual: failed to generate Mocha diff' + ) + '\n'; return msg; } From 30ea7a05dd47a48c05fe495ef365c124db6c79d7 Mon Sep 17 00:00:00 2001 From: Michael Brade Date: Mon, 22 Jun 2020 13:28:37 +0200 Subject: [PATCH 6/6] if you say so... --- lib/reporters/base.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/reporters/base.js b/lib/reporters/base.js index 55c2d15ddc..aeca18f345 100644 --- a/lib/reporters/base.js +++ b/lib/reporters/base.js @@ -191,15 +191,9 @@ var generateDiff = (exports.generateDiff = function(actual, expected) { } catch (err) { var msg = '\n ' + - color( - 'diff added' + (exports.inlineDiffs ? ' inline' : ''), - '+ expected' - ) + + color('diff added', '+ expected') + ' ' + - color( - 'diff removed' + (exports.inlineDiffs ? ' inline' : ''), - '- actual: failed to generate Mocha diff' - ) + + color('diff removed', '- actual: failed to generate Mocha diff') + '\n'; return msg; }