diff --git a/lib/tools/jsExecutionTransformer.js b/lib/tools/jsExecutionTransformer.js index c7801e3..587fe97 100644 --- a/lib/tools/jsExecutionTransformer.js +++ b/lib/tools/jsExecutionTransformer.js @@ -1,5 +1,7 @@ var debug = require('debug')('ylt:jsExecutionTransformer'); +var offendersHelpers = require('../offendersHelpers'); + var jsExecutionTransformer = function() { this.transform = function(data) { @@ -46,6 +48,14 @@ var jsExecutionTransformer = function() { data.toolsResults.phantomas.metrics.domComplete = node.data.timestamp; break; } + + // Change the list of dom paths into a tree + treeRecursiveParser(node, function(node) { + if (node.data.callDetails && node.data.callDetails.context && node.data.callDetails.context.length > 0) { + var domArrays = node.data.callDetails.context.elements.map(offendersHelpers.domPathToArray); + node.data.callDetails.context.elements = offendersHelpers.listOfDomArraysToTree(domArrays); + } + }); }); } @@ -57,6 +67,15 @@ var jsExecutionTransformer = function() { return javascriptExecutionTree; }; + + function treeRecursiveParser(node, fn) { + if (node.children) { + node.children.forEach(function(child) { + treeRecursiveParser(child, fn); + }); + } + fn(node); + } }; module.exports = new jsExecutionTransformer(); \ No newline at end of file diff --git a/lib/tools/phantomas/custom_modules/modules/domQYLT/domQYLT.js b/lib/tools/phantomas/custom_modules/modules/domQYLT/domQYLT.js index 85ed0ef..ab23f0d 100644 --- a/lib/tools/phantomas/custom_modules/modules/domQYLT/domQYLT.js +++ b/lib/tools/phantomas/custom_modules/modules/domQYLT/domQYLT.js @@ -33,9 +33,6 @@ exports.module = function(phantomas) { phantomas.enterContext({ type: 'getElementById', callDetails: { - context: { - domElement: '#document' - }, arguments: ['#' + id] }, backtrace: phantomas.getBacktrace() @@ -65,7 +62,8 @@ exports.module = function(phantomas) { type: 'getElementsByClassName', callDetails: { context: { - domElement: context + length: 1, + elements: [context] }, arguments: ['.' + className] }, @@ -103,7 +101,8 @@ exports.module = function(phantomas) { type: 'getElementsByTagName', callDetails: { context: { - domElement: context + length: 1, + elements: [context] }, arguments: [tagName] }, @@ -145,7 +144,8 @@ exports.module = function(phantomas) { type: 'querySelector', callDetails: { context: { - domElement: context + length: 1, + elements: [context] }, arguments: [selector] }, @@ -177,7 +177,8 @@ exports.module = function(phantomas) { type: 'querySelectorAll', callDetails: { context: { - domElement: context + length: 1, + elements: [context] }, arguments: [selector] }, @@ -237,7 +238,8 @@ exports.module = function(phantomas) { type: 'appendChild', callDetails: { context: { - domElement: context + length: 1, + elements: [context] }, arguments: [appended] }, @@ -256,7 +258,8 @@ exports.module = function(phantomas) { type: 'insertBefore', callDetails: { context: { - domElement: context + length: 1, + elements: [context] }, arguments: [appended] }, @@ -277,9 +280,6 @@ exports.module = function(phantomas) { phantomas.enterContext({ type: 'createElement', callDetails: { - context: { - domElement: '#document' - }, arguments: [tagName] }, backtrace: phantomas.getBacktrace() @@ -295,9 +295,6 @@ exports.module = function(phantomas) { phantomas.enterContext({ type: 'createTextNode', callDetails: { - context: { - domElement: '#document' - }, arguments: [text] }, backtrace: phantomas.getBacktrace() @@ -313,9 +310,6 @@ exports.module = function(phantomas) { phantomas.enterContext({ type: 'createDocumentFragment', callDetails: { - context: { - domElement: '#document' - }, arguments: [] }, backtrace: phantomas.getBacktrace() diff --git a/lib/tools/phantomas/custom_modules/modules/eventListYLT/eventListYLT.js b/lib/tools/phantomas/custom_modules/modules/eventListYLT/eventListYLT.js index c1620fc..5b79785 100644 --- a/lib/tools/phantomas/custom_modules/modules/eventListYLT/eventListYLT.js +++ b/lib/tools/phantomas/custom_modules/modules/eventListYLT/eventListYLT.js @@ -27,7 +27,8 @@ exports.module = function(phantomas) { type: 'addEventListener', callDetails: { context: { - domElement: path + length: 1, + elements: [path] }, arguments: [eventType] }, diff --git a/lib/tools/phantomas/custom_modules/modules/jQYLT/jQYLT.js b/lib/tools/phantomas/custom_modules/modules/jQYLT/jQYLT.js index 299ae3e..23b36dd 100644 --- a/lib/tools/phantomas/custom_modules/modules/jQYLT/jQYLT.js +++ b/lib/tools/phantomas/custom_modules/modules/jQYLT/jQYLT.js @@ -197,8 +197,8 @@ exports.module = function(phantomas) { type: 'jQuery - Sizzle call', callDetails: { context: { - length: this.length, - firstElementPath: phantomas.getDOMPath(context) + length: 1, + elements: [phantomas.getDOMPath(context)] }, arguments: [selector] }, @@ -221,7 +221,7 @@ exports.module = function(phantomas) { callDetails: { context: { length: 1, - firstElementPath: '#document' + elements: ['#document'] }, arguments: [selector] }, @@ -234,7 +234,8 @@ exports.module = function(phantomas) { var data = phantomas.getContextData(); if (data.type === 'jQuery - find' && - data.callDetails.context.firstElementPath === '#document' && + data.callDetails.context.elements.length === 1 && + data.callDetails.context.elements[0] === '#document' && data.callDetails.arguments.length === 1 && /^#([\w\-]*)$/.exec(data.callDetails.arguments[0]) !== null) { @@ -335,13 +336,17 @@ exports.module = function(phantomas) { args[index] = arg; }); + var elements = []; + for (var i = 0 ; i < this.length ; i++) { + elements.push(phantomas.getDOMPath(this[i])); + } phantomas.enterContext({ type: 'jQuery - ' + functionName, callDetails: { context: { length: this.length, - firstElementPath: phantomas.getDOMPath(this[0]) + elements: elements }, arguments: args },