diff --git a/core/scope.js b/core/scope.js index 64cd51882..87bb968cf 100644 --- a/core/scope.js +++ b/core/scope.js @@ -233,6 +233,10 @@ break; } + if (node instanceof DocumentFragment) { + entry = 'DocumentFragment'; + } + // div#foo if (node.id && node.id !== '') { entry += '#' + node.id; diff --git a/lib/metadata/metadata.json b/lib/metadata/metadata.json index 4a2c4e29e..bf9dbc8fe 100644 --- a/lib/metadata/metadata.json +++ b/lib/metadata/metadata.json @@ -561,6 +561,7 @@ }, "DOMinserts": { "desc": "number of DOM nodes inserts", + "offenders": true, "unit": "number", "module": "domQueries" }, diff --git a/modules/domQueries/domQueries.js b/modules/domQueries/domQueries.js index 662bbdeba..e77bdbc58 100644 --- a/modules/domQueries/domQueries.js +++ b/modules/domQueries/domQueries.js @@ -63,15 +63,24 @@ exports.module = function(phantomas) { // count DOM inserts function appendSpy(child) { /* jshint validthis: true */ - var hasParent = (typeof this.parentNode !== 'undefined'); - // ignore appending to the node that's not yet added to DOM tree - if (!hasParent) { + if (!this.parentNode) { + return; + } + + var destNodePath = phantomas.getDOMPath(this), + appendedNodePath = phantomas.getDOMPath(child); + + // don't count elements added to fragments as a DOM inserts (issue #350) + // DocumentFragment > div[0] + if (destNodePath.indexOf('DocumentFragment') === 0) { return; } phantomas.incrMetric('DOMinserts'); - phantomas.log('DOM insert: node "' + phantomas.getDOMPath(child) + '" added to "' + phantomas.getDOMPath(this) + '"'); + phantomas.addOffender('DOMinserts', '"%s" appended to "%s"', appendedNodePath, destNodePath); + + phantomas.log('DOM insert: node "%s" appended to "%s"', appendedNodePath, destNodePath); } phantomas.spy(Node.prototype, 'appendChild', appendSpy);