Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeCoverage for Functional automation in NodeJS Applications

I am looking for pointers towards a tool which can help me determine the functional automation coverage in nodeJs. (This is not unit Tests!).

I have a lot of selenium automation running for my frontend application written in NodeJS. But I want to know the functional coverage of these automation.

(I used jacoco for java based earlier)

like image 363
footy Avatar asked Oct 20 '22 00:10

footy


2 Answers

As mentioned in one of the comments, istanbul is a really nice, very generic, coverage tool. It acts as a middle man between the node process and your scripts, so as long as you are executing something in the node runtime, it should do what you want. I'm not sure how you are running your selenium tests but I run mocha through it like so:

node ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- test/*-test.js
#or simply:
./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- test/*-test.js

Even though mocha is normally run as its own "command", it can be "fed" into istanbul and coverage is printed out that way. So in your case, whatever command you use to run the frontend tests in node/selenium can be run in istanbul. As I said, this is a very generic process that can be applied to anything that runs within node.js.

Now I don't really have any hands on experience with Selenium but what I do know that it is a bit a Rube Goldberg system with many interconnected processes (some potentially on different machines). If you are looking for something to capture both front end, backend, and test code (or frontend code running in the browser, served from backend code) in one line, I'm not sure that exists ("frontend application written in NodeJS" is what keyed me into this).

like image 133
mattr Avatar answered Oct 27 '22 08:10

mattr


The answer to this question is to have istanbul-middleware https://github.com/gotwarlost/istanbul-middleware

istanbul and istanbul-middleware are different and needs to be installed separately. I have successfully instrumented the code using this. Steps are as follows

  1. add istanbul-middleware to your nodejs application
  2. add the instrumentation code inside your application startup. The example is given in github.
  3. Then start your node server and run your selenium tests againsts it.
  4. if you run in localhost then you can goto /coverage (or if you changed it from the github example change it here) and get your coverage information.

Read the github readme for more details.

like image 29
footy Avatar answered Oct 27 '22 07:10

footy