From 85682d3da457e7c6cf2f376f0a6520a68052c922 Mon Sep 17 00:00:00 2001 From: Chowdhurian Date: Fri, 6 Oct 2017 12:14:09 -0700 Subject: [PATCH 1/3] test: include expected result in error messages The script being tested for is expected to be present only if the analytics id is provided. To improve user experience, the error message indicates whether the script is expected to be present or not. --- test/doctool/test-doctool-html.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/doctool/test-doctool-html.js b/test/doctool/test-doctool-html.js index 9a4300a5d06e04..4e88a333e852f3 100644 --- a/test/doctool/test-doctool-html.js +++ b/test/doctool/test-doctool-html.js @@ -115,6 +115,7 @@ testData.forEach((item) => { assert.ifError(err); const actual = output.replace(spaces, ''); + const scriptDomain = 'google-analytics.com' // Assert that the input stripped of all whitespace contains the // expected list assert(actual.includes(expected)); @@ -122,11 +123,11 @@ testData.forEach((item) => { // Testing the insertion of Google Analytics script when // an analytics id is provided. Should not be present by default if (includeAnalytics) { - assert(actual.includes('google-analytics.com'), - 'Google Analytics script was not present'); + assert(actual.includes(scriptDomain), + 'Google Analytics script was not present, but it should be'); } else { - assert.strictEqual(actual.includes('google-analytics.com'), false, - 'Google Analytics script was present'); + assert.strictEqual(actual.includes(scriptDomain), false, + 'Google Analytics script was present, but it should not be'); } })); })); From 20efb5ad33477b1d86a0db1b5c6ca9eb2fb9eacf Mon Sep 17 00:00:00 2001 From: Chowdhurian Date: Sat, 7 Oct 2017 10:18:05 -0700 Subject: [PATCH 2/3] test: include actual result in error messages Remove expected result from error message and include actual result for clarity and easier debugging. --- test/doctool/test-doctool-html.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/doctool/test-doctool-html.js b/test/doctool/test-doctool-html.js index 4e88a333e852f3..c71242b0744a18 100644 --- a/test/doctool/test-doctool-html.js +++ b/test/doctool/test-doctool-html.js @@ -124,10 +124,10 @@ testData.forEach((item) => { // an analytics id is provided. Should not be present by default if (includeAnalytics) { assert(actual.includes(scriptDomain), - 'Google Analytics script was not present, but it should be'); + `Google Analytics script was not present in "${actual}"`); } else { assert.strictEqual(actual.includes(scriptDomain), false, - 'Google Analytics script was present, but it should not be'); + `Google Analytics script was present in "${actual}"`); } })); })); From 07c70cc6fe6166ce33abfd1eb272cf1d6cf885b8 Mon Sep 17 00:00:00 2001 From: Chowdhurian Date: Sat, 7 Oct 2017 14:22:12 -0700 Subject: [PATCH 3/3] test: fix linter errors Linter errored for missing semi colon and line length. --- test/doctool/test-doctool-html.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/doctool/test-doctool-html.js b/test/doctool/test-doctool-html.js index c71242b0744a18..40d7b54f59320a 100644 --- a/test/doctool/test-doctool-html.js +++ b/test/doctool/test-doctool-html.js @@ -115,7 +115,7 @@ testData.forEach((item) => { assert.ifError(err); const actual = output.replace(spaces, ''); - const scriptDomain = 'google-analytics.com' + const scriptDomain = 'google-analytics.com'; // Assert that the input stripped of all whitespace contains the // expected list assert(actual.includes(expected)); @@ -127,7 +127,8 @@ testData.forEach((item) => { `Google Analytics script was not present in "${actual}"`); } else { assert.strictEqual(actual.includes(scriptDomain), false, - `Google Analytics script was present in "${actual}"`); + 'Google Analytics script was present in ' + + `"${actual}"`); } })); }));