Esanders has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/77327


Change subject: Include element HTML in QUnit summary for diff
......................................................................

Include element HTML in QUnit summary for diff

Because trying to work out how broken your test case is
by looking at two (potentially multi-page) serialisations
of the DOM summary is a pain in the arse. Diffing two
HTML strings may highlight the problem much more clearly.

TODO: Is it possible to defer the calculation of the HTML
infused summary object until we have determined the assertion
has failed. Otherwise we're slowing down our tests for no
reason.

Change-Id: I873bf2479ab81d15389792bd59d15580da63941a
---
M modules/ve/test/ve.qunit.js
M modules/ve/ve.js
2 files changed, 11 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/27/77327/1

diff --git a/modules/ve/test/ve.qunit.js b/modules/ve/test/ve.qunit.js
index c33fc05..de9efb1 100644
--- a/modules/ve/test/ve.qunit.js
+++ b/modules/ve/test/ve.qunit.js
@@ -146,10 +146,12 @@
  */
 QUnit.assert.equalDomElement = function ( actual, expected, message ) {
        var actualSummary = ve.getDomElementSummary( actual ),
-               expectedSummary = ve.getDomElementSummary( expected );
+               expectedSummary = ve.getDomElementSummary( expected ),
+               actualSummaryHtml = ve.getDomElementSummary( actual, true ),
+               expectedSummaryHtml = ve.getDomElementSummary( expected, true );
 
        QUnit.push(
-               QUnit.equiv( actualSummary, expectedSummary ), actualSummary, 
expectedSummary, message
+               QUnit.equiv( actualSummary, expectedSummary ), 
actualSummaryHtml, expectedSummaryHtml, message
        );
 };
 
diff --git a/modules/ve/ve.js b/modules/ve/ve.js
index 12ac44a..566a13b 100644
--- a/modules/ve/ve.js
+++ b/modules/ve/ve.js
@@ -767,9 +767,10 @@
         *
         * @private
         * @param {HTMLElement} element Element to summarize
+        * @param {boolean} [includeHtml=false] Include an HTML summary for 
element nodes
         * @returns {Object} Summary of element.
         */
-       ve.getDomElementSummary = function ( element ) {
+       ve.getDomElementSummary = function ( element, includeHtml ) {
                var i,
                        $element = $( element ),
                        summary = {
@@ -778,6 +779,10 @@
                                'attributes': {},
                                'children': []
                        };
+
+               if ( includeHtml && element.nodeType === Node.ELEMENT_NODE ) {
+                       summary.html = element.outerHTML;
+               }
 
                // Gather attributes
                if ( element.attributes ) {
@@ -789,7 +794,7 @@
                if ( element.childNodes ) {
                        for ( i = 0; i < element.childNodes.length; i++ ) {
                                if ( element.childNodes[i].nodeType !== 
Node.TEXT_NODE ) {
-                                       summary.children.push( 
ve.getDomElementSummary( element.childNodes[i] ) );
+                                       summary.children.push( 
ve.getDomElementSummary( element.childNodes[i], includeHtml ) );
                                }
                        }
                }

-- 
To view, visit https://gerrit.wikimedia.org/r/77327
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I873bf2479ab81d15389792bd59d15580da63941a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to