tests/utils/compare-html.js
// ordering. Returns a boolean.
ordering. Returns a boolean.
ordering . Returns a boolean .
function compareHTMLStrings(first, second) {
    var parser = new DOMParser();
    var firstDoc = parser.parseFromString(first, "text/html");
    var secondDoc = parser.parseFromString(second, "text/html");
    function filterEmptyTextNodes(nodes) {
        var filteredNodes = [];
        for (var i = 0; i < nodes.length; i++) {
            var node = nodes[i];
            if (node.nodeName == '#text' &&
                    (!node.textContent || /^\s*$/.test(node.textContent))) {
                continue;
            }
            filteredNodes.push(node);
        }
        return filteredNodes;
    }
    function nodeHasAttributes(node, node2) {
        if (node.attributes) {
            for (var i = 0; i < node.attributes.length; i++) {
                var nodeAttribute = node.attributes[i];
                if (nodeAttribute.value != node2.getAttribute(nodeAttribute.name)) {
                    return false;
                }
            }
        }
        return true;
    }
    function recursiveCompare(node, node2) {
        if (node.nodeName != node2.nodeName) {
            return false;
        }
        if (!nodeHasAttributes(node, node2) || !nodeHasAttributes(node2, node)) {
            return false;
        }
        if ((node.nodeName == '#text' || node.nodeName == '#comment') &&
                node.textContent != node2.textContent) {
            return false;
        }
        var childNodes = filterEmptyTextNodes(node.childNodes);
        var childNodes2 = filterEmptyTextNodes(node2.childNodes);
        if (childNodes.length != childNodes2.length) {
            return false;
        }
        for (var i = 0; i < childNodes.length; i++) {
            if (!recursiveCompare(childNodes[i], childNodes2[i])) {
                return false;
            }
        }
        return true;
    }
    return recursiveCompare(firstDoc, secondDoc);
}
function compareHTMLStrings ( first , second ) { var parser = new DOMParser ( ) ; var firstDoc = parser . parseFromString ( first , "text/html" ) ; var secondDoc = parser . parseFromString ( second , "text/html" ) ; function filterEmptyTextNodes ( nodes ) { var filteredNodes = [ ] ; for ( var i = 0 ; i < nodes . length ; i ++ ) { var node = nodes [ i ] ; if ( node . nodeName == '#text' && ( ! node . textContent || / ^\s*$ / . test ( node . textContent ) ) ) { continue ; } filteredNodes . push ( node ) ; } return filteredNodes ; } function nodeHasAttributes ( node , node2 ) { if ( node . attributes ) { for ( var i = 0 ; i < node . attributes . length ; i ++ ) { var nodeAttribute = node . attributes [ i ] ; if ( nodeAttribute . value != node2 . getAttribute ( nodeAttribute . name ) ) { return false ; } } } return true ; } function recursiveCompare ( node , node2 ) { if ( node . nodeName != node2 . nodeName ) { return false ; } if ( ! nodeHasAttributes ( node , node2 ) || ! nodeHasAttributes ( node2 , node ) ) { return false ; } if ( ( node . nodeName == '#text' || node . nodeName == '#comment' ) && node . textContent != node2 . textContent ) { return false ; } var childNodes = filterEmptyTextNodes ( node . childNodes ) ; var childNodes2 = filterEmptyTextNodes ( node2 . childNodes ) ; if ( childNodes . length != childNodes2 . length ) { return false ; } for ( var i = 0 ; i < childNodes . length ; i ++ ) { if ( ! recursiveCompare ( childNodes [ i ] , childNodes2 [ i ] ) ) { return false ; } } return true ; } return recursiveCompare ( firstDoc , secondDoc ) ; }
ordering.
ordering .
// Filters empty filler text nodes that can cause inconsistencies // between compared HTML strings. // Returns a boolean that indicates whether `node2` has `node`'s // attributes. // Ensure node names match. // Ensure node attributes match. // Ensure values match. // Ensure they have the same amount of child nodes. // Compare child nodes recursively.