How use JSCoverage with modified jsUnitTestManager

Questions, problems, suggestions, bug reports, and so on.
jsto
Posts: 10
Joined: 2009-02-09 9:46 am

How use JSCoverage with modified jsUnitTestManager

Post by jsto » 2009-02-09 12:45 pm

Hi,
I have a custom unittest window(instead testRunner.html), which load all test functions into array. User can choice test class (example: testClients). This class has constructor test (example: ClientsUnitTest) and prototype functions (example: testAddClients...).
All test classes inherit ClientUnitTest manager. This manager (Example: TestManager) is equal to containerTestFrame(jsUnitTestManager.js).
I tried use JSCoverage, but Summary tab display 0 results, because the code hasn't js files - only objects with functions. The function "jscoverage_recalculateSummaryTab"(file: jscoverage.js) hasn't files into variable "cc".
How I can use JSCoverage to calculate jsunit javascript code coverage for object?

Ed
Posts: 120
Joined: 2008-10-11 6:52 pm

Re: How use JSCoverage with modified jsUnitTestManager

Post by Ed » 2009-02-09 2:55 pm

Where is the JavaScript code located? Not the code for the test framework, but the code for the System Under Test - where is that coming from?

jsto
Posts: 10
Joined: 2009-02-09 9:46 am

Re: How use JSCoverage with modified jsUnitTestManager

Post by jsto » 2009-02-09 3:45 pm

An execuble file(.exe file) runs an application with browser control. With javascript loaded all javascript files - objects and functions from xml file. An exe file located into win folder(Example: C:\source\win) and javascript files located into script folder(example: C:\source\script, C:\source\script\app...). The browser control loaded main.html located into C:\source\script\app\html. The UnitTest folder located into C:\source\UnitTests. Is this information enough?

Ed
Posts: 120
Joined: 2008-10-11 6:52 pm

Re: How use JSCoverage with modified jsUnitTestManager

Post by Ed » 2009-02-09 4:18 pm

jsto wrote:javascript files located into script folder(example: C:\source\script, C:\source\script\app...).
OK, are these JavaScript files the files being tested? Or are they the test code? Or are they the code for the test framework?

If these are the files being tested, you will have to instrument those. Probably you want to do something like this:

Code: Select all

jscoverage.exe C:\source\script C:\source\script-instrumented

jsto
Posts: 10
Joined: 2009-02-09 9:46 am

Re: How use JSCoverage with modified jsUnitTestManager

Post by jsto » 2009-02-10 12:20 pm

Hi,
thank you for your help. I tried this but it was unsuccessful. May be this type of project can not use JSCoverage. I have javasript files outside html file.

About my test framework - I have different type of jsunit testing window and jsUnitTestManager.
This UnitTestManager loaded all objects and their functions from .js files and I tested functions as call a object - not working with .js files.

jsto
Posts: 10
Joined: 2009-02-09 9:46 am

Re: How use JSCoverage with modified jsUnitTestManager

Post by jsto » 2009-02-10 2:20 pm

Now i try again. Successful only for js files included into main.html file.

Ed
Posts: 120
Joined: 2008-10-11 6:52 pm

Re: How use JSCoverage with modified jsUnitTestManager

Post by Ed » 2009-02-10 2:48 pm

Are the JavaScript functions defined outside of a .js file somehow? For example, are they embedded in an XML file? In that case JSCoverage will not work, as the jscoverage.exe program will not be able to find them.

If the functions are defined in .js files, then it should work. It should not matter whether they are included in the HTML file or not. Just make sure you run jscoverage.exe to create instrumented .js files, and make sure your application is using these instrumented files (not the originals).

jsto
Posts: 10
Joined: 2009-02-09 9:46 am

Re: How use JSCoverage with modified jsUnitTestManager

Post by jsto » 2009-02-11 12:01 pm

All javascript code as objects and functions are defined in .js files.
An xml file contains only path+file name for .js and html files.
An executable file loaded one js file and that file loaded all other js files in the browser control.

The application hierarchy is for exapmle c:\script, c:\script\app, c:\script\clients, c:\script\app\bla....
Аfter jscoverage folder having created I started jscoverage.html and wrote path to html file. This html contained only a few js files. For other .js files (loaded only as objects) can not display coverage information.

Ed
Posts: 120
Joined: 2008-10-11 6:52 pm

Re: How use JSCoverage with modified jsUnitTestManager

Post by Ed » 2009-02-11 2:55 pm

jsto wrote:All javascript code as objects and functions are defined in .js files.
An xml file contains only path+file name for .js and html files.
This path must point to the instrumented .js files.
jsto wrote:An executable file loaded one js file and that file loaded all other js files in the browser control.
How do you specify where the "loader" js file will load its files from? Is that from the XML file? This must also be the instrumented .js files.
jsto wrote:The application hierarchy is for exapmle c:\script, c:\script\app, c:\script\clients, c:\script\app\bla....
Аfter jscoverage folder having created I started jscoverage.html and wrote path to html file. This html contained only a few js files. For other .js files (loaded only as objects) can not display coverage information.
I suspect the loader is, for some reason, loading files from the original directory and not the instrumented directory.

