Skip to content

Instantly share code, notes, and snippets.

@johnbender
Last active December 14, 2015 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnbender/3a4898465e4c0a9092eb to your computer and use it in GitHub Desktop.
Save johnbender/3a4898465e4c0a9092eb to your computer and use it in GitHub Desktop.
Determine jQuery method dependencies.
# assumes pwd == /path/to/core/project/dir
for method in `cat ../mobile/debug/uniq-methods`; do
grep -lR "$method:" src >> /tmp/core-method-list;
done
# exclude sizzle since we're sure we'll need it
cat /tmp/core-method-list.log | grep -v 'sizzle' | sort | uniq
# assumes pwd == /path/to/jqm/project/dir
node node_modules/.bin/grunt test > /tmp/method-log-output
grep "METHOD USED" /tmp/method-log-output | sed 's/.*METHOD USED: //' | sort | uniq | > /tmp/uniq-methods
// After jQuery/QUnit but before tests run
// complete crap but it works
window.methodList = {
new: {},
old: {}
};
function redefineProp( prop ){
var original = jQuery.fn[prop];
return function(){
// if we haven't seen it this page load
// make note of it
if( !window.methodList.old[prop] ){
window.methodList.new[prop] = true;
}
// keep track for subsequent calls
window.methodList.old[prop] = true;
return original.apply(this, arguments);
};
}
for(prop in jQuery.fn) {
if( jQuery.fn.hasOwnProperty( prop ) &&
typeof jQuery.fn[ prop ] == "function" &&
prop !== "init" ) {
jQuery.fn[prop] = redefineProp(prop);
}
}
// NOTE with qunit and phantom QUnit.done appears to be bound after the
// grunt-qunit binding which moves the suite on to the next set of tests
$(function() {
console.log( "" );
QUnit.testDone(function() {
console.log( "" );
// print only the new stuff
for( method in window.methodList.new ) {
console.log( "METHOD USED: " + method );
}
window.methodList.new = {};
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment