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

JSCover not capturing the coverage data. #248

Closed abhibang closed 7 years ago

abhibang commented 7 years ago

Using JSCover to capture Java Script coverage of my application. Some brief about my application: Our application is not a pure JS application. It has java components on back end.

Currently JS cover is not collecting the reports with below approaches The application war is hosted on web server (Glassfish).

Approach1: To obtain the JS code coverage I've started JS Cover as specified in manual: java -jar target/dist/JSCover-all.jar -ws --document-root= --report-dir=target

Accessed my application url in http://localhost:8080/jscoverage.html

  1. Via opening it in frame, here the first screen of my application does not show up
  2. Via opening it in window, here my application opens up but on further navigation, after clicking on store Report, the coverage data is not collected.

Where in the reports have coverage collected for the demo app.

Approach2: Used and modified WebDriverGeneralProxyTest (added my application url and navigation in @Test shouldRunExampleAndStoreResultProgrammatically) present in https://github.com/tntim96/JSCover-samples to collect the coverage data making selenium to do the navigations.

Please guide me if I'm doing something wrong.

tntim96 commented 7 years ago

If you want to gather code coverage while testing your application on Glassfish (or any server) you can't use the server-mode (i.e. -ws switch). That is for serving static test files like Jasmine and QUnit.

You can use proxy-mode, but it doesn't work over SSL, and I generally recommend using file-system mode.

To do this you need to (from the top of my head):

  1. Instrument the JS files you want (normally using the HTML5 local storage switch )
  2. Start your application with the instrumented JS files replacing the original ones
  3. Run your tests
  4. Save your coverage data

There's a working example using this technique in https://github.com/tntim96/JSCover/tree/master/examples/localStorage-file-system