jsto
Posts: 10
Joined: 2009-02-09 9:46 am

Re: How use JSCoverage with modified jsUnitTestManager

Post by jsto » 2009-02-11 3:47 pm

All js files are instrumented as:
/* automatically generated by JSCoverage - do not edit */
if (! top._$jscoverage) {
top._$jscoverage = {};
}
var _$jscoverage = top._$jscoverage;
if (! _$jscoverage['app/box.js']) {
_$jscoverage['app/box.js'] = [];
_$jscoverage['app/box.js'][19] = 0;.....

But when I wrote main html file in the url textbox(example: file:///C:/Source/main.html) loaded only .js files in this file. The main application is c++ application. This application loaded other js files.

Ed
Posts: 120
Joined: 2008-10-11 6:52 pm

Re: How use JSCoverage with modified jsUnitTestManager

Post by Ed » 2009-02-11 5:12 pm

jsto wrote:But when I wrote main html file in the url textbox(example: file:///C:/Source/main.html) loaded only .js files in this file. The main application is c++ application. This application loaded other js files.
How does this C++ application work? I presume it works like this:
  • Run C++ application
  • C++ application loads browser control
  • Browser control loads jscoverage.html
  • jscoverage.html loads file:///C:/Source/main.html
  • file:///C:/Source/main.html includes "loader" .js file
  • "loader" .js file loads other .js files
Is this correct?

jsto
Posts: 10
Joined: 2009-02-09 9:46 am

Re: How use JSCoverage with modified jsUnitTestManager

Post by jsto » 2009-02-12 9:28 am

No, it isn't correct.
1. run C++ application
2. C++ application loads browser control
3. Browser control loads main.html
4. One button(for test) load jscoverage.html(from instrumented folder)
5. JSCoverage displays "Browser" tab.

I cann't load jscoverage.html into browser control, because when main.html loaded, a browser control used functions from this main page(included .js files,which jscoverage can execute).
I cann't load main.html from instrumented folder too.

I will try different scenarios.

Ed
Posts: 120
Joined: 2008-10-11 6:52 pm

Re: How use JSCoverage with modified jsUnitTestManager

Post by Ed » 2009-02-12 2:53 pm

jsto wrote:No, it isn't correct.
1. run C++ application
2. C++ application loads browser control
3. Browser control loads main.html
4. One button(for test) load jscoverage.html(from instrumented folder)
5. JSCoverage displays "Browser" tab.
OK, that is slightly different but I think that can work too.
jsto wrote: I cann't load jscoverage.html into browser control, because when main.html loaded, a browser control used functions from this main page(included .js files,which jscoverage can execute).
I cann't load main.html from instrumented folder too.
If you cannot change the C++ application to load main.html from the instrumented folder, can you (temporarily) move the original folder and replace it with the instrumented folder?
Something like this:
  • move C:\source\script C:\source\script-original
  • move C:\source\script-instrumented C:\source\script

jsto
Posts: 10
Joined: 2009-02-09 9:46 am

Re: How use JSCoverage with modified jsUnitTestManager

Post by jsto » 2009-02-12 3:28 pm

I don't want to change c++ code. I tried this before, but c++ loaded instrumented js code and display errors (Microsoft JScript runtime error: 'top' is undefined). Perhaps I need some tool to coverage js objects.
The different scenarios is:
- adds jscoverage button into instrumented main.html file.
- loads instrumented main.html
- calls jscoverage.html
- displays only included .js(in main.html) files with changeable statistic.

Ed
Posts: 120
Joined: 2008-10-11 6:52 pm

Re: How use JSCoverage with modified jsUnitTestManager

Post by Ed » 2009-02-12 7:29 pm

jsto wrote:I don't want to change c++ code. I tried this before, but c++ loaded instrumented js code and display errors (Microsoft JScript runtime error: 'top' is undefined). Perhaps I need some tool to coverage js objects.
The different scenarios is:
- adds jscoverage button into instrumented main.html file.
- loads instrumented main.html
- calls jscoverage.html
- displays only included .js(in main.html) files with changeable statistic.
I think I understand what is going on now. You are saying that the other .js files - these are being executed outside the browser control? If that is the case, JSCoverage will not work, as it assumes code is being executed in a web browser.

You might be able to modify JSCoverage (or modify the instrumented code generated by jscoverage) to get it to work, but you would have to do 2 things:
  • Modify the statements from instrumented code that assume a browser (the statements referencing "top")
  • Write code to display the code coverage statistics (since jscoverage.html will not work)

Post Reply