Patches and Improvements for jscoverage-0.5

Questions, problems, suggestions, bug reports, and so on.
Post Reply
Klaus

Patches and Improvements for jscoverage-0.5

Post by Klaus »

Hello!

The last few days I've begun using jscoverage to improve my application tests.
Finally it works really good after some problems and some improvements in the code.

I figured out to get the jscoverage-server to work using the proxy option.
Here are some possible improvements I could imagine:
  • It would also be nice to have the possibility to use pre-instrumented JS-code for the jscoverage-server.
  • Maybe a "report-finishing"-function, which processes the JSON-file and writes simple-HTML code for the final result data would help to make the report-results faster (especially when you have big JS-files resulting in a huge JSON-file) ... because after the tests have finished / or the server has shutdown the coverage data will not be changed any more - so than the data can be optimized for viewing the results.
Here are 2 patches I made to improve performance of the resulting report (using JSON.parse if available in modern browsers) and to fix a shutdown problem of the jscoverage-server when using non-localhost IP:

Code: Select all

diff -r jscoverage-0.5/jscoverage.js jscoverage-0.5.patched/jscoverage.js
334,335c334
<             var response = request.responseText;
<             if (response === '') {
---
>             if (request.responseText === '') {
338c337,342
<             var json = eval('(' + response + ')');
---
>             var json;
>             if (JSON && JSON.parse && typeof JSON.parse === "function") {
>               json = JSON.parse(request.responseText);
>             } else {
>               json = eval('(' + response + ')');
>             }
diff -r jscoverage-0.5/jscoverage-server.c jscoverage-0.5.patched/jscoverage-server.c
1280c1280
<     HTTPConnection * connection = HTTPConnection_new_client(ip_address, numeric_port);
---
>     HTTPConnection * connection = HTTPConnection_new_client("127.0.0.1", numeric_port);
Kind regards,
Klaus.
Attachments
jscoverage-patches.zip
* patched jscoverage.js to improve performance of JSON parsing (using JSON.parse if available in modern browsers)
* patched jscoverage-server.c to fix shutdown with non-localhost ip
(16.71 KiB) Downloaded 2422 times
Ed
Posts: 120
Joined: 2008-10-11 6:52 pm

Re: Patches and Improvements for jscoverage-0.5

Post by Ed »

Thanks for the patches. I just have a few questions:
Klaus wrote:It would also be nice to have the possibility to use pre-instrumented JS-code for the jscoverage-server.
I'm not sure why that would be useful?
Klaus wrote:Maybe a "report-finishing"-function, which processes the JSON-file and writes simple-HTML code for the final result data would help to make the report-results faster (especially when you have big JS-files resulting in a huge JSON-file) ... because after the tests have finished / or the server has shutdown the coverage data will not be changed any more - so than the data can be optimized for viewing the results.
Yes, probably that would improve the report. (The current implementation is basically just a quick hack to get reports working by reusing the existing JSCoverage user interface.)
Klaus wrote:

Code: Select all

diff -r jscoverage-0.5/jscoverage-server.c jscoverage-0.5.patched/jscoverage-server.c
1280c1280
<     HTTPConnection * connection = HTTPConnection_new_client(ip_address, numeric_port);
---
>     HTTPConnection * connection = HTTPConnection_new_client("127.0.0.1", numeric_port);
I am confused about this - doesn't the original code use 127.0.0.1? Is the patch reversed?
Guest

Re: Patches and Improvements for jscoverage-0.5

Post by Guest »

Ed wrote:Thanks for the patches. I just have a few questions:
Klaus wrote:It would also be nice to have the possibility to use pre-instrumented JS-code for the jscoverage-server.
I'm not sure why that would be useful?
-> for performance improvements, so that the code is instrumented before the first page access. (but this was only an idea, not really required)
Klaus wrote:

Code: Select all

diff -r jscoverage-0.5/jscoverage-server.c jscoverage-0.5.patched/jscoverage-server.c
1280c1280
<     HTTPConnection * connection = HTTPConnection_new_client(ip_address, numeric_port);
---
>     HTTPConnection * connection = HTTPConnection_new_client("127.0.0.1", numeric_port);
Ed wrote: I am confused about this - doesn't the original code use 127.0.0.1? Is the patch reversed?
-> yes, I changed the parameter to use the given ip_address also for shutdown, otherwise the shutdown did not work when using a non local IP (e.g. using 0.0.0.0 as IP)
Post Reply