tntim96 / JSCover

JSCover is a JavaScript Code Coverage Tool that measures line, branch and function coverage
GNU General Public License v2.0
399 stars 84 forks source link

Javascript code coverage for CEF based desktop application #201

Closed smmehadi closed 9 years ago

smmehadi commented 9 years ago

We have a desktop application which renders html/javascript in CEF (chromium embedded framework). Now we want to measure javascript code coverage for it. How should we go for it.

All the current page talk about javascript code coverage in browser only, but i haven't found anything for dekstop applications rendering html/javascript.

tntim96 commented 9 years ago

You're probably best off instrumenting the JavaScript using file-mode.

The coverage object can then be obtained using jscoverage_serializeCoverageToJSON() as described in the manual.

smmehadi commented 9 years ago

Thanks for replying, and apologies for asking basic question. can you please tell me what is the command to instrument (in file-mode). tried executing this command: java -jar target/dist/JSCover-all.jar -fs doc/example target/example it gives this output: Jul 27, 2015 2:55:28 PM jscover.Main runMain INFO: Args: -fs,doc/example,target/example

also my application doesn't have a url bar, but in manual everywhere it is mentioned to navigate to http://localhost:8080 what should i do in case of desktop application, which doesn't have a url bar?

tntim96 commented 9 years ago

Try executing the JavaScript code jscoverage_serializeCoverageToJSON() to see if you can get the coverage data.

smmehadi commented 9 years ago

So i was able to instrument the js files using: java -jar target/dist/JSCover-all.jar -fs doc/<> target/<>

I replaced these instrumented files (<>) in my application, then i relaunched my application, and i started manual tests on it. after some time, i wanted to see the coverage. is there a way to do so manually as well (apart from writing some code in JS or Java or python)?

or i execute jscoverage_serializeCoverageToJSON() in response to some button click in my application UI, and write its returned value using document.write(json). Are the steps written above correct or needs some modifications?

tntim96 commented 9 years ago

The coverage is stored in JavaScript, so the steps you described sound correct. The string that is returned goes in a file called jscoverage.json which can then be converted to Cobertura XML, LCOV, or viewed directly with accompanying JSCover report files (e.g. jscoverage.html, jscoverage.js - NB the file mode generated jscoverage.js needs jscoverage_isReport = true; appended to view the report).

smmehadi commented 9 years ago

Thanks a lot for help, that worked. one more question is if in each jscoverage_serializeCoverageToJSON() function (during instrumentation), i want to insert couple of more javascript statements (like sending coverage result to a server), then in which file i have to make changes.

tntim96 commented 9 years ago

The function jscoverage_report will serialize and POST the data to the current server at /jscoverage-store if that's any help.