Improve arguments reading in timeline

This commit is contained in:
Gaël Métais
2015-03-08 23:13:09 +01:00
parent 3e0e31a5fe
commit 121a8b11b8
13 changed files with 313 additions and 27 deletions
@@ -247,11 +247,12 @@ exports.module = function(phantomas) {
});
}
function insertBeforeSpyBefore(child) {
function insertBeforeSpyBefore(child, refElement) {
/*jshint validthis: true */
var context = phantomas.getDOMPath(this);
var appended = phantomas.getDOMPath(child);
var referent = phantomas.getDOMPath(refElement);
appendChild(child, this, context, appended);
phantomas.enterContext({
@@ -261,7 +262,10 @@ exports.module = function(phantomas) {
length: 1,
elements: [context]
},
arguments: [appended]
arguments: [
appended,
referent
]
},
backtrace: phantomas.getBacktrace()
});
@@ -116,8 +116,9 @@ exports.module = function(phantomas) {
'addClass',
'removeClass',
'toggleClass',
];
// Tree traversal
var jQueryTraversalFunctions = [
'children',
'closest',
'find',
@@ -134,9 +135,11 @@ exports.module = function(phantomas) {
'siblings'
];
jQueryFunctions = jQueryFunctions.concat(jQueryTraversalFunctions);
// spy calls to jQuery functions
phantomas.once('init', function() {
phantomas.evaluate(function(jQueryFunctions) {
phantomas.evaluate(function(jQueryFunctions, jQueryTraversalFunctions) {
(function(phantomas) {
var jQuery;
var oldJQuery;
@@ -219,10 +222,6 @@ exports.module = function(phantomas) {
phantomas.enterContext({
type: 'jQuery - find',
callDetails: {
context: {
length: 1,
elements: ['#document']
},
arguments: [selector]
},
backtrace: phantomas.getBacktrace()
@@ -234,8 +233,7 @@ exports.module = function(phantomas) {
var data = phantomas.getContextData();
if (data.type === 'jQuery - find' &&
data.callDetails.context.elements.length === 1 &&
data.callDetails.context.elements[0] === '#document' &&
!data.callDetails.context &&
data.callDetails.arguments.length === 1 &&
/^#([\w\-]*)$/.exec(data.callDetails.arguments[0]) !== null) {
@@ -284,6 +282,11 @@ exports.module = function(phantomas) {
args = [].slice.call(arguments);
args.forEach(function(arg, index) {
if (arg instanceof Array) {
arg = '[Array]';
}
if (arg instanceof Object) {
if (arg instanceof jQuery || (arg.jquery && arg.jquery.length > 0)) {
@@ -354,12 +357,19 @@ exports.module = function(phantomas) {
});
}, function(result) {
phantomas.leaveContext();
if (jQueryTraversalFunctions.indexOf(functionName) >= 0) {
var moreData = {
resultsNumber : (result && result.length) ? result.length : 0
};
phantomas.leaveContext(moreData);
} else {
phantomas.leaveContext();
}
}) || phantomas.log('jQuery: can not track jQuery - ' + functionName + ' (this version of jQuery doesn\'t support it)');
});
});
})(window.__phantomas);
}, jQueryFunctions);
}, jQueryFunctions, jQueryTraversalFunctions);
});