How to get js code coverage for tomcat application?
Closed this issue · 1 comments
@tntim96, I can see that you've been handling this project alone. Thanks for all your efforts and keep moving this project!
I'm very new to code coverage and applications deployed in tomcat. Searched a lot and also went through JSCOver doc but could comprehend fully, hence need your help. My questions could be silly but please help me.
My requirement is to get JS Code Coverage of application which is deployed in Tomcat. To hit the code, I'll execute Selenium tests.
In document I can see following command where doc/example has js code(& index.html) which is going to be checked for coverage -
java -jar target/dist/JSCover-all.jar -ws --document-root=doc/example --report-dir=target
In Tomcat, my app is at - /home/oracle/apache-tomcat-8.5.11/webapps/MyApp
which is using port 8080
. And I hit command -
java -jar target/dist/JSCover-all.jar -ws --document-root=/home/oracle/apache-tomcat-8.5.11/webapps/MyApp --report-dir=target
But it results into error -
Exception in thread "main" java.lang.RuntimeException: java.net.BindException: Address already in use (Bind failed)
- How can I use different port for server started by above js cover?
- Am I doing above things correctly? This question is because our team has documented like following and neither is helping me move further
Steps by team -
- Stop the application i.e MyApp
- Instrument js files of MyApp with -
java -jar target\dist\JSCover-all.jar -fs --local-storage /home/oracle/apache-tomcat-8.5.11/webapps/MyApp target/MyApp-Ins
This created instrumented folder MyApp-Ins
- Rename
WEB-INF
folder from/home/oracle/apache-tomcat-8.5.11/webapps/MyApp
to something likeWEB-INF-OLD
- Copied instrumented folder
MyApp-Ins
underwebapps
at same level as ofMyApp
- Restart server and access instrumented app like - http://localhost:8080/MyApp-Ins
- Start JSCover server with -
java -cp target\dist\JSCover-all.jar jscover.server.SimpleWebServer target/MyApp-Ins 8080
But this results into error -
Exception in thread "main" java.lang.NullPointerException
at jscover.server.SimpleWebServer.main(SimpleWebServer.java:362)
I did not understand why this failed and why to use port 8080
again here(which is used for app deployed) and use target/MyaApp-Ins
which is instrumented in JSCover directory
Please help me how I can proceed with this?
If the application is deployed, you should instrument the JS code using file-mode before deploying. There is a working example here: https://github.com/tntim96/JSCover/tree/master/examples/localStorage-file-system
There are also other tools that might be better suited for your scenario:
https://blog.logrocket.com/using-the-chrome-devtools-new-code-coverage-feature-ca96c3dddcaf/
https://egghead.io/lessons/javascript-how-to-write-a-javascript-library-adding-code-coverage-recording-with-istanbul