From f64806c5ad120646fdb7cddc808b6c145837cd37 Mon Sep 17 00:00:00 2001 From: alex-seville Date: Thu, 14 Mar 2013 21:56:28 -0400 Subject: [PATCH] Refactor of timeouts --- README.md | 1 + dist/Panel.html | 4 ---- dist/devtoolsjs/fetaSource.js | 2 +- lib/feta.js | 17 ++++++++++++++--- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 9d84064..143285d 100644 --- a/README.md +++ b/README.md @@ -43,4 +43,5 @@ OR -refactor timeouts in test -mock host objects in test (alert, confirm) and add pass throughs to feta for them, but also add option to not do that -more qunit tests for lib/feta.js +-bug when selecting a second test in sidebar, possibly related to id diff --git a/dist/Panel.html b/dist/Panel.html index 92ff26d..ee37a5b 100644 --- a/dist/Panel.html +++ b/dist/Panel.html @@ -31,11 +31,7 @@ -<<<<<<< HEAD
-======= -
->>>>>>> working on sidebar expansion
diff --git a/dist/devtoolsjs/fetaSource.js b/dist/devtoolsjs/fetaSource.js index 0521bc2..50d148d 100644 --- a/dist/devtoolsjs/fetaSource.js +++ b/dist/devtoolsjs/fetaSource.js @@ -26,6 +26,6 @@ fetaSrc.prototype.loadStr = function(){ }; (root||window).fetaSource = new fetaSrc(); -var fetaStr="if (!window.feta){window.feta=function(e,n){function t(e){for(var o=0;s.length>o;o++)if(n(e).on&&(!n(e).data(\"events\")||!n(e).data(\"events\")[s[o]]||n(e).data(\"events\")[s[o]].handler!==r))try{n(e).on(s[o],r)}catch(i){}var a=e.childNodes;if(a)for(var l=0;a.length>l;l++)t(a[l])}function r(n){if(g){if(n.selector=i(n.target),l.length>0){var r=l[l.length-1];if(r.timeStamp==n.timeStamp&&r.type==n.type&&r.target==n.target)return}if(n.target==window&&(\"focus\"==n.type||\"blur\"==n.type))return;console.log(\"TRACKING EVENT\"),l.push(n),setTimeout(function(){t(e.body)},50)}}function o(e){return JSON.stringify({type:e.type,elem:e.selector,timeStamp:e.timeStamp,key:\"keypress\"==e.type?e.which:null})}function i(e){if(0===n(e).parents().length)return\"DOCUMENT\";var t=\"\";n(e).parents()[0]!==n(\"body\")[0]&&n.each(n(e).parents().get().reverse(),function(){t+=this.tagName+a(this);var e=n(t).index(n(this));0>e&&console.log(\"parent not in parent selector?\");var r=1===n(t).length?\"\":\":nth-child(\"+(e+1)+\")\";t+=r+\" \"}),t+=n(e)[0].nodeName,t+=a(e);var r=n(t),o=r.length;if(o>1)for(var i=0;o>i;)n(t)[i]===e&&(t+=\":nth-child(\"+(i+1)+\")\",i=o),i++;return t}function a(e){if(\"BODY\"==e.tagName.toUpperCase()||\"HTML\"==e.tagName.toUpperCase())return\"\";var t=\"\",r=n(e).attr(\"id\");r&&(t+=\"#\"+r);var o=n(e).attr(\"class\");return o&&(t+=\".\"+n.trim(o).replace(/\\s/gi,\".\")),t}var s=[\"click\",\"focus\",\"keypress\",\"blur\"],l=[],g=!1,c=e.body;console.log(\"binding event handlers\"),t(c),console.log(\"done binding\");var f;n(e).on(\"feta.hasRegression\",function(e,n){f=n.data?n.data:[]});var u=!1;return n(e).on(\"feta.startPlaying\",function(){u=!0}),n(e).on(\"feta.endPlaying\",function(){u=!1}),{isPlaying:function(){return u},lastRegression:function(){return f},start:function(){l=[],g=!0},stop:function(e,n){g=!1;for(var t=\"\",r=0;l.length>r;r++)t+=o(l[r])+\",\";return this.saveAsJS('{ \"playlist\": ['+t.slice(0,t.length-1)+\"]}\",e?function(n){e({events:l,JS:n})}:null,n)},saveAsJS:function(e,n,t){var r=\"/* TestSetup, you shouldn't need to modify this */\\n\";r+=\"(function($,PhantomJS){\",r+=\"$(document).trigger('feta.startPlaying');\",r+=\"function regression(){\",r+=\"var regressions=[];\",r+=\"return {\",r+=\"add: function(item){\",r+=\"item = item || '';\",r+=\"regressions.push(item);\",r+=\"},\",r+=\"checkIfRegressed: function(cb){\",r+=\"var res = regressions.length > 0;\",r+=\"if (cb){\",r+=\"cb(res,regressions);\",r+=\"}else{\",r+=\"if (res ){\",r+=\"$(document).trigger('feta.hasRegression',{data: regressions});\",r+=\"console.log('FETA:Regression!');\",r+=\"}else{\",r+=\"$(document).trigger('feta.hasRegression',{});\",r+=\"console.log('FETA:No Regression.');\",r+=\"}\",r+=\"}\",r+=\"}\",r+=\"};\",r+=\"}\",r+=\"var r = new regression();\\n\",r+=\"function keyEvent(keyCode,el){\",r+='var e = $.Event(\"keypress\");',r+=\"e.keyCode=keyCode;\",r+=\"el.trigger(e);\",r+=\"el.val(el.val()+String.fromCharCode(keyCode));\",r+=\"}\\n\\n\",r+=\"/* Done TestSetup */\\n\\n\\n\";for(var o=JSON.parse(e).playlist,i=0,a=\"setTimeout(function(){\",s=0;o.length>s;s++){var l=o[s];r+=\"keypress\"===l.type?\" keyEvent(\"+l.key+\",$('\"+l.elem+\"'));\\n\":\" $('\"+l.elem+\"').trigger('\"+l.type+\"');\\n\",r+=\"\\n /* add any verification code here */\\n\",r+=\" /* use `r.add()` or $(document).trigger('feta.regression',[data]) */\\n\\n\",s>0&&(r+=\" } ,\"+i+\");\\n\"),o.length>s+1&&(i+=o[s+1].timeStamp-l.timeStamp),r+=a}return r+=\"\\n\\n /* Add final verification code here */\\n\",r+=\" r.checkIfRegressed();\\n\",r+=\" $(document).trigger('feta.endPlaying');\\n\",r+=' if (PhantomJS){ console.log(\"FETA_PHANTOMJS:done\");}\\n',r+=\"},\"+(i+100)+\");\",r+=\"\\n})(jQuery,typeof PhantomJS === 'undefined' ? null: PhantomJS);\\n\",t?r:((n||eval).call(this,r),void 0)}}}(document,jQuery);}"; +var fetaStr="if (!window.feta){window.feta=function(e,t){function n(e){for(var o=0;a.length>o;o++)if(t(e).on&&(!t(e).data(\"events\")||!t(e).data(\"events\")[a[o]]||t(e).data(\"events\")[a[o]].handler!==r))try{t(e).on(a[o],r)}catch(i){}var s=e.childNodes;if(s)for(var u=0;s.length>u;u++)n(s[u])}function r(t){if(c){if(t.selector=i(t.target),u.length>0){var r=u[u.length-1];if(r.timeStamp==t.timeStamp&&r.type==t.type&&r.target==t.target)return}if(t.target==window&&(\"focus\"==t.type||\"blur\"==t.type))return;console.log(\"TRACKING EVENT\"),u.push(t),setTimeout(function(){n(e.body)},50)}}function o(e){return JSON.stringify({type:e.type,elem:e.selector,timeStamp:e.timeStamp,key:\"keypress\"==e.type?e.which:null})}function i(e){if(0===t(e).parents().length)return\"DOCUMENT\";var n=\"\";t(e).parents()[0]!==t(\"body\")[0]&&t.each(t(e).parents().get().reverse(),function(){n+=this.tagName+s(this);var e=t(n).index(t(this));0>e&&console.log(\"parent not in parent selector?\");var r=1===t(n).length?\"\":\":nth-child(\"+(e+1)+\")\";n+=r+\" \"}),n+=t(e)[0].nodeName,n+=s(e);var r=t(n),o=r.length;if(o>1)for(var i=0;o>i;)t(n)[i]===e&&(n+=\":nth-child(\"+(i+1)+\")\",i=o),i++;return n}function s(e){if(\"BODY\"==e.tagName.toUpperCase()||\"HTML\"==e.tagName.toUpperCase())return\"\";var n=\"\",r=t(e).attr(\"id\");r&&(n+=\"#\"+r);var o=t(e).attr(\"class\");return o&&(n+=\".\"+t.trim(o).replace(/\\s/gi,\".\")),n}var a=[\"click\",\"focus\",\"keypress\",\"blur\"],u=[],c=!1,l=e.body;console.log(\"binding event handlers\"),n(l),console.log(\"done binding\");var f;t(e).on(\"feta.hasRegression\",function(e,t){f=t.data?t.data:[]});var g=!1;return t(e).on(\"feta.startPlaying\",function(){g=!0}),t(e).on(\"feta.endPlaying\",function(){g=!1}),{isPlaying:function(){return g},lastRegression:function(){return f},start:function(){u=[],c=!0},stop:function(e,t){c=!1;for(var n=\"\",r=0;u.length>r;r++)n+=o(u[r])+\",\";return this.saveAsJS('{ \"playlist\": ['+n.slice(0,n.length-1)+\"]}\",e?function(t){e({events:u,JS:t})}:null,t)},saveAsJS:function(e,t,n){var r=\"/* TestSetup, you shouldn't need to modify this */\\n\";r+=\"(function($,PhantomJS){\",r+=\"$(document).trigger('feta.startPlaying');\",r+=\"function regression(){\",r+=\"var regressions=[];\",r+=\"return {\",r+=\"add: function(item){\",r+=\"item = item || '';\",r+=\"regressions.push(item);\",r+=\"},\",r+=\"checkIfRegressed: function(cb){\",r+=\"var res = regressions.length > 0;\",r+=\"if (cb){\",r+=\"cb(res,regressions);\",r+=\"}else{\",r+=\"if (res ){\",r+=\"$(document).trigger('feta.hasRegression',{data: regressions});\",r+=\"console.log('FETA:Regression!');\",r+=\"}else{\",r+=\"$(document).trigger('feta.hasRegression',{});\",r+=\"console.log('FETA:No Regression.');\",r+=\"}\",r+=\"}\",r+=\"}\",r+=\"};\",r+=\"}\",r+=\"var r = new regression();\\n\",r+=\"function keyEvent(keyCode,el){\",r+='var e = $.Event(\"keypress\");',r+=\"e.keyCode=keyCode;\",r+=\"el.trigger(e);\",r+=\"el.val(el.val()+String.fromCharCode(keyCode));\",r+=\"}\\n\\n\",r+=\"/* Done TestSetup */\\n\\n\\n\",r+=\"var timeouts=[];\\n\";for(var o=JSON.parse(e).playlist,i=0,s=0,a=\"timeouts.push({fcn:function(){\",u=0;o.length>u;u++){var c=o[u];r+=\"keypress\"===c.type?\" keyEvent(\"+c.key+\",$('\"+c.elem+\"'));\\n\":\" $('\"+c.elem+\"').trigger('\"+c.type+\"');\\n\",r+=\"\\n /* add any verification code here */\\n\",r+=\" /* use `r.add()` or $(document).trigger('feta.regression',[data]) */\\n\\n\",u>0&&(r+=\" } ,time:\"+(i-s)+\"});\\n\",s=i),o.length>u+1&&(i+=o[u+1].timeStamp-c.timeStamp),r+=a}return r+=\"\\n\\n /* Add final verification code here */\\n\",r+=\" r.checkIfRegressed();\\n\",r+=\" $(document).trigger('feta.endPlaying');\\n\",r+=' if (PhantomJS){ console.log(\"FETA_PHANTOMJS:done\");}\\n',r+=\"},time:100});\",r+=\"function doTimeouts(current){\",r+=\"if (current){\",r+=\"setTimeout(function(){\",r+=\"current.fcn();\",r+=\"doTimeouts(timeouts.shift());\",r+=\"},current.time);\",r+=\"} }\",r+=\"doTimeouts(timeouts.shift());\",r+=\"\\n})(jQuery,typeof PhantomJS === 'undefined' ? null: PhantomJS);\\n\",n?r:((t||eval).call(this,r),void 0)}}}(document,jQuery);}"; //@ sourceURL=feta.js })(window); \ No newline at end of file diff --git a/lib/feta.js b/lib/feta.js index c59a1fe..c8f0ac6 100644 --- a/lib/feta.js +++ b/lib/feta.js @@ -225,9 +225,11 @@ window.feta = (function(document,$){ reportAsJS+= "el.val(el.val()+String.fromCharCode(keyCode));"; reportAsJS+= "}\n\n"; reportAsJS+= "/* Done TestSetup */\n\n\n"; + reportAsJS+= "var timeouts=[];\n"; var playlist = JSON.parse(report).playlist; var delay = 0; - var setTimeoutStr = "setTimeout(function(){"; + var lastTime=0; + var setTimeoutStr = "timeouts.push({fcn:function(){"; for(var i=0;i 0){ - reportAsJS += " } ,"+delay+");\n"; + reportAsJS += " } ,time:"+(delay-lastTime)+"});\n"; + lastTime = delay; } if (i+1 < playlist.length){ delay += playlist[i+1].timeStamp - evt.timeStamp; @@ -250,7 +253,15 @@ window.feta = (function(document,$){ reportAsJS += "\tr.checkIfRegressed();\n"; reportAsJS+= "\t$(document).trigger('feta.endPlaying');\n"; reportAsJS+= "\tif (PhantomJS){ console.log(\"FETA_PHANTOMJS:done\");}\n"; - reportAsJS += "},"+(delay+100)+");"; + reportAsJS += "},time:"+(100)+"});"; + reportAsJS += "function doTimeouts(current){"; + reportAsJS += "if (current){"; + reportAsJS += "setTimeout(function(){"; + reportAsJS += "current.fcn();"; + reportAsJS += "doTimeouts(timeouts.shift());"; + reportAsJS += "},current.time);"; + reportAsJS += "} }"; + reportAsJS += "doTimeouts(timeouts.shift());"; reportAsJS += "\n})(jQuery,typeof PhantomJS === 'undefined' ? null: PhantomJS);\n"; if (ret){