Question

I've got a rather hideous and large javascript file that I've inherited from a dev I loathe. There is a lot of dead code, and I find I've spent a lot of time refactoring functions that aren't even called.

Ideally, I just want something that can tie into the js engine and keep track of when and how many times functions are called.

In FF, I can get a list of the functions by walking the window object, and dynamically wrap them all in a method that would log the call to them, and then call the function as normal.

Unfortunately, in IE, I can't use this as I can't seem to find a way to get a list of all the functions that have been loaded. And I can't run this app in FF, as it's horribly browser specific. At last count there were 138 lines containing "new ActiveXObject(...)"

Help, either with a tool that can do this, or at the very least, a way to get a list of the functions that IE7 has loaded from the user script.

Thanks -c

Was it helpful?

Solution

Try JSCoverage.

JSCoverage is a tool that measures code coverage for JavaScript programs.

JSCoverage works by instrumenting the JavaScript code used in web pages. Code coverage statistics are collected while the instrumented JavaScript code is executed in a web browser.

The instrumentation can be done on-the-fly if you set the JSCoverage Server to run as an HTTP proxy and configure your browser to go through it.

One way to use it is:

  1. Launch JSCoverage Server in proxy mode:
jscoverage-server --proxy --verbose
  1. Configure your browser to you use localhost:8080 as the HTTP proxy.
  2. Add the following bookmarklet, making sure the relative path to jscoverage is correct:
javascript:void(window.open('jscoverage/jscoverage.html'))
  1. Run your tests.
  2. Run the bookmarklet. It will popup a new window that shows you the coverage results.

OTHER TIPS

There is a Firebug extension for JS Code Coverage...

FirebugCodeCoverage 0.1 (https://addons.mozilla.org/en-US/firefox/addon/4837)

Unfortunately, its not currently updated for the latest version of FF.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top