I'm designing my tests using the Behavior Driven Development (BDD) approach using Gherkin syntax and running my tests with Cucumber JS.
I'm using Cucumber Studio to share reports and keep synced with my business stakeholders, and management.
Recently I needed to get test coverage reports for the project, and made some research but couldn't decide which library to use to get coverage reports and how.
So far I've found JSCover, Cucumber Reports, and Istanbul for test coverage reports, but I'm not sure how to use them exactly and which would be best for my case to use with Cucumber JS.
After several trials, I've figured out that it is pretty simple to use Istanbul JS to see code coverage.
I've followed the instructions on the website and install Istanbul's JavaScript library nyc
using:
yarn add -D nyc
Then, I've updated my scripts
in the package.json
as the following:
...
"scripts": {
"test": "cucumber-js ...",
...
"coverage": "nyc yarn test"
},
...
And when I run yarn coverage
it runs the tests with wrapping by nyc
and creating a coverage report as the following: