From 0113e0cc368d2b2e1fc66b24a42aa9fc3c7c4d0b Mon Sep 17 00:00:00 2001 From: Julie Ralph Date: Wed, 4 Mar 2015 21:29:17 -0800 Subject: [PATCH] fix(accessibility): improve output for long elements Instead of just printing the first N characters of the element's template, print the first and last N/2. See #1854 --- plugins/accessibility/index.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/plugins/accessibility/index.js b/plugins/accessibility/index.js index 438f8e1a2..12a9c7b86 100644 --- a/plugins/accessibility/index.js +++ b/plugins/accessibility/index.js @@ -175,6 +175,15 @@ function runChromeDevTools(config) { var elementPromises = [], elementStringLength = 200; + function trimText(text) { + if (text.length > elementStringLength) { + return text.substring(0, elementStringLength / 2) + ' ... ' + + text.substring(text.length - elementStringLength / 2); + } else { + return text; + } + } + var testHeader = 'Chrome A11Y - '; return browser.executeScript_(data, 'a11y developer tool rules').then(function(results) { @@ -189,7 +198,7 @@ function runChromeDevTools(config) { elem.getOuterHtml().then(function(text) { return { code: result.rule.code, - list: text.substring(0, elementStringLength) + list: trimText(text) }; }) );